Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petehouston/github-actions-query-branch-name
Get pure Git branch name
https://github.com/petehouston/github-actions-query-branch-name
github-actions hacktoberfest
Last synced: 2 days ago
JSON representation
Get pure Git branch name
- Host: GitHub
- URL: https://github.com/petehouston/github-actions-query-branch-name
- Owner: petehouston
- Created: 2021-04-21T19:10:21.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-20T16:25:45.000Z (about 1 year ago)
- Last Synced: 2024-09-20T15:26:18.789Z (6 days ago)
- Topics: github-actions, hacktoberfest
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Github Actions: Query Git branch name
Get pure Git branch name without `***/ref/` prefix.
## Inputs
### `name`
**Required** The environment variable name to export, ex. `CURRENT_BRANCH`, `GIT_BRANCH`. Default `"GIT_BRANCH_NAME"`.
On `pull_request` event, two additional environment variables are exported for `HEAD` and `BASE`. The env names are suffixed with `_HEAD` and `_BASE`. By default, they are `GIT_BRANCH_NAME_HEAD` and `GIT_BRANCH_NAME_BASE`.
## Outputs
### `git_branch_name`
The current Git branch name.
On `pull_request` event, it is the same as `git_branch_name_head`.
### `git_branch_name_head`
The current Git branch name at `HEAD`. Only available on `pull_request` event.
### `git_branch_name_base`
The current Git branch name at `BASE`. Only available on `pull_request` event.
## Example usage
Export to default environment variable `GIT_BRANCH_NAME`.
```yaml
uses: petehouston/[email protected]
```Export to custom environment variable, ex. `MY_BRANCH`
```yaml
uses: petehouston/[email protected]
with:
name: MY_BRANCH
```Get branch name from output.
```yaml
- name: Query Git branch name
uses: petehouston/[email protected]
id: queryBranch
- name: Get Git branch name
run: |-
echo "GIT_BRANCH_NAME = $GIT_BRANCH_NAME"
echo "Branch name: ${{ steps.queryBranch.outputs.git_branch_name }}"
```Get branch name from `pull_request`.
```yaml
- name: Query Git branch name
uses: petehouston/[email protected]
id: queryBranch
- name: Get Git branch name only on pull request
if: github.event_name == 'pull_request'
run: |-
echo "GIT_BRANCH_NAME = $GIT_BRANCH_NAME"
echo "GIT_BRANCH_NAME_HEAD = $GIT_BRANCH_NAME_BEAD"
echo "GIT_BRANCH_NAME_BASE = $GIT_BRANCH_NAME_BASE"
echo "Branch name: ${{ steps.queryBranch.outputs.git_branch_name }}"
echo "Branch name: ${{ steps.queryBranch.outputs.git_branch_name_head }}"
echo "Branch name: ${{ steps.queryBranch.outputs.git_branch_name_base }}"
```