mirror of
https://github.com/tj-actions/branch-names.git
synced 2024-12-27 14:27:59 +08:00
Merge pull request #55 from tj-actions/feature/add-support-for-is_tag
This commit is contained in:
commit
d25195875f
42
.github/workflows/test.yml
vendored
42
.github/workflows/test.yml
vendored
@ -28,49 +28,53 @@ jobs:
|
|||||||
echo "Ref: ${{ steps.branch-name.outputs.ref_branch }}"
|
echo "Ref: ${{ steps.branch-name.outputs.ref_branch }}"
|
||||||
echo "Is Default: ${{ steps.branch-name.outputs.is_default }}"
|
echo "Is Default: ${{ steps.branch-name.outputs.is_default }}"
|
||||||
echo "Current tag: ${{ steps.branch-name.outputs.tag }}"
|
echo "Current tag: ${{ steps.branch-name.outputs.tag }}"
|
||||||
- name: Check is_default for pull request
|
- name: Test is_default output for pull request
|
||||||
if: github.event_name == 'pull_request' && !startsWith(github.ref, 'refs/tags/') && steps.branch-name.outputs.is_default != 'false'
|
if: github.event_name == 'pull_request' && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'false'
|
||||||
run: |
|
run: |
|
||||||
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Check is_default for non pull request
|
- name: Test is_default output for non pull request
|
||||||
if: github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/tags/') && steps.branch-name.outputs.is_default != 'true'
|
if: github.event_name != 'pull_request' && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'true'
|
||||||
run: |
|
run: |
|
||||||
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Test base ref output
|
- name: Test base_ref_branch output
|
||||||
if: github.event_name == 'pull_request' && !startsWith(github.ref, 'refs/tags/') && !steps.branch-name.outputs.base_ref_branch
|
if: github.event_name == 'pull_request' && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.base_ref_branch
|
||||||
run: |
|
run: |
|
||||||
echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Test head ref output
|
- name: Test head_ref output
|
||||||
if: github.event_name == 'pull_request' && !startsWith(github.ref, 'refs/tags/') && !steps.branch-name.outputs.head_ref_branch
|
if: github.event_name == 'pull_request' && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.head_ref_branch
|
||||||
run: |
|
run: |
|
||||||
echo "Head ref unset: ${{ steps.branch-name.outputs.head_ref_branch }}"
|
echo "Head ref unset: ${{ steps.branch-name.outputs.head_ref_branch }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Test ref output
|
- name: Test ref_branch output
|
||||||
if: "!steps.branch-name.outputs.ref_branch && !startsWith(github.ref, 'refs/tags/') "
|
if: "!steps.branch-name.outputs.ref_branch && steps.branch-name.outputs.is_tag == 'false'"
|
||||||
run: |
|
run: |
|
||||||
echo "Ref unset: ${{ steps.branch-name.outputs.ref_branch }}"
|
echo "Ref unset: ${{ steps.branch-name.outputs.ref_branch }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Test current branch output for pull_request event.
|
- name: Test current_branch output for pull_request event.
|
||||||
if: github.event_name == 'pull_request' && !startsWith(github.ref, 'refs/tags/') && !steps.branch-name.outputs.current_branch
|
if: github.event_name == 'pull_request' && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch
|
||||||
run: |
|
run: |
|
||||||
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Test current branch output for push event.
|
- name: Test current_branch output for push event.
|
||||||
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/') && !steps.branch-name.outputs.current_branch
|
if: github.event_name == 'push' && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch
|
||||||
run: |
|
run: |
|
||||||
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Test current branch output for tag based push event.
|
- name: Test current_branch output for tag based push event.
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !steps.branch-name.outputs.current_branch
|
if: github.event_name == 'push' && steps.branch-name.outputs.is_tag == 'true' && !steps.branch-name.outputs.current_branch
|
||||||
run: |
|
run: |
|
||||||
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
||||||
exit 1
|
exit 1
|
||||||
- name: Test current tag for push events.
|
- name: Test is_tag output for tag based push event.
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !steps.branch-name.outputs.tag
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') == 'true'
|
||||||
|
run: |
|
||||||
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
||||||
|
exit 1
|
||||||
|
- name: Test tag output for tag based push event.
|
||||||
|
if: github.event_name == 'push' && steps.branch-name.outputs.is_tag == 'true' && !steps.branch-name.outputs.tag
|
||||||
run: |
|
run: |
|
||||||
echo "Current tag unset: ${{ steps.branch-name.outputs.tag }}"
|
echo "Current tag unset: ${{ steps.branch-name.outputs.tag }}"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
27
README.md
27
README.md
@ -10,11 +10,12 @@ Get branch or tag information without the `/ref/*` prefix
|
|||||||
| Output | type | Example | Description |
|
| Output | type | Example | Description |
|
||||||
|:--------------------:|:------------:|:---------------------------:|:-----------------------------------------------------------------:|
|
|:--------------------:|:------------:|:---------------------------:|:-----------------------------------------------------------------:|
|
||||||
| is_default | `boolean` | `true` *OR* `false` | Detects wheter the action is running on a default branch |
|
| is_default | `boolean` | `true` *OR* `false` | Detects wheter the action is running on a default branch |
|
||||||
|
| is_tag | `boolean` | `true` *OR* `false` | Detects wheter the action is running on a tag branch |
|
||||||
| current_branch | `string` | `main` *OR* `feature/test` | Always returns a valid branch name for a triggered workflow run. |
|
| current_branch | `string` | `main` *OR* `feature/test` | Always returns a valid branch name for a triggered workflow run. |
|
||||||
| base_ref_branch | `string` | `main` | The target branch of a pull request |
|
| base_ref_branch | `string` | `main` | The target branch of a pull request |
|
||||||
| head_ref_branch | `string` | `feature/test` | The source branch of a pull request |
|
| head_ref_branch | `string` | `feature/test` | The source branch of a pull request |
|
||||||
| ref_branch | `string` | `1/merge` *OR* `main` | The branch that triggered the workflow run |
|
| ref_branch | `string` | `1/merge` *OR* `main` | The branch that triggered the workflow run |
|
||||||
| tag | `string` | `v0.0.1` *OR* `0.0.1` | The tag that triggered the workflow run |
|
| tag | `string` | `v0.0.1` *OR* `0.0.1` | The tag that triggered the workflow run |
|
||||||
|
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
@ -28,7 +29,6 @@ Get branch or tag information without the `/ref/*` prefix
|
|||||||
```yaml
|
```yaml
|
||||||
...
|
...
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Get branch names
|
- name: Get branch names
|
||||||
id: branch-name
|
id: branch-name
|
||||||
uses: tj-actions/branch-names@v4.2
|
uses: tj-actions/branch-names@v4.2
|
||||||
@ -39,11 +39,10 @@ Get branch or tag information without the `/ref/*` prefix
|
|||||||
```yaml
|
```yaml
|
||||||
...
|
...
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Get branch names
|
- name: Get branch names
|
||||||
id: branch-name
|
id: branch-name
|
||||||
uses: tj-actions/branch-names@v4.2
|
uses: tj-actions/branch-names@v4.2
|
||||||
|
|
||||||
- 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: |
|
||||||
@ -55,6 +54,24 @@ Get branch or tag information without the `/ref/*` prefix
|
|||||||
run: |
|
run: |
|
||||||
echo "Running on pr: ${{ steps.branch-name.outputs.current_branch }}"
|
echo "Running on pr: ${{ steps.branch-name.outputs.current_branch }}"
|
||||||
# Outputs: "Running on pr: feature/test".
|
# 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'
|
||||||
|
run: |
|
||||||
|
echo "Running on branch: ${{ steps.branch-name.outputs.current_branch }}"
|
||||||
|
# Outputs: "Running on branch: main".
|
||||||
|
|
||||||
|
- 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'
|
||||||
|
run: |
|
||||||
|
echo "Running on branch: ${{ steps.branch-name.outputs.current_branch }}"
|
||||||
|
# Outputs: "Running on branch: feature/test".
|
||||||
|
|
||||||
- name: Current branch name
|
- name: Current branch name
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
@ -114,6 +131,8 @@ on:
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
* Free software: [MIT license](LICENSE)
|
* Free software: [MIT license](LICENSE)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@ outputs:
|
|||||||
is_default:
|
is_default:
|
||||||
value: ${{ steps.default.outputs.is_default }}
|
value: ${{ steps.default.outputs.is_default }}
|
||||||
description: 'Returns "true" if the current branch is the default else "false".'
|
description: 'Returns "true" if the current branch is the default else "false".'
|
||||||
|
is_tag:
|
||||||
|
value: ${{ steps.tag.outputs.is_tag }}
|
||||||
|
description: 'Returns "true" if the current branch is a tag else "false".'
|
||||||
current_branch:
|
current_branch:
|
||||||
value: ${{ steps.current_branch.outputs.current_branch }}
|
value: ${{ steps.current_branch.outputs.current_branch }}
|
||||||
description: 'Returns the value of the current branch which is consistent regardless of event_type: i.e (push, pull_requests).'
|
description: 'Returns the value of the current branch which is consistent regardless of event_type: i.e (push, pull_requests).'
|
||||||
@ -72,6 +75,9 @@ runs:
|
|||||||
REF=${{ github.ref }}
|
REF=${{ github.ref }}
|
||||||
TAG=${REF/refs\/tags\/${{ inputs.strip_tag_prefix }}/}
|
TAG=${REF/refs\/tags\/${{ inputs.strip_tag_prefix }}/}
|
||||||
echo "::set-output name=tag::$TAG"
|
echo "::set-output name=tag::$TAG"
|
||||||
|
echo "::set-output name=is_tag::true"
|
||||||
|
else
|
||||||
|
echo "::set-output name=is_tag::false"
|
||||||
fi
|
fi
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user