Skip to content

Commit 39ba5d0

Browse files
authored
Sync up GitHub Actions workflows, to allow runs from branch (#102)
1 parent 731970b commit 39ba5d0

File tree

2 files changed

+26
-47
lines changed

2 files changed

+26
-47
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
name: Build
1010

1111
on:
12-
push:
13-
branches: [ 'master', 'release/**' ]
12+
workflow_dispatch:
1413
pull_request:
14+
push:
1515
branches: [ 'master', 'release/**' ]
1616
release:
1717
types: [published]
@@ -51,17 +51,15 @@ jobs:
5151
- name: Git checkout
5252
uses: actions/checkout@v5
5353
- name: Restore tools
54-
run: |
55-
dotnet tool restore
54+
run: dotnet tool restore
5655
- name: Restore packages
57-
run: |
58-
dotnet restore
56+
run: dotnet restore
5957
- name: Calculate version suffix
6058
shell: pwsh
6159
run: |
6260
if ($env:GITHUB_REF_TYPE -eq 'tag') {
6361
# Get the version prefix/suffix from the git tag. For example: 'v1.0.0-preview1-final' => '1.0.0' and 'preview1-final'
64-
$segments = $env:GITHUB_REF_NAME -split "-"
62+
$segments = $env:GITHUB_REF_NAME -split '-'
6563
$versionPrefix = $segments[0].TrimStart('v')
6664
$versionSuffix = $segments.Length -eq 1 ? '' : $segments[1..$($segments.Length - 1)] -join '-'
6765
@@ -87,26 +85,21 @@ jobs:
8785
Write-Output "Using version suffix: $versionSuffix"
8886
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
8987
- name: Build
90-
shell: pwsh
91-
run: |
92-
dotnet build --no-restore --configuration Release /p:VersionSuffix=$env:PACKAGE_VERSION_SUFFIX
88+
run: dotnet build --no-restore --configuration Release /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
9389
- name: Test
94-
run: |
95-
dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true"
90+
run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true"
9691
- name: Upload coverage to codecov.io
97-
if: matrix.os == 'ubuntu-latest'
92+
if: ${{ matrix.os == 'ubuntu-latest' }}
9893
env:
9994
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
10095
uses: codecov/codecov-action@v5
10196
with:
10297
fail_ci_if_error: true
10398
verbose: true
10499
- name: Generate packages
105-
shell: pwsh
106-
run: |
107-
dotnet pack --no-build --configuration Release --output $env:GITHUB_WORKSPACE/artifacts/packages /p:VersionSuffix=$env:PACKAGE_VERSION_SUFFIX
100+
run: dotnet pack --no-build --configuration Release --output ${{ github.workspace }}/artifacts/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
108101
- name: Upload packages to artifacts
109-
if: matrix.os == 'ubuntu-latest'
102+
if: ${{ matrix.os == 'ubuntu-latest' }}
110103
uses: actions/upload-artifact@v4
111104
with:
112105
name: packages
@@ -133,8 +126,7 @@ jobs:
133126
- name: Git checkout
134127
uses: actions/checkout@v5
135128
- name: Restore tools
136-
run: |
137-
dotnet tool restore
129+
run: dotnet tool restore
138130
- name: InspectCode
139131
shell: pwsh
140132
run: |
@@ -163,7 +155,7 @@ jobs:
163155
}
164156
165157
if ($failed) {
166-
Write-Error "One or more projects failed code inspection."
158+
Write-Error 'One or more projects failed code inspection.'
167159
}
168160
}
169161
@@ -190,13 +182,11 @@ jobs:
190182
with:
191183
fetch-depth: 2
192184
- name: Restore tools
193-
run: |
194-
dotnet tool restore
185+
run: dotnet tool restore
195186
- name: Restore packages
196-
run: |
197-
dotnet restore
187+
run: dotnet restore
198188
- name: CleanupCode (on PR diff)
199-
if: github.event_name == 'pull_request'
189+
if: ${{ github.event_name == 'pull_request' }}
200190
shell: pwsh
201191
run: |
202192
# 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:
207197
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash in pull request."
208198
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
209199
- name: CleanupCode (on branch)
210-
if: github.event_name == 'push' || github.event_name == 'release'
200+
if: ${{ github.event_name == 'push' || github.event_name == 'release' }}
211201
shell: pwsh
212202
run: |
213-
Write-Output "Running code cleanup on all files."
203+
Write-Output 'Running code cleanup on all files.'
214204
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
215205
216206
publish:
@@ -227,25 +217,15 @@ jobs:
227217
- name: Download artifacts
228218
uses: actions/download-artifact@v4
229219
- name: Publish to GitHub Packages
230-
if: github.event_name == 'push' || github.event_name == 'release'
231-
env:
232-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
233-
shell: pwsh
220+
if: ${{ github.event_name == 'push' || github.event_name == 'release' }}
234221
run: |
235-
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'
236-
dotnet nuget push "$env:GITHUB_WORKSPACE/packages/*.nupkg" --api-key "$env:GITHUB_TOKEN" --source 'github'
222+
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'
223+
dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.GITHUB_TOKEN }}' --source 'github'
237224
- name: Publish to feedz.io
238-
if: github.event_name == 'push' || github.event_name == 'release'
239-
env:
240-
FEEDZ_IO_API_KEY: ${{ secrets.FEEDZ_IO_API_KEY }}
241-
shell: pwsh
225+
if: ${{ github.event_name == 'push' || github.event_name == 'release' }}
242226
run: |
243227
dotnet nuget add source --name 'feedz-io' 'https://f.feedz.io/json-api-dotnet/jsonapidotnetcore/nuget/index.json'
244-
dotnet nuget push "$env:GITHUB_WORKSPACE/packages/*.nupkg" --api-key "$env:FEEDZ_IO_API_KEY" --source 'feedz-io'
228+
dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.FEEDZ_IO_API_KEY }}' --source 'feedz-io'
245229
- name: Publish to NuGet
246-
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')
247-
env:
248-
NUGET_ORG_API_KEY: ${{ secrets.NUGET_ORG_API_KEY }}
249-
shell: pwsh
250-
run: |
251-
dotnet nuget push "$env:GITHUB_WORKSPACE/packages/*.nupkg" --api-key "$env:NUGET_ORG_API_KEY" --source 'nuget.org'
230+
if: ${{ github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v') }}
231+
run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.NUGET_ORG_API_KEY }}' --source 'nuget.org' --skip-duplicate

.github/workflows/codeql.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
name: "CodeQL"
22

33
on:
4-
push:
5-
branches: [ 'master', 'release/**' ]
4+
workflow_dispatch:
65
pull_request:
7-
# The branches below must be a subset of the branches above
6+
push:
87
branches: [ 'master', 'release/**' ]
98
schedule:
109
- cron: '0 0 * * 5'

0 commit comments

Comments
 (0)