mirror of
https://github.com/tj-actions/branch-names.git
synced 2024-11-23 19:13:51 +08:00
parent
740e6590b2
commit
12119e483b
95
README.md
95
README.md
@ -58,73 +58,93 @@ on:
|
||||
|:-----------------:|:---------:|:--------:|:-----------------------:|
|
||||
| strip_tag_prefix | `string` | `''` | The tag prefix to strip <br> *i.e `v0.0.1` -> `v` -> `0.0.1`* |
|
||||
|
||||
## Examples
|
||||
|
||||
## Events
|
||||
|
||||
- `push*`
|
||||
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
...
|
||||
steps:
|
||||
- name: Get branch names
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v4.5
|
||||
|
||||
- name: Current branch name
|
||||
run: |
|
||||
echo "${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "main" the branch that triggered the push event.
|
||||
|
||||
- name: Running on the default branch.
|
||||
if: steps.branch-name.outputs.is_default == 'true'
|
||||
run: |
|
||||
echo "Running on default: ${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "Running on default: main".
|
||||
|
||||
- name: Running on a pull request branch.
|
||||
if: steps.branch-name.outputs.is_default == 'false'
|
||||
run: |
|
||||
echo "Running on pr: ${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "Running on pr: feature/test".
|
||||
|
||||
- name: Running on a tag branch.
|
||||
if: steps.branch-name.outputs.is_tag == 'true'
|
||||
run: |
|
||||
echo "Running on tag: ${{ steps.branch-name.outputs.tag }}"
|
||||
# Outputs: "Running on tag: v0.0.1".
|
||||
|
||||
- name: Running on a non tag based branch and the default branch.
|
||||
- name: Running on the default branch (i.e non tag based branch).
|
||||
if: steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default == 'true'
|
||||
run: |
|
||||
echo "Running on branch: ${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "Running on branch: main".
|
||||
|
||||
```
|
||||
|
||||
- `pull_request*`
|
||||
|
||||
```yaml
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
...
|
||||
steps:
|
||||
- name: Get branch names
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v4.5
|
||||
|
||||
- name: Current branch name
|
||||
run: |
|
||||
echo "${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "feature/test" current PR branch.
|
||||
|
||||
- name: Running on a non tag based branch and a PR branch.
|
||||
if: steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default == 'false'
|
||||
if: steps.branch-name.outputs.is_default == 'false'
|
||||
run: |
|
||||
echo "Running on branch: ${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "Running on branch: feature/test".
|
||||
|
||||
- name: Current branch name
|
||||
if: github.event_name == 'pull_request'
|
||||
- name: Running on a pull request (i.e non tag based branch).
|
||||
if: steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default == 'false'
|
||||
run: |
|
||||
echo "${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "feature/test" current PR branch.
|
||||
echo "Running on branch: ${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "Running on branch: feature/test".
|
||||
```
|
||||
|
||||
- name: Current branch name
|
||||
if: github.event_name == 'push'
|
||||
run: |
|
||||
echo "${{ steps.branch-name.outputs.current_branch }}"
|
||||
# Outputs: "main" the branch that triggered the push event.
|
||||
- `tag*`
|
||||
|
||||
- name: Get Ref brach name
|
||||
run: |
|
||||
echo "${{ steps.branch-name.outputs.ref_branch }}"
|
||||
# Outputs: "main" for non PR branches | "1/merge" for a PR branch
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
- name: Get Head Ref branch name
|
||||
if: github.event_name == 'pull_request'
|
||||
run: |
|
||||
echo "${{ steps.branch-name.outputs.head_ref_branch }}"
|
||||
# Outputs: "feature/test" current PR branch.
|
||||
...
|
||||
steps:
|
||||
- name: Get branch names
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v4.5.
|
||||
|
||||
- name: Get Base Ref branch name
|
||||
if: github.event_name == 'pull_request'
|
||||
- name: Running on a tag branch.
|
||||
if: steps.branch-name.outputs.is_tag == 'true'
|
||||
run: |
|
||||
echo "${{ steps.branch-name.outputs.base_ref_branch }}"
|
||||
# Outputs: "main" for main <- PR branch.
|
||||
echo "Running on: ${{ steps.branch-name.outputs.tag }}"
|
||||
# Outputs: "Running on: v0.0.1".
|
||||
|
||||
- name: Get the current tag
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
@ -133,6 +153,7 @@ on:
|
||||
# Outputs: "v0.0.1" OR "0.0.1"
|
||||
```
|
||||
|
||||
|
||||
### Possible usage with [actions/checkout@v2](https://github.com/actions/checkout):
|
||||
|
||||
```yaml
|
||||
|
Loading…
Reference in New Issue
Block a user