Skip to content
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

Add SHA option #92

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Github Release On Push Action

> [!NOTE]
> We don't use this to create releases any longer; releases are created directly in the
> reusable CI/CD workflow.

> Stop using files for versioning. Use git tags instead!

Github Action to create a Github Release on pushes to master.
Expand Down Expand Up @@ -245,6 +249,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)
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion src/release_on_push_action/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
[args]
{:token (getenv-or-throw "GITHUB_TOKEN")
:repo (getenv-or-throw "GITHUB_REPOSITORY")
: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"))
Expand Down