-
Notifications
You must be signed in to change notification settings - Fork 1k
Publish GitHub release after release jobs #5468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clockwork-labs-bot
wants to merge
12
commits into
master
Choose a base branch
from
bot/publish-github-release-after-steps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
eb532e5
Publish GitHub release after release jobs
clockwork-labs-bot 455e2c7
Merge branch 'master' into bot/publish-github-release-after-steps
bfops 18bf4de
Move GitHub release publish into release tool
clockwork-labs-bot a4433a7
[bot/publish-github-release-after-steps]: update
bfops 8b63dda
[bot/publish-github-release-after-steps]: consistency
bfops 3cfe10b
Remove GitHub release repo option
clockwork-labs-bot 6205542
Simplify GitHub release target repo handling
clockwork-labs-bot b26a966
Use duct for GitHub release commands
clockwork-labs-bot 4c5401f
Inline GitHub release command helpers
clockwork-labs-bot 8da79d8
Simplify GitHub release publish flow
clockwork-labs-bot f38edba
Rename GitHub workflow run ID parser
clockwork-labs-bot d1645e2
[bot/publish-github-release-after-steps]: Merge remote-tracking branc…
bfops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| use crate::targets::ReleaseTarget; | ||
| use duct::Expression; | ||
| use serde::Deserialize; | ||
| use std::ffi::OsString; | ||
|
|
||
| const REPO: &str = "clockworklabs/SpacetimeDB"; | ||
|
|
||
| fn gh(args: impl IntoIterator<Item = impl Into<OsString>>) -> Expression { | ||
| duct::cmd("gh", args) | ||
| } | ||
|
|
||
| fn run_output(cmd: Expression, label: &str) -> Result<String, String> { | ||
|
bfops marked this conversation as resolved.
Outdated
|
||
| println!("$> {:?}", cmd); | ||
|
|
||
| let output = cmd | ||
| .unchecked() | ||
| .stdout_capture() | ||
| .stderr_capture() | ||
| .run() | ||
| .map_err(|err| format!("Failed to execute {}: {}", label, err))?; | ||
|
|
||
| if output.status.success() { | ||
| let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string(); | ||
| if !stdout.is_empty() { | ||
| return Ok(stdout); | ||
| } | ||
| return Ok(String::from_utf8_lossy(&output.stderr).trim().to_string()); | ||
| } | ||
|
|
||
| Err(format!( | ||
| "{} failed\n--- stdout ---\n{}\n--- stderr ---\n{}", | ||
| label, | ||
| String::from_utf8_lossy(&output.stdout), | ||
| String::from_utf8_lossy(&output.stderr) | ||
| )) | ||
| } | ||
|
|
||
| fn run_status(cmd: Expression, label: &str) -> Result<(), String> { | ||
|
bfops marked this conversation as resolved.
Outdated
|
||
| println!("$> {:?}", cmd); | ||
|
|
||
| let output = cmd | ||
| .unchecked() | ||
| .stdout_capture() | ||
| .stderr_capture() | ||
| .run() | ||
| .map_err(|err| format!("Failed to execute {}: {}", label, err))?; | ||
|
|
||
| if output.status.success() { | ||
| Ok(()) | ||
| } else { | ||
| Err(format!( | ||
| "{} failed with status {}\n--- stdout ---\n{}\n--- stderr ---\n{}", | ||
| label, | ||
| output.status, | ||
| String::from_utf8_lossy(&output.stdout), | ||
| String::from_utf8_lossy(&output.stderr) | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| struct Release { | ||
| is_draft: bool, | ||
| url: String, | ||
| } | ||
|
|
||
| pub struct GithubRelease { | ||
| version: String, | ||
| } | ||
|
|
||
| impl GithubRelease { | ||
| pub fn new(version: String) -> Self { | ||
| Self { version } | ||
| } | ||
|
|
||
| fn release(&self) -> Result<Release, String> { | ||
|
bfops marked this conversation as resolved.
Outdated
|
||
| let cmd = gh([ | ||
| "release", | ||
| "view", | ||
| &self.version, | ||
| "--repo", | ||
| REPO, | ||
| "--json", | ||
| "isDraft,url", | ||
| ]); | ||
|
|
||
| let output = run_output(cmd, "view GitHub release")?; | ||
| serde_json::from_str(&output).map_err(|err| format!("Failed to parse GitHub release JSON: {}", err)) | ||
| } | ||
|
|
||
| fn dispatch_attach_artifacts(&self) -> Result<String, String> { | ||
| let release_tag = format!("release_tag={}", self.version); | ||
| let cmd = gh([ | ||
| "workflow", | ||
| "run", | ||
| "attach-artifacts.yml", | ||
| "--repo", | ||
| REPO, | ||
| "--ref", | ||
| "master", | ||
| "-f", | ||
| &release_tag, | ||
| ]); | ||
|
|
||
| run_output(cmd, "dispatch attach-artifacts.yml") | ||
| } | ||
|
|
||
| fn run_id_from_output<'a>(&self, output: &'a str) -> Result<&'a str, String> { | ||
| let url = output | ||
| .split_whitespace() | ||
| .find(|word| word.starts_with("https://") && word.contains("/actions/runs/")) | ||
| .unwrap_or(output); | ||
|
|
||
| url.trim_end_matches('/') | ||
| .rsplit('/') | ||
| .next() | ||
| .filter(|segment| !segment.is_empty() && segment.chars().all(|ch| ch.is_ascii_digit())) | ||
| .ok_or_else(|| { | ||
| format!( | ||
| "Could not parse workflow run id from gh workflow run output: {}", | ||
| output | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| fn wait_for_artifacts(&self, workflow_output: &str) -> Result<(), String> { | ||
|
bfops marked this conversation as resolved.
Outdated
|
||
| let run_id = self.run_id_from_output(workflow_output)?; | ||
| let cmd = gh(["run", "watch", run_id, "--repo", REPO, "--exit-status"]); | ||
| run_status(cmd, "watch attach-artifacts.yml") | ||
| } | ||
|
|
||
| fn publish_release(&self) -> Result<(), String> { | ||
| let release_endpoint = format!("repos/{}/releases/tags/{}", REPO, self.version); | ||
| let id_cmd = gh(["api", &release_endpoint, "--jq", ".id"]); | ||
| let release_id = run_output(id_cmd, "get GitHub release id")?; | ||
|
|
||
| let publish_endpoint = format!("repos/{}/releases/{}", REPO, release_id); | ||
| let publish_cmd = gh(["api", "--method", "PATCH", &publish_endpoint, "-F", "draft=false"]); | ||
| run_status(publish_cmd, "publish GitHub release") | ||
| } | ||
| } | ||
|
|
||
| impl ReleaseTarget for GithubRelease { | ||
| fn release(&self) -> Result<(), String> { | ||
| let release = self.release()?; | ||
| if !release.is_draft { | ||
| println!("GitHub release {} is already published: {}", self.version, release.url); | ||
| return Ok(()); | ||
| } | ||
|
|
||
| println!("Found draft GitHub release {}: {}", self.version, release.url); | ||
| let run_url = self.dispatch_attach_artifacts()?; | ||
| self.wait_for_artifacts(&run_url)?; | ||
| self.publish_release()?; | ||
| println!("Published GitHub release {}.", self.version); | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn name(&self) -> &'static str { | ||
| "github-release" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.