Skip to content

Commit b0b819c

Browse files
committed
Create package.yml
1 parent 39c1bf1 commit b0b819c

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

.github/workflows/package.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Package
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- '[0-9]+.x'
9+
- 'release/*'
10+
pull_request:
11+
release:
12+
types: [ published ]
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
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+
26+
jobs:
27+
build:
28+
name: Build
29+
timeout-minutes: 15
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Setup .NET
34+
uses: actions/setup-dotnet@v4
35+
with:
36+
dotnet-version: |
37+
8.0.*
38+
9.0.*
39+
40+
- name: Git checkout
41+
uses: actions/checkout@v4
42+
43+
- name: Restore packages
44+
run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal
45+
46+
- name: Calculate package version (for release)
47+
if: ${{ github.event_name == 'release' }}
48+
env:
49+
TAG_NAME: ${{ github.ref_name }}
50+
shell: pwsh
51+
run: |
52+
# Get the version suffix from the git tag. For example: '1.2.3-preview1-final' => '1.2.3' and 'preview1-final'
53+
$tagSegments = '${{ env.TAG_NAME }}' -split '-'
54+
$versionPrefix = $tagSegments[0]
55+
$versionSuffix = $tagSegments.Length -eq 1 ? '' : $tagSegments[1..$($tagSegments.Length - 1)] -join '-'
56+
57+
[xml]$xml = Get-Content shared-package.props
58+
$configuredVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1
59+
60+
if ($configuredVersionPrefix -ne $versionPrefix) {
61+
Write-Error "Version prefix from git release tag '$versionPrefix' does not match version prefix '$configuredVersionPrefix' stored in shared-package.props."
62+
# To recover from this:
63+
# - Delete the GitHub release
64+
# - Run: git push --delete origin the-invalid-tag-name
65+
# - Adjust VersionPrefix in shared-package.props, commit and push
66+
# - Recreate the GitHub release
67+
}
68+
69+
Write-Output "Using version suffix: $versionSuffix"
70+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
71+
72+
- name: Calculate package version (for branch)
73+
if: ${{ github.event_name == 'push' }}
74+
env:
75+
BRANCH_NAME: ${{ github.ref_name }}
76+
shell: pwsh
77+
run: |
78+
# Get the version suffix from the branch name and auto-incrementing build number. For example: 'main' and '123' => 'main-00123'
79+
$revision = "{0:D5}" -f [convert]::ToInt32(${{ github.run_number }}, 10)
80+
$branchName = '${{ env.BRANCH_NAME }}'
81+
$safeName = $branchName.Replace('/', '-').Replace('_', '-').Replace('$', '-').Replace(';', '-')
82+
$versionSuffix = "$safeName-$revision"
83+
84+
Write-Output "Using version suffix: $versionSuffix"
85+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
86+
87+
- name: Calculate package version (for pr)
88+
if: ${{ github.event_name == 'pull_request' }}
89+
shell: pwsh
90+
run: |
91+
# Get the version suffix from the PR number and auto-incrementing build number. For example: '18' and '123' => 'pr18-00123'
92+
$revision = "{0:D5}" -f ${{ github.run_number }}
93+
$versionSuffix = "pr${{ github.event.number }}-$revision"
94+
95+
Write-Output "Using version suffix: $versionSuffix"
96+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
97+
98+
- name: Build solution
99+
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
100+
101+
- name: Collect packages
102+
run: dotnet pack ${{ env.SOLUTION_FILE }} --no-build --configuration Release --output ${{ github.workspace }}/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
103+
104+
- name: Upload packages
105+
uses: actions/upload-artifact@v4
106+
with:
107+
if-no-files-found: error
108+
name: unsigned-packages
109+
path: ${{ github.workspace }}/packages/**/*.nupkg

0 commit comments

Comments
 (0)