Skip to content

Analyze, Release and Publish to GHCR #7

Analyze, Release and Publish to GHCR

Analyze, Release and Publish to GHCR #7

Workflow file for this run

name: Analyze, Release and Publish to GHCR
on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-*'
jobs:
analyze:
name: Analyze
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
- name: Extract tag and pre-release check
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: SonarQube scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
args: -Dsonar.projectVersion=${{ env.VERSION }}
- name: Quality gate check
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
release:
name: Release
needs: analyze
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Generate release notes
id: changelog
run: |
CHANGELOG=$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"- %s")
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: ${{env.PRERELEASE == 'true'}}
body: ${{ env.CHANGELOG }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- 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: 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