ci: enable workflow_dispatch event #45
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: Build on main | |
on: | |
push: | |
branches: main | |
pull_request: | |
branches: main | |
workflow_dispatch: | |
permissions: | |
checks: write | |
pull-requests: write | |
jobs: | |
unit-test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Run Tests | |
run: dotnet test --verbosity normal --logger trx --results-directory TestResults | |
- name: Publish Test Results to Workflow | |
uses: EnricoMi/publish-unit-test-result-action@v2 | |
if: always() | |
with: | |
check_name: test-results | |
comment_title: Test Results | |
files: | | |
TestResults/*.trx | |
snapcraft-build: | |
runs-on: ubuntu-latest | |
needs: unit-test | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run Snapcraft | |
id: snapcraft | |
uses: snapcore/action-build@v1 | |
- name: Upload Snap to workflow artifacts | |
id: upload-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: snap | |
path: ${{ steps.snapcraft.outputs.snap }} | |
snapcraft-publish: | |
runs-on: ubuntu-latest | |
if: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && github.ref_name == 'main' }} | |
needs: snapcraft-build | |
steps: | |
- uses: actions/download-artifact@v4 | |
id: download-artifact | |
with: | |
name: snap | |
- name: Gather filename | |
id: gather-filename | |
env: | |
ARTIFACT_PATH: ${{ steps.download-artifact.outputs.download-path }} | |
run: | | |
ls -la $ARTIFACT_PATH | |
SNAP_FILE_NAME=$(ls ${ARTIFACT_PATH}/${SNAP_NAME}*.snap) | |
echo "SNAP_PATH=${SNAP_FILE_NAME}" >> "$GITHUB_OUTPUT" | |
- uses: snapcore/action-publish@v1 | |
env: | |
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_STORE_LOGIN }} | |
with: | |
snap: ${{ steps.gather-filename.outputs.SNAP_PATH }} | |
release: edge | |
publish-coverage: | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' }} | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Install reportgenerator tool | |
run: | | |
dotnet tool install -g dotnet-reportgenerator-globaltool | |
- name: Generate Coverage report | |
run: | | |
dotnet test --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory TestResults | |
reportgenerator -reports:TestResults/*/coverage.cobertura.xml -targetdir:TestResults/Html/coverage -reporttypes:'Html' | |
- name: Commit Coverage files | |
run: | | |
cd TestResults/Html | |
git init | |
git add -A | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git commit -m 'deploy' | |
- name: Push to GH Pages branch | |
uses: ad-m/github-push-action@v0.8.0 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: gh-pages | |
force: true | |
directory: ./TestResults/Html |