From 90d8352b293894b9bc062746e9acc7f9f85b7f55 Mon Sep 17 00:00:00 2001 From: Benjamin Wuethrich Date: Wed, 2 Aug 2023 22:44:13 -0400 Subject: [PATCH 1/2] [PLAT-6085] Add SHA option (#1) This adds an option to overwrite the commit SHA on which the release is created; by default, that's GITHUB_SHA, but for some events such as workflow_run, GITHUB_SHA might not be what we want. PLAT-6085 --- README.md | 30 +++++++++++++++++++++++++++++ action.yml | 3 +++ src/release_on_push_action/core.clj | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd333fb..b1e6c0f 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,36 @@ jobs: max_commits: 100 ``` +### How can I select a commit SHA different from `GITHUB_SHA`? + +By default, the release is created on the commit that triggered the workflow, as identified by the `GITHUB_SHA` environment variable. Sometimes, that's not the desired behaviour; for example, the `workflow_run` event sets `GITHUB_SHA` to the last commit on the default branch, but we might want to tag the commit that was the most recent one when the workflow started. + +A different SHA can be selected using the `sha` option. If it is unset, `GITHUB_SHA` is used. + +Example usage for a release triggered by a (potentially long running) workflow run: + +```yaml +on: + workflow_run: + workflows: + - Slow CI test workflow + types: + - completed + branches: + - master + +jobs: + release-on-push: + if: github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: rymndhng/release-on-push-action@master + with: + sha: ${{ github.event.workflow_run.head_sha }} +``` + ## Development Uses [babashka](https://github.com/borkdude/babashka) diff --git a/action.yml b/action.yml index cb199ff..f4b8bbc 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,9 @@ inputs: description: "When set to 'true', will compute the next tag, but will not create a release." required: false default: "false" + sha: + description: 'The commit SHA to create the release on if different from GITHUB_SHA' + required: false outputs: tag_name: description: 'Tag of released version' diff --git a/src/release_on_push_action/core.clj b/src/release_on_push_action/core.clj index 0a8506f..fdd1fd3 100644 --- a/src/release_on_push_action/core.clj +++ b/src/release_on_push_action/core.clj @@ -33,7 +33,7 @@ [args] {:token (getenv-or-throw "GITHUB_TOKEN") :repo (getenv-or-throw "GITHUB_REPOSITORY") - :sha (getenv-or-throw "GITHUB_SHA") + :sha (or (System/getenv "INPUT_SHA") (getenv-or-throw "GITHUB_SHA")) :github/api-url (getenv-or-throw "GITHUB_API_URL") :github/output (System/getenv "GITHUB_OUTPUT") :input/max-commits (Integer/parseInt (getenv-or-throw "INPUT_MAX_COMMITS")) From 568e7604dc2691d07302576aa666aa3f3a71d967 Mon Sep 17 00:00:00 2001 From: Benjamin Wuethrich Date: Fri, 23 Feb 2024 17:16:42 -0500 Subject: [PATCH 2/2] Don't use empty SHA input (#2) When the SHA input is empty, it's considered truthy, and we try to use it; this PR checks for empty, and then falls back to "GITHUB_SHA" instead. --- src/release_on_push_action/core.clj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/release_on_push_action/core.clj b/src/release_on_push_action/core.clj index fdd1fd3..32d1fb0 100644 --- a/src/release_on_push_action/core.clj +++ b/src/release_on_push_action/core.clj @@ -33,7 +33,10 @@ [args] {:token (getenv-or-throw "GITHUB_TOKEN") :repo (getenv-or-throw "GITHUB_REPOSITORY") - :sha (or (System/getenv "INPUT_SHA") (getenv-or-throw "GITHUB_SHA")) + :sha (let [input-sha (System/getenv "INPUT_SHA")] + (if (or (empty? input-sha) (nil? input-sha)) + (getenv-or-throw "GITHUB_SHA") + input-sha)) :github/api-url (getenv-or-throw "GITHUB_API_URL") :github/output (System/getenv "GITHUB_OUTPUT") :input/max-commits (Integer/parseInt (getenv-or-throw "INPUT_MAX_COMMITS"))