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