-
Notifications
You must be signed in to change notification settings - Fork 2
124 lines (108 loc) · 4.04 KB
/
Copy pathgithub-release.yml
File metadata and controls
124 lines (108 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Create GitHub Release (manual)
on:
workflow_dispatch:
inputs:
confirm:
description: "Confirm create release"
required: true
type: boolean
permissions: {}
jobs:
guard-ci-success:
runs-on: windows-2022
permissions:
contents: read
statuses: read
actions: read
steps:
- name: Ensure CI for this commit succeeded
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ownerRepo = $env:GITHUB_REPOSITORY
$sha = $env:GITHUB_SHA
$authValue = "token $env:GITHUB_TOKEN"
$headers = @{
Authorization = $authValue #gitleaks:allow
Accept = 'application/vnd.github+json'
'X-GitHub-Api-Version' = '2022-11-28'
}
$workflow = 'ci.yml'
$branch = $env:GITHUB_REF_NAME
$url = "https://api.github.com/repos/$ownerRepo/actions/workflows/$workflow/runs?branch=$branch&per_page=20"
try {
$resp = Invoke-RestMethod -Method Get -Uri $url -Headers $headers -ErrorAction Stop
} catch {
Write-Error "Blocking release: failed to query CI workflow runs ($($_.Exception.Message))"
exit 1
}
if (-not $resp.workflow_runs) {
Write-Error "Blocking release: no CI runs found on branch '$branch'"
exit 1
}
$matching = $resp.workflow_runs | Where-Object { $_.head_sha -eq $sha -and $_.status -eq 'completed' }
if (-not $matching) {
Write-Error "Blocking release: no completed CI run found for commit $sha"
exit 1
}
$success = $matching | Where-Object { $_.conclusion -eq 'success' } | Select-Object -First 1
if (-not $success) {
$concl = ($matching | Select-Object -First 1).conclusion
Write-Error "Blocking release: CI conclusion for $sha is '$concl'"
exit 1
}
build-and-release:
needs: guard-ci-success
if: ${{ github.event.inputs.confirm == 'true' && startsWith(github.ref_name, 'release/') }}
runs-on: windows-2022
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Check release tag does not already exist
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ownerRepo = $env:GITHUB_REPOSITORY
$versionJson = Get-Content -Raw -Path version.json | ConvertFrom-Json
$tag = "v$($versionJson.major).$($versionJson.minor).$($versionJson.patch)"
$authValue = "token $env:GITHUB_TOKEN"
$headers = @{
Authorization = $authValue #gitleaks:allow
Accept = 'application/vnd.github+json'
'X-GitHub-Api-Version' = '2022-11-28'
}
$url = "https://api.github.com/repos/$ownerRepo/releases/tags/$tag"
try {
$release = Invoke-RestMethod -Method Get -Uri $url -Headers $headers -ErrorAction Stop
Write-Error "Release tag '$tag' already exists (id: $($release.id)). Bump version.json before creating a new release."
exit 1
} catch {
$statusCode = $null
if ($_.Exception.Response) {
$statusCode = [int]$_.Exception.Response.StatusCode
}
if ($statusCode -eq 404) {
Write-Output "Release tag '$tag' not found — proceeding."
} else {
Write-Error "Failed to check for existing release tag '$tag': $($_.Exception.Message)"
exit 1
}
}
- name: Build package
run: python run.py build
- name: Create GitHub Release
run: python run.py release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}