Skip to content

Commit

Permalink
feat(init): Add action.yml metadata & readme
Browse files Browse the repository at this point in the history
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
jskrzypek committed Jan 27, 2022
0 parents commit f9715a8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Readme.md
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.
34 changes: 34 additions & 0 deletions action.yml
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

0 comments on commit f9715a8

Please sign in to comment.