Skip to content

Commit 6321f0f

Browse files
committed
fix: centralize release version resolution
1 parent 754b938 commit 6321f0f

1 file changed

Lines changed: 23 additions & 25 deletions

File tree

.github/workflows/release.yml

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ permissions:
1111
id-token: write
1212

1313
jobs:
14+
prepare:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
version: ${{ steps.version.outputs.value }}
18+
19+
steps:
20+
- name: Resolve version from tag
21+
id: version
22+
shell: bash
23+
run: echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
24+
1425
build-binaries:
26+
needs: prepare
1527
runs-on: ${{ matrix.os }}
1628
strategy:
1729
matrix:
@@ -36,11 +48,6 @@ jobs:
3648
- uses: actions/checkout@v4
3749
with:
3850
fetch-depth: 0
39-
40-
- name: Get version from tag
41-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
42-
shell: bash
43-
4451
- name: Setup .NET
4552
uses: actions/setup-dotnet@v4
4653
with:
@@ -50,13 +57,13 @@ jobs:
5057
run: dotnet restore
5158

5259
- name: Build with version from tag
53-
run: dotnet build src/hypr.csproj --configuration Release --no-restore -p:Version=${{ env.VERSION }}
60+
run: dotnet build src/hypr.csproj --configuration Release --no-restore -p:Version=${{ needs.prepare.outputs.version }}
5461

5562
- name: Test
5663
run: dotnet test --no-restore --verbosity normal
5764

5865
- name: Publish binary with version
59-
run: dotnet publish src/hypr.csproj --configuration Release --runtime ${{ matrix.rid }} --self-contained true --output ./publish/${{ matrix.name }} -p:Version=${{ env.VERSION }}
66+
run: dotnet publish src/hypr.csproj --configuration Release --runtime ${{ matrix.rid }} --self-contained true --output ./publish/${{ matrix.name }} -p:Version=${{ needs.prepare.outputs.version }}
6067

6168
- name: Upload artifacts
6269
uses: actions/upload-artifact@v4
@@ -65,17 +72,13 @@ jobs:
6572
path: ./publish/${{ matrix.name }}/
6673

6774
build-dotnet-tool:
75+
needs: prepare
6876
runs-on: ubuntu-latest
6977

7078
steps:
7179
- uses: actions/checkout@v4
7280
with:
7381
fetch-depth: 0
74-
75-
- name: Get version from tag
76-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
77-
shell: bash
78-
7982
- name: Setup .NET
8083
uses: actions/setup-dotnet@v4
8184
with:
@@ -85,11 +88,11 @@ jobs:
8588
run: dotnet restore
8689

8790
- name: Pack dotnet tool with version from tag
88-
run: dotnet pack src/hypr.csproj --configuration Release --output ./nupkg -p:Version=${{ env.VERSION }}
91+
run: dotnet pack src/hypr.csproj --configuration Release --output ./nupkg -p:Version=${{ needs.prepare.outputs.version }}
8992

9093
- name: Smoke test packaged dotnet tool
9194
run: |
92-
dotnet tool install --tool-path ./tool-smoke --add-source ./nupkg hypr --version ${{ env.VERSION }}
95+
dotnet tool install --tool-path ./tool-smoke --add-source ./nupkg hypr --version ${{ needs.prepare.outputs.version }}
9396
./tool-smoke/hypr --help
9497
9598
- name: Upload dotnet tool package
@@ -99,18 +102,13 @@ jobs:
99102
path: ./nupkg/
100103

101104
create-release:
102-
needs: [build-binaries, build-dotnet-tool]
105+
needs: [prepare, build-binaries, build-dotnet-tool]
103106
runs-on: ubuntu-latest
104107

105108
steps:
106109
- uses: actions/checkout@v4
107110
with:
108111
fetch-depth: 0
109-
110-
- name: Get version from tag
111-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
112-
shell: bash
113-
114112
- name: Install zip
115113
run: sudo apt-get update && sudo apt-get install -y zip
116114

@@ -137,8 +135,8 @@ jobs:
137135
- name: Create GitHub Release
138136
uses: softprops/action-gh-release@v2
139137
with:
140-
tag_name: v${{ env.VERSION }}
141-
name: Release v${{ env.VERSION }}
138+
tag_name: v${{ needs.prepare.outputs.version }}
139+
name: Release v${{ needs.prepare.outputs.version }}
142140
files: |
143141
artifacts/*.tar.gz
144142
artifacts/*.zip
@@ -148,7 +146,7 @@ jobs:
148146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149147

150148
publish-nuget:
151-
needs: build-dotnet-tool
149+
needs: [prepare, build-dotnet-tool]
152150
runs-on: ubuntu-latest
153151

154152
steps:
@@ -175,9 +173,9 @@ jobs:
175173
shell: bash
176174
run: |
177175
shopt -s nullglob
178-
for package in ./nupkg/hypr.*.${{ env.VERSION }}.nupkg; do
176+
for package in ./nupkg/hypr.*.${{ needs.prepare.outputs.version }}.nupkg; do
179177
dotnet nuget push "$package" --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
180178
done
181179
182180
- name: Publish pointer package to NuGet
183-
run: dotnet nuget push ./nupkg/hypr.${{ env.VERSION }}.nupkg --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
181+
run: dotnet nuget push ./nupkg/hypr.${{ needs.prepare.outputs.version }}.nupkg --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate

0 commit comments

Comments
 (0)