Skip to content

Commit 0d1511f

Browse files
committed
Create package.yml, fix build for stable release
1 parent c154c4f commit 0d1511f

File tree

5 files changed

+282
-102
lines changed

5 files changed

+282
-102
lines changed

.github/workflows/Steeltoe.All.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
name: Build and Test
3131
timeout-minutes: 30
3232
strategy:
33+
fail-fast: false
3334
matrix:
3435
os: [ubuntu-latest, windows-latest, macos-latest]
3536
include:

.github/workflows/package.yml

Lines changed: 279 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,291 @@ on:
88
- '[0-9]+.x'
99
- 'release/*'
1010
pull_request:
11+
release:
12+
types:
13+
- published
1114

1215
concurrency:
1316
group: ${{ github.workflow }}-${{ github.ref }}
1417
cancel-in-progress: true
1518

19+
permissions:
20+
contents: read
21+
22+
env:
23+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
24+
DOTNET_NOLOGO: true
25+
SOLUTION_FILE: 'src/Steeltoe.All.sln'
26+
VERSION_FILE: 'shared-package.props'
27+
1628
jobs:
17-
empty:
18-
name: Empty job
29+
build:
30+
name: Build
31+
timeout-minutes: 15
1932
runs-on: ubuntu-latest
2033

2134
steps:
22-
- name: Empty step
23-
run: echo "Packaging using GitHub Actions is not yet implemented."
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@v4
37+
with:
38+
dotnet-version: |
39+
8.0.*
40+
9.0.*
41+
42+
- name: Git checkout
43+
uses: actions/checkout@v4
44+
45+
- name: Restore packages
46+
run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal
47+
48+
- name: Calculate package version (for release)
49+
if: ${{ github.event_name == 'release' }}
50+
env:
51+
TAG_NAME: ${{ github.ref_name }}
52+
shell: pwsh
53+
run: |
54+
# Get the version suffix from the git tag. For example: '1.2.3-preview1-final' => 'preview1-final'
55+
$tagSegments = '${{ env.TAG_NAME }}' -split '-'
56+
$versionPrefix = $tagSegments[0]
57+
$versionSuffix = $tagSegments.Length -eq 1 ? '' : $tagSegments[1..$($tagSegments.Length - 1)] -join '-'
58+
59+
[xml]$xml = Get-Content $env:VERSION_FILE
60+
$configuredVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1
61+
62+
if ($configuredVersionPrefix -ne $versionPrefix) {
63+
Write-Error "Version prefix from git release tag '$versionPrefix' does not match version prefix '$configuredVersionPrefix' stored in $env:VERSION_FILE."
64+
# To recover from this:
65+
# - Delete the GitHub release
66+
# - Run: git push --delete origin the-invalid-tag-name
67+
# - Adjust VersionPrefix in file, commit and push
68+
# - Recreate the GitHub release
69+
}
70+
71+
Write-Output "Using version suffix: $versionSuffix"
72+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
73+
74+
- name: Calculate package version (for branch)
75+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
76+
env:
77+
BRANCH_NAME: ${{ github.ref_name }}
78+
shell: pwsh
79+
run: |
80+
# Get the version suffix from the branch name and auto-incrementing build number. For example: 'main' and '123' => 'main-00123'
81+
$revision = "{0:D5}" -f ${{ github.run_number }}
82+
$branchName = '${{ env.BRANCH_NAME }}'
83+
$safeBranchName = $branchName -Replace '[^a-zA-Z0-9-]', '-'
84+
$versionSuffix = "$safeBranchName-$revision"
85+
86+
Write-Output "Using version suffix: $versionSuffix"
87+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
88+
89+
- name: Calculate package version (for pr)
90+
if: ${{ github.event_name == 'pull_request' }}
91+
shell: pwsh
92+
run: |
93+
# Get the version suffix from the PR number and auto-incrementing build number. For example: '18' and '123' => 'pr18-00123'
94+
$revision = "{0:D5}" -f ${{ github.run_number }}
95+
$versionSuffix = "pr${{ github.event.number }}-$revision"
96+
97+
Write-Output "Using version suffix: $versionSuffix"
98+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
99+
100+
- name: Verify package version
101+
if: ${{ env.PACKAGE_VERSION_SUFFIX == '' && github.event_name != 'release' }}
102+
run: |
103+
echo "Package version suffix is empty. This should never happen."
104+
exit 1
105+
106+
- name: Build solution
107+
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
108+
109+
- name: Collect packages
110+
run: dotnet pack ${{ env.SOLUTION_FILE }} --no-build --configuration Release --output ${{ github.workspace }}/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
111+
112+
- name: Upload unsigned packages
113+
uses: actions/upload-artifact@v4
114+
with:
115+
if-no-files-found: error
116+
name: unsigned-packages
117+
path: ${{ github.workspace }}/packages/**/*.nupkg
118+
119+
sign:
120+
name: Sign
121+
if: ${{ github.event_name != 'pull_request' }}
122+
timeout-minutes: 15
123+
needs: build
124+
runs-on: windows-latest
125+
# TODO: Why do we have an environment for this?
126+
environment: signing
127+
permissions:
128+
id-token: write
129+
130+
steps:
131+
- name: Download unsigned packages
132+
uses: actions/download-artifact@v4
133+
with:
134+
name: unsigned-packages
135+
path: packages
136+
137+
- name: Setup .NET
138+
uses: actions/setup-dotnet@v4
139+
with:
140+
dotnet-version: 8.0.*
141+
142+
- name: Install code signing tool
143+
run: dotnet tool install --global sign --prerelease
144+
145+
- name: Azure login
146+
uses: azure/login@v2
147+
with:
148+
client-id: ${{ secrets.AZURE_KEY_VAULT_CLIENT_ID }}
149+
tenant-id: ${{ secrets.AZURE_KEY_VAULT_TENANT_ID }}
150+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
151+
152+
- name: Sign packages
153+
run: >-
154+
sign code azure-key-vault '**/*.nupkg'
155+
--base-directory '${{ github.workspace }}/packages'
156+
--azure-key-vault-managed-identity true
157+
--azure-credential-type 'azure-cli'
158+
--azure-key-vault-url '${{ secrets.AZURE_KEY_VAULT_URL }}'
159+
--azure-key-vault-certificate '${{ secrets.AZURE_KEY_VAULT_CERTIFICATE_ID }}'
160+
--publisher-name 'Steeltoe'
161+
--description 'Steeltoe'
162+
--description-url 'https://steeltoe.io/'
163+
164+
- name: Upload signed packages
165+
uses: actions/upload-artifact@v4
166+
with:
167+
if-no-files-found: error
168+
name: signed-packages
169+
path: ${{ github.workspace }}/packages/**/*.nupkg
170+
171+
dev-feed-deploy:
172+
name: Deploy packages to development feed
173+
timeout-minutes: 15
174+
needs: sign
175+
if: ${{ github.event_name != 'pull_request' }}
176+
environment: azdo
177+
runs-on: ubuntu-latest
178+
permissions:
179+
id-token: write
180+
env:
181+
# TODO: AZURE_ARTIFACTS_FEED_URL could be an org-wide var/secret.
182+
AZURE_ARTIFACTS_FEED_URL: https://pkgs.dev.azure.com/dotnet/Steeltoe/_packaging/dev/nuget/v3/index.json
183+
VSS_NUGET_URI_PREFIXES: https://pkgs.dev.azure.com/dotnet/
184+
185+
steps:
186+
- name: Azure login
187+
uses: azure/login@v2
188+
with:
189+
# TODO: Are we happy with the names of these secrets, or should we rename to distinguish between signing/keyvault/foundation/azdo? Because "Azure" is pretty vague.
190+
# TODO: Verify we have no redundant variables and secrets in GitHub org/repo/environment settings.
191+
client-id: ${{ secrets.AZURE_KEY_VAULT_CLIENT_ID }}
192+
tenant-id: ${{ secrets.AZURE_KEY_VAULT_TENANT_ID }}
193+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
194+
195+
- name: Download signed packages
196+
uses: actions/download-artifact@v4
197+
with:
198+
name: signed-packages
199+
path: packages
200+
201+
- name: Setup .NET
202+
uses: actions/setup-dotnet@v4
203+
with:
204+
dotnet-version: 8.0.x
205+
source-url: ${{ env.AZURE_ARTIFACTS_FEED_URL }}
206+
env:
207+
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208+
209+
- name: Install credential provider for Azure Artifacts
210+
run: sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)"
211+
212+
- name: Extract access token
213+
run: |
214+
accessToken=$(az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv)
215+
echo "::add-mask::$accessToken"
216+
echo "ACCESS_TOKEN=$accessToken" >> $GITHUB_ENV
217+
218+
- name: Configure authentication provider to use Azure DevOps token
219+
run: echo "VSS_NUGET_ACCESSTOKEN=$ACCESS_TOKEN" >> $GITHUB_ENV
220+
221+
- name: Push packages to Azure Artifacts
222+
# TODO: What's the meaning of azdo-placeholder?
223+
run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key 'azdo-placeholder' --source '${{ env.AZURE_ARTIFACTS_FEED_URL }}'
224+
225+
nuget-org-deploy:
226+
name: Deploy packages to nuget.org
227+
timeout-minutes: 15
228+
needs: sign
229+
if: ${{ github.event_name == 'release' }}
230+
environment: nuget.org
231+
runs-on: ubuntu-latest
232+
233+
steps:
234+
- name: Setup .NET
235+
uses: actions/setup-dotnet@v4
236+
with:
237+
dotnet-version: 8.0.x
238+
239+
- name: Download signed packages
240+
uses: actions/download-artifact@v4
241+
with:
242+
name: signed-packages
243+
path: packages
244+
245+
- name: Push packages to nuget.org
246+
run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.STEELTOE_NUGET_API_KEY }}' --source 'nuget.org'
247+
248+
open_pr:
249+
name: Open pull request to bump Steeltoe version after release
250+
needs: nuget-org-deploy
251+
timeout-minutes: 15
252+
runs-on: ubuntu-latest
253+
permissions:
254+
contents: write
255+
pull-requests: write
256+
257+
steps:
258+
- name: Git checkout
259+
uses: actions/checkout@v4
260+
261+
- name: Calculate next package version
262+
shell: pwsh
263+
run: |
264+
[xml]$xml = Get-Content $env:VERSION_FILE
265+
$oldVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1
266+
267+
$versionSegments = $oldVersionPrefix.split('.')
268+
([int]$versionSegments[-1])++
269+
$newVersionPrefix = $versionSegments -join('.')
270+
271+
Write-Output "OLD_PACKAGE_VERSION_PREFIX=$oldVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
272+
Write-Output "NEW_PACKAGE_VERSION_PREFIX=$newVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
273+
274+
- name: Open pull request
275+
env:
276+
GH_TOKEN: ${{ github.token }}
277+
shell: pwsh
278+
run: |
279+
$oldVersionPrefix = '${{ env.OLD_PACKAGE_VERSION_PREFIX }}'
280+
$newVersionPrefix = '${{ env.NEW_PACKAGE_VERSION_PREFIX }}'
281+
$prBranchName = "bump-version-to-$newVersionPrefix-${{ github.run_number }}"
282+
$commitMessage = "Bump Steeltoe version from $oldVersionPrefix to $newVersionPrefix."
283+
284+
$pattern = '(?<left>^\s*\<VersionPrefix\>)[^>]+(?<right>\<\/VersionPrefix\>)\s*$'
285+
$fileContent = Get-Content $env:VERSION_FILE
286+
$fileContent = $fileContent -Replace $pattern,"`${left}$newVersionPrefix`${right}"
287+
Set-Content $fileContent -Path $env:VERSION_FILE
288+
289+
Write-Output "Creating pull request for commit: $commitMessage"
290+
git config --global user.name '${{ env.GIT_USERNAME }}'
291+
git config --global user.email '${{ env.GIT_USERNAME }}@noreply.github.com'
292+
git checkout -b $prBranchName
293+
git add -A
294+
git commit -m $commitMessage
295+
git push --set-upstream origin $prBranchName
296+
297+
Write-Output "Opening pull request to merge $prBranchName."
298+
gh pr create --head $prBranchName --title 'Bump Steeltoe version' --body $commitMessage

.github/workflows/verify-code-style.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
dotnet regitlint -s ${{ env.SOLUTION_FILE }} --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="Steeltoe Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --properties:NuGetAudit=false --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
5959
6060
- name: CleanupCode (on branch)
61-
if: ${{ github.event_name == 'push' || github.event_name == 'release' }}
61+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'release' }}
6262
shell: pwsh
6363
run: |
6464
Write-Output "Running code cleanup on all files."

0 commit comments

Comments
 (0)