diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb2d88d..5447553 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,20 +1,57 @@ -name: Build +name: Build and Publish to GHCR on: push: branches: - main + tags: + - 'v*.*.*' + - 'v*.*.*-*' jobs: build: name: Build runs-on: ubuntu-latest permissions: read-all + steps: - uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - uses: sonarsource/sonarqube-scan-action@master env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + + - name: Extract tag name and check if pre-release + run: | + echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + if [[ "${GITHUB_REF#refs/tags/}" == *-* ]]; then + echo "PRERELEASE=true" >> $GITHUB_ENV + else + echo "PRERELEASE=false" >> $GITHUB_ENV + fi + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_PAT }} + + - name: Extract tag name + run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Build and push version-tagged Docker image + uses: docker/build-push-action@v2 + with: + push: true + tags: ghcr.io/${{ github.repository }}:${{ env.VERSION }} + + - name: Build and push latest Docker image + if: env.PRERELEASE == 'false' + uses: docker/build-push-action@v2 + with: + push: true + tags: ghcr.io/${{ github.repository }}:latest