Build #68
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
# This workflow will build a .NET project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | |
name: Build | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
projectVersion: v0.0.1 | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'zulu' # Alternative distribution options are available. | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: '0' | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
global-json-file: ./global.json | |
- name: Install SonarCloud scanner | |
run: | | |
mkdir ./.sonar/ | |
mkdir ./.sonar/scanner/ | |
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner | |
- name: Restore dependencies | |
run: dotnet restore --runtime linux-x64 /property:Configuration=Release | |
- name: Build, test and analize | |
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:"ValMati_StockBot" /o:"valmati" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /v:="${{ env.projectVersion }}" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" | |
dotnet build -c Release --no-restore --no-self-contained | |
dotnet test -c Release --no-build --collect:"XPlat Code Coverage;Format=opencover" | |
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | |
- name: Prepare docker image | |
id: prep | |
run: | | |
DOCKER_IMAGE=${{ secrets.IMGREG_ENDPOINT }}/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/} | |
DOCKER_IMAGE=${DOCKER_IMAGE@L} | |
VERSION=latest | |
SHORTREF=${GITHUB_SHA::8} | |
# If this is git tag, use the tag name as a docker tag | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/v} | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}" | |
# If the VERSION looks like a version number, assume that | |
# this is the most recent version of the image and also | |
# tag it 'latest'. | |
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | |
TAGS="$TAGS,${DOCKER_IMAGE}:latest" | |
fi | |
# Set output parameters. | |
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | |
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT | |
- name: Build docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: false | |
platforms: linux/amd64 | |
tags: ${{ steps.prep.outputs.tags }} | |
- name: SonarCloud Scan (for other files) | |
uses: sonarsource/sonarcloud-github-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
with: | |
args: > | |
-Dsonar.organization=valmati | |
-Dsonar.projectKey=ValMati_StockBot_OtherFiles | |
-Dsonar.projectVersion=${{ env.projectVersion }} |