Skip to content

Commit

Permalink
Run github action against tag during release
Browse files Browse the repository at this point in the history
Previously this would pass the empty string which would default to main.
  • Loading branch information
glasser committed Sep 8, 2024
1 parent 895caca commit 0c51d07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ workflows:
command: [github-actions]
options:
- |
--workflow-name 'tests-mac-x86.yml' --branch "<< pipeline.git.branch >>" --commit-id "<< pipeline.git.revision >>"
--workflow-name 'tests-mac-x86.yml' --git-ref "<< pipeline.git.branch >>" --commit-id "<< pipeline.git.revision >>"
- xtask:
name: Run supergraph-demo tests (<< matrix.rust_channel >> rust on << matrix.platform >>)
Expand Down Expand Up @@ -219,7 +219,7 @@ workflows:
command: [ github-actions ]
options:
- |
--workflow-name 'tests-mac-x86.yml' --branch "<< pipeline.git.branch >>" --commit-id "<< pipeline.git.revision >>"
--workflow-name 'tests-mac-x86.yml' --git-ref "<< pipeline.git.tag >>" --commit-id "<< pipeline.git.revision >>"
<<: *run_release

- install_js:
Expand Down
23 changes: 12 additions & 11 deletions xtask/src/commands/github_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub struct GithubActions {
#[arg(long = "repository", default_value = "rover")]
pub(crate) repository: String,

/// The repository branch to use
#[arg(long = "branch", default_value = "main")]
pub(crate) branch: String,
/// The repository branch or tag to use
#[arg(long = "git-ref", default_value = "main")]
pub(crate) git_ref: String,

/// The commit ID for this run
#[arg(long = "commit-id")]
Expand All @@ -38,12 +38,12 @@ pub struct GithubActions {

impl GithubActions {
pub async fn run(&self) -> Result<()> {
let branch = if self.branch.is_empty() {
let git_ref = if self.git_ref.is_empty() {
String::from("main")
} else {
self.branch.clone()
self.git_ref.clone()
};
crate::info!("Running against branch {}", branch);
crate::info!("Running against git ref {}", git_ref);
let token = std::env::var("GITHUB_ACTIONS_TOKEN")
.map_err(|_err| anyhow!("$GITHUB_ACTIONS_TOKEN is not set or is not valid UTF-8."))?;
let octocrab = OctocrabBuilder::new()
Expand All @@ -55,11 +55,11 @@ impl GithubActions {

// Trigger GitHub workflow by sending a workflow dispatch event
// See <https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event>
let mut json_payload = json!({"ref": branch});
let mut json_payload = json!({"ref": git_ref});
if let Some(inputs) = &self.inputs {
let json_inputs: serde_json::Value = serde_json::from_str(inputs)?;
json_payload = json!({
"ref": branch,
"ref": git_ref,
"inputs": json_inputs,
});
}
Expand All @@ -84,7 +84,7 @@ impl GithubActions {
// Find the corresponding workflow run ID
let fut = async {
loop {
match self.get_run_id(&octocrab, &user, &branch).await {
match self.get_run_id(&octocrab, &user, &git_ref).await {
Ok(run_id) => return run_id,
Err(_err) => {
tokio::time::sleep(WORKFLOW_WAIT_TIME).await;
Expand All @@ -104,11 +104,12 @@ impl GithubActions {
Ok(())
}

async fn get_run_id(&self, octocrab: &Octocrab, login: &str, branch: &str) -> Result<RunId> {
async fn get_run_id(&self, octocrab: &Octocrab, login: &str, git_ref: &str) -> Result<RunId> {
Ok(octocrab
.workflows(&self.organization, &self.repository)
.list_runs(&self.workflow_name)
.branch(branch)
// Despite the name, this does appear to work with tags.
.branch(git_ref)
.event("workflow_dispatch")
.actor(login)
.send()
Expand Down

0 comments on commit 0c51d07

Please sign in to comment.