Skip to content

ci(task-nr): set env var #38

ci(task-nr): set env var

ci(task-nr): set env var #38

Workflow file for this run

name: CI/CD
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- master
release:
types: [published]
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
env:
TAG_VERSION: >-
if [ "${{ github.event_name }}" = 'published' ]; then
echo "${{ github.event.release.tag_name }}"
else
echo "${{ github.sha }}"
fi
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Compile
run: |
echo "Compiling the code"
./mvnw compile
- name: Test
run: |
echo "Running the tests"
./mvnw test
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
uses: docker/metadata-action@v3
with:
images: ${{ github.event.repository.name }}:${{ env.TAG_VERSION }}
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ env.TAG_VERSION }}
deploy:
if: (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true) ||
(github.event_name == 'release' && github.event.action == 'published')
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy
run: |
echo "Deploying the app using ${{ github.event.repository.name }}:${{ env.TAG_VERSION }} image"