Skip to content

Commit 3738574

Browse files
committed
Decouple Moldflow API public PyPI publish from GitHub Release (#85)
* [IM-14373] Decouple GitHub Release from PyPI publish Split publish.yml into github-release.yml and pypi-publish.yml. Add PyPI ordering guard that blocks publishing newer versions before older ones are on PyPI. Update RELEASE.md to document two-step release process. * fix: avoid gitleaks false positive on Authorization header * fix: suppress checkov CKV2_GHA_1 and gitleaks false positives
1 parent 3930358 commit 3738574

4 files changed

Lines changed: 506 additions & 230 deletions

File tree

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

.github/workflows/publish.yml

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)