Skip to content

Commit eb3e74a

Browse files
committed
Create package.yml
1 parent c154c4f commit eb3e74a

File tree

2 files changed

+152
-5
lines changed

2 files changed

+152
-5
lines changed

.github/workflows/package.yml

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

1214
concurrency:
1315
group: ${{ github.workflow }}-${{ github.ref }}
1416
cancel-in-progress: true
1517

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

2133
steps:
22-
- name: Empty step
23-
run: echo "Packaging using GitHub Actions is not yet implemented."
34+
- name: Setup .NET
35+
uses: actions/setup-dotnet@v4
36+
with:
37+
dotnet-version: |
38+
8.0.*
39+
9.0.*
40+
41+
- name: Git checkout
42+
uses: actions/checkout@v4
43+
44+
- name: Restore packages
45+
run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal
46+
47+
- name: Calculate package version (for release)
48+
if: ${{ github.event_name == 'release' }}
49+
env:
50+
TAG_NAME: ${{ github.ref_name }}
51+
shell: pwsh
52+
run: |
53+
# Get the version suffix from the git tag. For example: '1.2.3-preview1-final' => '1.2.3' and 'preview1-final'
54+
$tagSegments = '${{ env.TAG_NAME }}' -split '-'
55+
$versionPrefix = $tagSegments[0]
56+
$versionSuffix = $tagSegments.Length -eq 1 ? '' : $tagSegments[1..$($tagSegments.Length - 1)] -join '-'
57+
58+
[xml]$xml = Get-Content $env:VERSION_FILE
59+
$configuredVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1
60+
61+
if ($configuredVersionPrefix -ne $versionPrefix) {
62+
Write-Error "Version prefix from git release tag '$versionPrefix' does not match version prefix '$configuredVersionPrefix' stored in $env:VERSION_FILE."
63+
# To recover from this:
64+
# - Delete the GitHub release
65+
# - Run: git push --delete origin the-invalid-tag-name
66+
# - Adjust VersionPrefix in file, commit and push
67+
# - Recreate the GitHub release
68+
}
69+
70+
Write-Output "Using version suffix: $versionSuffix"
71+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
72+
73+
- name: Calculate package version (for branch)
74+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
75+
env:
76+
BRANCH_NAME: ${{ github.ref_name }}
77+
shell: pwsh
78+
run: |
79+
# Get the version suffix from the branch name and auto-incrementing build number. For example: 'main' and '123' => 'main-00123'
80+
$revision = "{0:D5}" -f ${{ github.run_number }}
81+
$branchName = '${{ env.BRANCH_NAME }}'
82+
$safeBranchName = $branchName -Replace '[^a-zA-Z0-9_]', '_'
83+
$versionSuffix = "$safeBranchName-$revision"
84+
85+
Write-Output "Using version suffix: $versionSuffix"
86+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
87+
88+
- name: Calculate package version (for pr)
89+
if: ${{ github.event_name == 'pull_request' }}
90+
shell: pwsh
91+
run: |
92+
# Get the version suffix from the PR number and auto-incrementing build number. For example: '18' and '123' => 'pr18-00123'
93+
$revision = "{0:D5}" -f ${{ github.run_number }}
94+
$versionSuffix = "pr${{ github.event.number }}-$revision"
95+
96+
Write-Output "Using version suffix: $versionSuffix"
97+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
98+
99+
- name: Verify package version
100+
if: ${{ env.PACKAGE_VERSION_SUFFIX == '' && github.event_name != 'release' }}
101+
run: |
102+
echo "Package version suffix is empty. This should never happen."
103+
exit 1
104+
105+
- name: Build solution
106+
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
107+
108+
- name: Collect packages
109+
run: dotnet pack ${{ env.SOLUTION_FILE }} --no-build --configuration Release --output ${{ github.workspace }}/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
110+
111+
- name: Upload packages
112+
uses: actions/upload-artifact@v4
113+
with:
114+
if-no-files-found: error
115+
name: unsigned-packages
116+
path: ${{ github.workspace }}/packages/**/*.nupkg
117+
118+
open_pr:
119+
name: Open pull request to bump package version (after release)
120+
if: ${{ github.event_name == 'release' }}
121+
needs: build
122+
timeout-minutes: 15
123+
runs-on: ubuntu-latest
124+
permissions:
125+
contents: write
126+
pull-requests: write
127+
128+
steps:
129+
- name: Git checkout
130+
uses: actions/checkout@v4
131+
132+
- name: Calculate next package version
133+
shell: pwsh
134+
run: |
135+
[xml]$xml = Get-Content $env:VERSION_FILE
136+
$oldVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1
137+
138+
$versionSegments = $oldVersionPrefix.split('.')
139+
([int]$versionSegments[-1])++
140+
$newVersionPrefix = $versionSegments -join('.')
141+
142+
Write-Output "OLD_PACKAGE_VERSION_PREFIX=$oldVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
143+
Write-Output "NEW_PACKAGE_VERSION_PREFIX=$newVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
144+
145+
- name: Open pull request
146+
env:
147+
GIT_USERNAME: ${{ github.actor }}
148+
GH_TOKEN: ${{ github.token }}
149+
shell: pwsh
150+
run: |
151+
$oldVersionPrefix = '${{ env.OLD_PACKAGE_VERSION_PREFIX }}'
152+
$newVersionPrefix = '${{ env.NEW_PACKAGE_VERSION_PREFIX }}'
153+
$prBranchName = "bump-version-to-$newVersionPrefix-${{ github.run_number }}"
154+
$commitMessage = "Bump Steeltoe version from $oldVersionPrefix to $newVersionPrefix."
155+
156+
$pattern = '(?<left>^\s*\<VersionPrefix\>)[^>]+(?<right>\<\/VersionPrefix\>)\s*$'
157+
$fileContent = Get-Content $env:VERSION_FILE
158+
$fileContent = $fileContent -Replace $pattern,"`${left}$newVersionPrefix`${right}"
159+
Set-Content $fileContent -Path $env:VERSION_FILE
160+
161+
Write-Output "Creating pull request for commit: $commitMessage"
162+
git config --global user.name '${{ env.GIT_USERNAME }}'
163+
git config --global user.email '${{ env.GIT_USERNAME }}@noreply.github.com'
164+
git checkout -b $prBranchName
165+
git add -A
166+
git commit -m $commitMessage
167+
git push --set-upstream origin $prBranchName
168+
169+
Write-Output "Opening pull request to merge $prBranchName."
170+
gh pr create --head $prBranchName --title 'Bump Steeltoe version' --body $commitMessage

src/Management/src/Prometheus/Steeltoe.Management.Prometheus.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Extensions.Configuration" Version="$(FoundationalVersion)" />
1313
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(FoundationalVersion)" />
14-
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="$(OpenTelemetryExporterPrometheusVersion)" />
14+
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="$(OpenTelemetryExporterPrometheusVersion)" NoWarn="NU5104" />
1515
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="$(OpenTelemetryVersion)" />
1616
</ItemGroup>
1717

0 commit comments

Comments
 (0)