Skip to content

Commit bc517ab

Browse files
CopilotMikeMcQuaid
andcommitted
Implement workflow-based release process for immutable releases
Co-authored-by: MikeMcQuaid <[email protected]>
1 parent ba209a2 commit bc517ab

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

.github/workflows/pkg-installer.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ on:
1111
release:
1212
types:
1313
- published
14+
workflow_dispatch:
15+
inputs:
16+
tag:
17+
description: 'Git tag for the release'
18+
required: true
19+
type: string
1420
env:
1521
PKG_APPLE_DEVELOPER_TEAM_ID: ${{ secrets.PKG_APPLE_DEVELOPER_TEAM_ID }}
1622
HOMEBREW_NO_ANALYTICS_THIS_RUN: 1
@@ -85,6 +91,7 @@ jobs:
8591
path: brew
8692
fetch-depth: 0
8793
persist-credentials: false
94+
ref: ${{ inputs.tag || github.ref }}
8895

8996
- name: Get Homebrew version from Git
9097
id: homebrew-version
@@ -230,13 +237,17 @@ jobs:
230237
--wait
231238

232239
- name: Upload installer to GitHub release
233-
if: github.event_name == 'release'
240+
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
234241
env:
235242
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
236243
INSTALLER_PATH: ${{ needs.build.outputs.installer_path }}
237244
run: |
238245
VERSION="${INSTALLER_PATH#Homebrew-}"
239246
VERSION="${VERSION%.pkg}"
247+
# For workflow_dispatch, create a draft release if it doesn't exist yet
248+
if ! gh release view --repo Homebrew/brew "${VERSION}" >/dev/null 2>&1; then
249+
gh release create --repo Homebrew/brew "${VERSION}" --draft --title "${VERSION}" --notes ""
250+
fi
240251
gh release upload --repo Homebrew/brew "${VERSION}" "${INSTALLER_PATH}"
241252
242253
issue:

Library/Homebrew/dev-cmd/release.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ def run
7777
puts blog_post_notes
7878
end
7979

80+
ohai "Creating tag #{new_version}"
81+
safe_system "git", "-C", HOMEBREW_REPOSITORY, "tag", "-a", new_version, "-m", "Release #{new_version}"
82+
safe_system "git", "-C", HOMEBREW_REPOSITORY, "push", "origin", new_version
83+
84+
# Get the commit SHA for the tag
85+
tag_sha = Utils.safe_popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", new_version).strip
86+
8087
ohai "Creating draft release for version #{new_version}"
8188

8289
release_notes = if args.major? || args.minor?
@@ -93,6 +100,60 @@ def run
93100
odie "Unable to create release: #{e.message}!"
94101
end
95102

103+
ohai "Triggering pkg-installer workflow for #{new_version}"
104+
begin
105+
GitHub.workflow_dispatch_event("Homebrew", "brew", "pkg-installer.yml", new_version, tag: new_version)
106+
rescue *GitHub::API::ERRORS => e
107+
opoo "Unable to trigger workflow: #{e.message}"
108+
opoo "You may need to manually trigger the pkg-installer workflow."
109+
end
110+
111+
ohai "Waiting for pkg-installer workflow to complete..."
112+
opoo "This may take several minutes. You can monitor progress at:"
113+
puts "https://github.com/Homebrew/brew/actions/workflows/pkg-installer.yml"
114+
115+
# Poll for workflow completion
116+
max_attempts = 60 # 30 minutes (30 seconds * 60)
117+
attempt = 0
118+
workflow_completed = false
119+
120+
while attempt < max_attempts
121+
sleep 30
122+
attempt += 1
123+
124+
# Check workflow runs for the commit SHA
125+
begin
126+
runs_url = "#{GitHub::API_URL}/repos/Homebrew/brew/actions/workflows/pkg-installer.yml/runs"
127+
response = GitHub::API.open_rest("#{runs_url}?head_sha=#{tag_sha}&per_page=1")
128+
129+
if response["workflow_runs"]&.any?
130+
run = response["workflow_runs"].first
131+
status = run["status"]
132+
conclusion = run["conclusion"]
133+
134+
if status == "completed"
135+
if conclusion == "success"
136+
ohai "Workflow completed successfully!"
137+
workflow_completed = true
138+
else
139+
opoo "Workflow completed with status: #{conclusion}"
140+
opoo "Check the workflow run at: #{run["html_url"]}"
141+
end
142+
break
143+
elsif (attempt % 4).zero?
144+
print "."
145+
end
146+
end
147+
rescue *GitHub::API::ERRORS => e
148+
opoo "Error checking workflow status: #{e.message}" if attempt == 1
149+
end
150+
end
151+
152+
unless workflow_completed
153+
opoo "Workflow did not complete in time or failed."
154+
opoo "Please check the workflow status before publishing the release."
155+
end
156+
96157
puts release["html_url"]
97158
exec_browser release["html_url"]
98159
end

0 commit comments

Comments
 (0)