From 0627aaa959bdaa7bfad89e0aaf7f860835fe6c39 Mon Sep 17 00:00:00 2001 From: Bart Koelman <10324372+bkoelman@users.noreply.github.com> Date: Sat, 16 Aug 2025 14:35:22 +0200 Subject: [PATCH] Sync up GitHub Actions workflows, to allow runs from branch --- .github/workflows/build.yml | 68 +++++++++++++----------------------- .github/workflows/codeql.yml | 5 ++- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea258d4..e282c89 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,9 +9,9 @@ name: Build on: - push: - branches: [ 'master', 'release/**' ] + workflow_dispatch: pull_request: + push: branches: [ 'master', 'release/**' ] release: types: [published] @@ -51,17 +51,15 @@ jobs: - name: Git checkout uses: actions/checkout@v5 - name: Restore tools - run: | - dotnet tool restore + run: dotnet tool restore - name: Restore packages - run: | - dotnet restore + run: dotnet restore - name: Calculate version suffix shell: pwsh run: | if ($env:GITHUB_REF_TYPE -eq 'tag') { # Get the version prefix/suffix from the git tag. For example: 'v1.0.0-preview1-final' => '1.0.0' and 'preview1-final' - $segments = $env:GITHUB_REF_NAME -split "-" + $segments = $env:GITHUB_REF_NAME -split '-' $versionPrefix = $segments[0].TrimStart('v') $versionSuffix = $segments.Length -eq 1 ? '' : $segments[1..$($segments.Length - 1)] -join '-' @@ -87,14 +85,11 @@ jobs: Write-Output "Using version suffix: $versionSuffix" Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - name: Build - shell: pwsh - run: | - dotnet build --no-restore --configuration Release /p:VersionSuffix=$env:PACKAGE_VERSION_SUFFIX + run: dotnet build --no-restore --configuration Release /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} - name: Test - run: | - dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true" + run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true" - name: Upload coverage to codecov.io - if: matrix.os == 'ubuntu-latest' + if: ${{ matrix.os == 'ubuntu-latest' }} env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} uses: codecov/codecov-action@v5 @@ -102,11 +97,9 @@ jobs: fail_ci_if_error: true verbose: true - name: Generate packages - shell: pwsh - run: | - dotnet pack --no-build --configuration Release --output $env:GITHUB_WORKSPACE/artifacts/packages /p:VersionSuffix=$env:PACKAGE_VERSION_SUFFIX + run: dotnet pack --no-build --configuration Release --output ${{ github.workspace }}/artifacts/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} - name: Upload packages to artifacts - if: matrix.os == 'ubuntu-latest' + if: ${{ matrix.os == 'ubuntu-latest' }} uses: actions/upload-artifact@v4 with: name: packages @@ -133,8 +126,7 @@ jobs: - name: Git checkout uses: actions/checkout@v5 - name: Restore tools - run: | - dotnet tool restore + run: dotnet tool restore - name: InspectCode shell: pwsh run: | @@ -163,7 +155,7 @@ jobs: } if ($failed) { - Write-Error "One or more projects failed code inspection." + Write-Error 'One or more projects failed code inspection.' } } @@ -190,13 +182,11 @@ jobs: with: fetch-depth: 2 - name: Restore tools - run: | - dotnet tool restore + run: dotnet tool restore - name: Restore packages - run: | - dotnet restore + run: dotnet restore - name: CleanupCode (on PR diff) - if: github.event_name == 'pull_request' + if: ${{ github.event_name == 'pull_request' }} shell: pwsh run: | # Not using the environment variables for SHAs, because they may be outdated. This may happen on force-push after the build is queued, but before it starts. @@ -207,10 +197,10 @@ jobs: Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash in pull request." dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff - name: CleanupCode (on branch) - if: github.event_name == 'push' || github.event_name == 'release' + if: ${{ github.event_name == 'push' || github.event_name == 'release' }} shell: pwsh run: | - Write-Output "Running code cleanup on all files." + Write-Output 'Running code cleanup on all files.' dotnet regitlint -s JsonApiDotNetCore.MongoDb.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --verbosity=WARN --fail-on-diff --print-diff publish: @@ -227,25 +217,15 @@ jobs: - name: Download artifacts uses: actions/download-artifact@v4 - name: Publish to GitHub Packages - if: github.event_name == 'push' || github.event_name == 'release' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - shell: pwsh + if: ${{ github.event_name == 'push' || github.event_name == 'release' }} run: | - dotnet nuget add source --username 'json-api-dotnet' --password "$env:GITHUB_TOKEN" --store-password-in-clear-text --name 'github' 'https://nuget.pkg.github.com/json-api-dotnet/index.json' - dotnet nuget push "$env:GITHUB_WORKSPACE/packages/*.nupkg" --api-key "$env:GITHUB_TOKEN" --source 'github' + dotnet nuget add source --username 'json-api-dotnet' --password '${{ secrets.GITHUB_TOKEN }}' --store-password-in-clear-text --name 'github' 'https://nuget.pkg.github.com/json-api-dotnet/index.json' + dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.GITHUB_TOKEN }}' --source 'github' - name: Publish to feedz.io - if: github.event_name == 'push' || github.event_name == 'release' - env: - FEEDZ_IO_API_KEY: ${{ secrets.FEEDZ_IO_API_KEY }} - shell: pwsh + if: ${{ github.event_name == 'push' || github.event_name == 'release' }} run: | dotnet nuget add source --name 'feedz-io' 'https://f.feedz.io/json-api-dotnet/jsonapidotnetcore/nuget/index.json' - dotnet nuget push "$env:GITHUB_WORKSPACE/packages/*.nupkg" --api-key "$env:FEEDZ_IO_API_KEY" --source 'feedz-io' + dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.FEEDZ_IO_API_KEY }}' --source 'feedz-io' - name: Publish to NuGet - if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v') - env: - NUGET_ORG_API_KEY: ${{ secrets.NUGET_ORG_API_KEY }} - shell: pwsh - run: | - dotnet nuget push "$env:GITHUB_WORKSPACE/packages/*.nupkg" --api-key "$env:NUGET_ORG_API_KEY" --source 'nuget.org' + if: ${{ github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v') }} + run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.NUGET_ORG_API_KEY }}' --source 'nuget.org' --skip-duplicate diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 429a933..ccea231 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,10 +1,9 @@ name: "CodeQL" on: - push: - branches: [ 'master', 'release/**' ] + workflow_dispatch: pull_request: - # The branches below must be a subset of the branches above + push: branches: [ 'master', 'release/**' ] schedule: - cron: '0 0 * * 5'