Skip to content

Commit

Permalink
Update to 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
petehouston committed Apr 21, 2021
1 parent a49df9a commit 892c80c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions README.md
Expand Up @@ -8,33 +8,61 @@ Get pure Git branch name without `***/ref/` prefix.

**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/github-actions-query-branch-name@v1.1
uses: petehouston/github-actions-query-branch-name@v1.2
```

Export to custom environment variable, ex. `MY_BRANCH`
```yaml
uses: petehouston/github-actions-query-branch-name@v1.1
uses: petehouston/github-actions-query-branch-name@v1.2
with:
name: MY_BRANCH
```

Get branch name from output.
```yaml
- name: Query Git branch name
uses: petehouston/github-actions-query-branch-name@v1.1
uses: petehouston/github-actions-query-branch-name@v1.2
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/github-actions-query-branch-name@v1.2
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 }}"
```
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "github-actions-query-branch-name",
"version": "1.1.0",
"version": "1.2.0",
"description": "Get pure Git branch name without ref/ prefix",
"main": "dist/index.js",
"scripts": {
Expand Down

0 comments on commit 892c80c

Please sign in to comment.