Skip to content

Commit

Permalink
Updated workflow scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinscham committed Sep 21, 2023
1 parent 7f165c6 commit 471c3a4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 90 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/test-pr.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
name: Analyze PR

name: CI
# Trigger analysis when pushing to your main branches, and when creating a pull request.
on:
pull_request:
push:
branches:
- main
- develop
- 'release/**'
pull_request:
types: [opened, synchronize, reopened]

jobs:
analyze:
sonarqube:
name: Analyze PR
runs-on: ubuntu-latest
permissions: read-all

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
fetch-depth: 0

- 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.pullrequest.key=${{ github.event.number }}
-Dsonar.pullrequest.branch=${{ github.HEAD_REF }}
-Dsonar.pullrequest.base=${{ github.BASE_REF }}

- name: Quality gate check
uses: sonarsource/sonarqube-quality-gate-action@master
Expand Down
67 changes: 24 additions & 43 deletions .github/workflows/build.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Analyze, Release and Publish to GHCR
name: Release

on:
push:
Expand All @@ -7,53 +7,33 @@ on:
- 'v*.*.*-*'

jobs:
env:
name: Prepare environment
context:
name: Determine context
runs-on: ubuntu-latest
outputs:
version: ${{steps.version.outputs.version}}
prerelease: ${{steps.prerelease.outputs.prerelease}}
steps:
- id: version
- name: Grab version
id: version
run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
- id: prerelease

- name: Grab major version
id: major
run: echo "major=$(echo ${GITHUB_REF#refs/tags/} | cut -d'.' -f1)" >> "$GITHUB_OUTPUT"

- name: Determine (pre-)release status
id: prerelease
run: |
if [[ "${GITHUB_REF#refs/tags/}" == *-* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
analyze:
name: Pre-build Analysis
needs: env
runs-on: ubuntu-latest
permissions: read-all

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- 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.branch.name=main
-Dsonar.projectVersion=${{ needs.env.outputs.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: [env, analyze]
needs: context
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -72,21 +52,18 @@ jobs:
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: Release ${{ needs.env.outputs.version }}
name: Release ${{ needs.context.outputs.version }}
draft: false
prerelease: ${{ needs.env.outputs.prerelease == 'true' }}
prerelease: ${{ needs.context.outputs.prerelease == 'true' }}
body: ${{ steps.changelog.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GHCR_PAT }}

publish:
name: Publish to GHCR
needs: [env, release]
name: Build and push
needs: [context, release]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -95,14 +72,18 @@ jobs:
password: ${{ secrets.GHCR_PAT }}

- name: Build and push version-tagged Docker image
if: needs.context.outputs.prerelease == 'true'
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ needs.env.outputs.version }}
tags: ghcr.io/${{ github.repository }}:${{ needs.context.outputs.version }}

- name: Build and push latest Docker image
if: needs.env.outputs.prerelease == 'false'
if: needs.context.outputs.prerelease == 'false'
uses: docker/build-push-action@v5
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ needs.context.outputs.major }}
ghcr.io/${{ github.repository }}:${{ needs.context.outputs.version }}
37 changes: 0 additions & 37 deletions .github/workflows/test-branch.yml

This file was deleted.

2 changes: 2 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sonar.projectKey=Duolingo-API-Dockerized
sonar.sources=.
sonar.python.version=3.10

0 comments on commit 471c3a4

Please sign in to comment.