Implement Sonar #26
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pipeline | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
types: [opened, synchronize, reopened] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
# setup Sonar | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'zulu' # Alternative distribution options are available. | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v3 | |
with: | |
path: ~\sonar\cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Cache SonarCloud scanner | |
id: cache-sonar-scanner | |
uses: actions/cache@v3 | |
with: | |
path: .\.sonar\scanner | |
key: ${{ runner.os }}-sonar-scanner | |
restore-keys: ${{ runner.os }}-sonar-scanner | |
- name: Install SonarCloud scanner | |
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' | |
run: | | |
mkdir .sonar/scanner | |
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner | |
# setup .NET | |
- name: Setup .NET Core SDK 7 | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 7.0.x | |
# setup project dependencies | |
- name: Download katai struct compiler | |
run: | | |
wget https://github.com/kaitai-io/kaitai_struct_compiler/releases/download/0.9/kaitai-struct-compiler-0.9.zip | |
unzip kaitai-struct-compiler-0.9.zip | |
PATH="${PWD}/kaitai-struct-compiler-0.9/bin/:${PATH}" | |
sudo apt-get update && sudo apt-get install -y openjdk-8-jre | |
cd Executables/Game | |
sudo chmod +x generate_kaitai.sh | |
./generate_kaitai.sh | |
- name: Install dependencies | |
run: dotnet restore | |
# actual build | |
- name: Build and analyze | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
./.sonar/scanner/dotnet-sonarscanner begin /k:"MeikelLP_quantum-core-x" /o:"meikel" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" | |
dotnet build --configuration Release --no-restore | |
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | |
# finally tests | |
- name: Test | |
run: dotnet test --no-restore --verbosity normal | |
deploy: | |
needs: | |
- test | |
runs-on: ubuntu-latest | |
# only deploy if on master or tag | |
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Login to Docker Registry | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: ${{ env.REGISTRY }} | |
# game | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta-game | |
uses: docker/[email protected] | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/game | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=tag | |
type=raw,latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} | |
- name: Build and push game image | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: Executables/Game/Dockerfile | |
push: true | |
tags: ${{ steps.meta-game.outputs.tags }} | |
labels: ${{ steps.meta-game.outputs.labels }} | |
# auth | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta-auth | |
uses: docker/[email protected] | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/auth | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=tag | |
type=raw,latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} | |
- name: Build and push auth image | |
uses: docker/[email protected] | |
with: | |
context: . | |
images: ghcr.io/meikellp/quantum-core-x/auth | |
file: Executables/Auth/Dockerfile | |
push: true | |
tags: ${{ steps.meta-auth.outputs.tags }} | |
labels: ${{ steps.meta-auth.outputs.labels }} | |
# migrator | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta-migrator | |
uses: docker/[email protected] | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/migrator | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=tag | |
type=raw,latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} | |
- name: Build and push migrator image | |
uses: docker/[email protected] | |
with: | |
context: . | |
images: ghcr.io/meikellp/quantum-core-x/migrator | |
file: Executables/Migrator/Dockerfile | |
push: true | |
tags: ${{ steps.meta-migrator.outputs.tags }} | |
labels: ${{ steps.meta-migrator.outputs.labels }} |