-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(init): Add action.yml metadata & readme
This should be the only commit, unless I messed something up, or the github context changes in the future. Adds both the action.yml file and the readme.
- Loading branch information
0 parents
commit f9715a8
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,24 @@ | ||
# Set Git Branch | ||
|
||
This is a dead-simple composite action that uses the github context to provide | ||
an environment variable (`$GIT_BRANCH`) and an output (`branch-name`) with the | ||
branch name that workflow creators are most likely to care about. | ||
|
||
## Pull Request Events | ||
|
||
For Pull Request events (`pull_request` & `pull_request_target`) the `github` | ||
context provides the `github.head_ref` context variable that contains the name | ||
of the source branch for the PR. | ||
|
||
## Other `branch`-type Events | ||
|
||
For other events triggered by branches, the [`github` | ||
context](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) | ||
provides the `github.ref_name` variable with the name of the branch or tag that | ||
triggered the event, and this is what is used to set the env var & output | ||
|
||
## Tag Events | ||
|
||
Whenever `github.ref_type` is set to `tag`, the current event was triggered by a | ||
tag, and the `github` context does not provide any branch-relevant information, | ||
so this action provides an empty output and environment variable. |
This file contains 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,34 @@ | ||
name: 'Set Git Branch' | ||
author: Joshua Estrin Skrzypek <https://github.com/jskrzypek> | ||
description: | | ||
Sets the git branch name as a consistent env var & output. If the event is | ||
triggered by a tag, no value will be set. | ||
branding: | ||
icon: git-branch | ||
color: orange | ||
outputs: | ||
branch-name: | ||
description: "The branch name" | ||
value: ${{ env.GIT_BRANCH }} | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Set Git branch name on PR | ||
id: branch-name-from-pr | ||
if: |- | ||
github.event_name == 'pull_request' | ||
|| github.event_name == 'pull_request_target' | ||
run: | | ||
echo "GIT_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV | ||
echo "::set-output name=branch-name::${{ github.head_ref }}" | ||
shell: bash | ||
- name: Set Env Vars on non-PR branch events | ||
id: branch-name-from-non-pr | ||
if: |- | ||
github.event_name != 'pull_request' | ||
&& github.event_name != 'pull_request_target' | ||
&& github.ref_type == 'branch' | ||
run: | | ||
echo "GIT_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV | ||
echo "::set-output name=branch-name::${{ github.head_ref }}" | ||
shell: bash |