Skip to content

Commit 89afbfc

Browse files
committed
Add release workflow
1 parent 4fa9e72 commit 89afbfc

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: 🎁 Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
ship_run_id:
9+
description: ID of the GitHub workflow run to ship
10+
required: true
11+
12+
run-name: ${{ github.ref_name }}
13+
14+
permissions:
15+
actions: read
16+
contents: write
17+
18+
jobs:
19+
release:
20+
runs-on: ubuntu-22.04
21+
steps:
22+
- name: ⚙️ Initialization
23+
shell: pwsh
24+
run: |
25+
if ('${{ secrets.NUGET_API_KEY }}') {
26+
echo "NUGET_API_KEY_DEFINED=true" >> $GITHUB_ENV
27+
}
28+
29+
- name: 🔎 Search for build of ${{ github.ref }}
30+
shell: pwsh
31+
id: findrunid
32+
env:
33+
GH_TOKEN: ${{ github.token }}
34+
run: |
35+
if ('${{ inputs.ship_run_id }}') {
36+
$runid = '${{ inputs.ship_run_id }}'
37+
} else {
38+
$restApiRoot = '/repos/${{ github.repository }}'
39+
40+
# Resolve the tag reference to a commit sha
41+
$resolvedRef = gh api `
42+
-H "Accept: application/vnd.github+json" `
43+
-H "X-GitHub-Api-Version: 2022-11-28" `
44+
$restApiRoot/git/ref/tags/${{ github.ref_name }} `
45+
| ConvertFrom-Json
46+
$commitSha = $resolvedRef.object.sha
47+
48+
Write-Host "Resolved ${{ github.ref_name }} to $commitSha"
49+
50+
$releases = gh run list -R ${{ github.repository }} -c $commitSha -w .github/workflows/build.yml -s success --json databaseId,startedAt `
51+
| ConvertFrom-Json | Sort-Object startedAt -Descending
52+
53+
if ($releases.length -eq 0) {
54+
Write-Error "No successful builds found for ${{ github.ref }}."
55+
} elseif ($releases.length -gt 1) {
56+
Write-Warning "More than one successful run found for ${{ github.ref }}. Artifacts from the most recent successful run will ship."
57+
}
58+
59+
$runid = $releases[0].databaseId
60+
}
61+
62+
Write-Host "Using artifacts from run-id: $runid"
63+
64+
Echo "runid=$runid" >> $env:GITHUB_OUTPUT
65+
66+
- name: 🔻 Download deployables artifacts
67+
uses: actions/download-artifact@v4
68+
with:
69+
name: deployables-Linux
70+
path: ${{ runner.temp }}/deployables
71+
run-id: ${{ steps.findrunid.outputs.runid }}
72+
github-token: ${{ github.token }}
73+
74+
- name: 💽 Upload artifacts to release
75+
shell: pwsh
76+
if: ${{ github.event.release.assets_url }} != ''
77+
env:
78+
GH_TOKEN: ${{ github.token }}
79+
run: |
80+
Get-ChildItem '${{ runner.temp }}/deployables' |% {
81+
Write-Host "Uploading $($_.Name) to release..."
82+
gh release -R ${{ github.repository }} upload "${{ github.ref_name }}" $_.FullName
83+
}
84+
85+
- name: 🚀 Push NuGet packages
86+
run: dotnet nuget push ${{ runner.temp }}/deployables/*.nupkg --source https://api.nuget.org/v3/index.json -k '${{ secrets.NUGET_API_KEY }}'
87+
if: ${{ env.NUGET_API_KEY_DEFINED == 'true' }}

0 commit comments

Comments
 (0)