Skip to content

Update GitHub Actions workflow #441

Update GitHub Actions workflow

Update GitHub Actions workflow #441

Workflow file for this run

#
# GitHub Actions workflow: Builds and tests the code in this repository.
#
# For more details on workflows, see README.md.
#
# IMPORTANT: When changing this name, also change the name in the trigger section in "test-report.yaml".
name: CI
# When to run this workflow
#
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
#
# TIP: Don't use "schedule" triggers as this will cause the workflow to be disabled after 60 days of inactivity
# (and afterward the workflow must be manually reenabled).
on:
# Trigger the workflow on push to the main branch.
push:
branches:
- main
# Trigger the workflow for any pull requests.
pull_request:
# Allow manual run of this workflow (https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow)
workflow_dispatch:
# Permissions for GITHUB_TOKEN for this workflow.
#
# See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
#
# NOTE: Because we run with minimal permissions, we use "@vX" (instead of "@hash") for non-GitHub steps below.
# Usually you would use "@hash" as a security measure to pin a specific version. However, since we run with
# minimal permissions here, malicious code can't do much harm (most likely). For more details, see:
# https://blog.gitguardian.com/github-actions-security-cheat-sheet/#use-specific-action-version-tags
permissions:
contents: read
env:
DOTNET_VERSION: '7.0'
# NOTE: Jobs run in parallel by default.
# https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow
jobs:
#
# Build & Test job
#
build-and-test:
# Name of the job
name: Build & Test
# Set the type of machine to run on
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
steps:
###########################################################################
#
# Setup Steps
#
###########################################################################
# See: https://github.com/marketplace/actions/checkout
- name: Clone Git repository
uses: actions/checkout@v4
with:
lfs: true
submodules: true
# This creates ${{ steps.short-sha.outputs.sha }} to be used below.
# See: https://github.com/marketplace/actions/short-sha
- name: Determine Git short commit hash
id: short-sha
uses: benjlevesque/short-sha@v3.0
# See: https://github.com/marketplace/actions/setup-net-core-sdk
- name: Setup .NET build environment
uses: actions/setup-dotnet@v4
with:
# NOTE: Apparently only the 3rd component can be "x"; i.e. "5.x" is not supported.
dotnet-version: '${{ env.DOTNET_VERSION }}.x'
###########################################################################
#
# Build Steps
#
###########################################################################
# See: https://docs.microsoft.com/de-de/dotnet/core/tools/dotnet-build
# NOTE: Without specifying a solution file, "dotnet build" searches for a .sln file in the current directory.
- name: Build code
run: dotnet build --configuration Release
# See: https://docs.microsoft.com/de-de/dotnet/core/tools/dotnet-test
# NOTE: Without specifying a solution file, "dotnet test" searches for a .sln file in the current directory.
# NOTE 2: There seems to be no way to name the .trx file as '<project>.trx'. If no 'LogFileName' is specified,
# the .trx files will be named something like "_fv-az278-737_2021-08-15_03_50_33.trx".
- name: Run tests
id: run_tests
run: dotnet test --configuration Release --no-restore --no-build --logger "trx;LogFileName=${{ runner.os }}.trx" --nologo
env:
# Tells tests that they're running in a (potentially slow) CI environment.
RUNS_IN_CI: true
###########################################################################
#
# Archive Steps
#
###########################################################################
# See: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload test results
uses: actions/upload-artifact@v4
# Run this step even if "run_tests" has failed (but not if any other previous step has failed - which would
# be "failure()" - because in this case the tests have not run and thus no .trx files have been generated).
# See: https://docs.github.com/en/actions/learn-github-actions/expressions#failure
if: success() || steps.run_tests.conclusion == 'failure'
with:
# NOTE: To make the downloads of the test results easier to use (i.e. when downloading test results
# from different runs), we'll add an id to the name.
#
# We don't just use the sha because this workflow also runs on a schedule - which means that different
# runs would again create files with the same name (e.g. two consecutive scheduled runs while the
# repo hasn't changed in the meantime).
#
# Instead we use 'github.run_number' because this gives us the same number that's also shown in the
# ui - like 27 for run #27 ('github.run_id' on the other hand gives us some "random" big number like
# 1152888876 - which is less useful). For more details, see:
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
#
# NOTE: We put the "run_number" first so that the result zip file can be sorted by name.
name: 'test-results-#${{ github.run_number }}-${{ steps.short-sha.outputs.sha }}-${{ runner.os }}'
path: '**/*.trx'
if-no-files-found: error
#
# CodeQL job
#
codeql:
# Name of the job
name: CodeQL
# Set the type of machine to run on
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
permissions:
actions: read
security-events: write
steps:
###########################################################################
#
# Setup Steps
#
###########################################################################
# See: https://github.com/marketplace/actions/checkout
- name: Clone Git repository
uses: actions/checkout@v4
with:
lfs: true
submodules: true
# Initializes the CodeQL tools for scanning.
# See: https://github.com/github/codeql-action
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: csharp
# See: https://github.com/marketplace/actions/setup-net-core-sdk
- name: Setup .NET build environment
uses: actions/setup-dotnet@v4
with:
# NOTE: Apparently only the 3rd component can be "x"; i.e. "5.x" is not supported.
dotnet-version: '${{ env.DOTNET_VERSION }}.x'
###########################################################################
#
# Build Steps
#
###########################################################################
# See: https://docs.microsoft.com/de-de/dotnet/core/tools/dotnet-build
# NOTE: Without specifying a solution file, "dotnet build" searches for a .sln file in the current directory.
- name: Build code
run: dotnet build --configuration CodeQL_Release
# See: https://github.com/github/codeql-action
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3