2021-08-04 15:17:49 -04:00
|
|
|
name: Branch Names
|
2023-08-23 09:49:11 -07:00
|
|
|
description: Retrieve github branch or tag information without the /ref/* prefix
|
2020-12-11 08:15:40 -05:00
|
|
|
author: tj-actions
|
|
|
|
inputs:
|
2021-04-24 20:07:39 -04:00
|
|
|
strip_tag_prefix:
|
2023-03-09 02:26:25 -07:00
|
|
|
description: 'The prefix that should be stripped from the tag e.g `v` -> with a tag `v0.0.1` -> returns `0.0.1`'
|
2021-04-24 20:07:39 -04:00
|
|
|
default: ''
|
|
|
|
required: false
|
2020-12-11 08:23:56 -05:00
|
|
|
|
2020-12-11 08:15:40 -05:00
|
|
|
outputs:
|
2021-02-12 16:30:56 -05:00
|
|
|
is_default:
|
2021-02-12 16:33:03 -05:00
|
|
|
value: ${{ steps.default.outputs.is_default }}
|
2022-03-22 17:28:06 -04:00
|
|
|
description: 'Returns `"true"` if the current branch is the default else `"false"`.'
|
2021-05-27 08:24:26 -04:00
|
|
|
is_tag:
|
|
|
|
value: ${{ steps.tag.outputs.is_tag }}
|
2022-03-22 17:28:06 -04:00
|
|
|
description: 'Returns `"true"` if the current branch is a tag else `"false"`.'
|
2022-03-22 16:35:08 -04:00
|
|
|
default_branch:
|
|
|
|
value: ${{ steps.default.outputs.default_branch }}
|
2022-03-24 11:01:05 -04:00
|
|
|
description: 'The default branch name e.g `main` OR `master`'
|
2021-02-07 19:30:56 -05:00
|
|
|
current_branch:
|
|
|
|
value: ${{ steps.current_branch.outputs.current_branch }}
|
2022-08-27 09:35:53 -06:00
|
|
|
description: 'The current branch name regardless of event_type e.g `main`, `feature/test`'
|
2020-12-11 08:15:40 -05:00
|
|
|
base_ref_branch:
|
2020-12-11 08:41:21 -05:00
|
|
|
value: ${{ steps.branch.outputs.base_ref_branch }}
|
2022-09-24 00:38:31 -06:00
|
|
|
description: 'The target branch of a pull request or tag e.g `main`'
|
2020-12-11 08:15:40 -05:00
|
|
|
head_ref_branch:
|
2020-12-11 08:41:21 -05:00
|
|
|
value: ${{ steps.branch.outputs.head_ref_branch }}
|
2022-03-22 17:28:06 -04:00
|
|
|
description: 'The source branch of a pull request e.g `feature/test`'
|
2020-12-11 08:15:40 -05:00
|
|
|
ref_branch:
|
2020-12-11 08:41:21 -05:00
|
|
|
value: ${{ steps.branch.outputs.ref_branch }}
|
2022-03-22 17:28:06 -04:00
|
|
|
description: 'The branch that triggered the workflow run. e.g `1/merge`, `main`'
|
2021-04-24 06:35:28 -04:00
|
|
|
tag:
|
2021-04-24 06:50:42 -04:00
|
|
|
value: ${{ steps.tag.outputs.tag }}
|
2022-03-22 17:28:06 -04:00
|
|
|
description: 'The tag that triggered the workflow run. e.g `v0.0.1`, `0.0.1`'
|
2020-12-11 08:15:40 -05:00
|
|
|
|
|
|
|
runs:
|
2020-12-11 08:41:21 -05:00
|
|
|
using: "composite"
|
|
|
|
steps:
|
|
|
|
- id: branch
|
2023-12-02 22:39:12 -07:00
|
|
|
env:
|
|
|
|
GITHUB_REF: ${{ github.ref }}
|
|
|
|
GITHUB_BASE_REF: ${{ github.event.pull_request.base.ref || github.base_ref }}
|
|
|
|
GITHUB_HEAD_REF: ${{ github.event.pull_request.head.ref || github.head_ref }}
|
|
|
|
GITHUB_EVENT_BASE_REF: ${{ github.event.base_ref }}
|
|
|
|
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
|
2020-12-11 08:41:21 -05:00
|
|
|
run: |
|
2022-08-21 10:59:36 -06:00
|
|
|
# "Set branch names..."
|
2023-12-02 22:39:12 -07:00
|
|
|
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
|
|
|
|
BASE_REF=$(printf "%q" "$GITHUB_BASE_REF")
|
|
|
|
HEAD_REF=$(printf "%q" "$GITHUB_HEAD_REF")
|
|
|
|
REF=$(printf "%q" "$GITHUB_REF")
|
2021-09-14 13:38:39 -04:00
|
|
|
|
|
|
|
BASE_REF=${BASE_REF/refs\/heads\//}
|
|
|
|
HEAD_REF=${HEAD_REF/refs\/heads\//}
|
2021-04-24 06:35:28 -04:00
|
|
|
REF_BRANCH=${REF/refs\/pull\//}
|
2021-09-14 13:38:39 -04:00
|
|
|
REF_BRANCH=${REF_BRANCH/refs\/heads\//}
|
2022-10-15 22:45:18 -06:00
|
|
|
|
2023-11-29 15:39:56 -07:00
|
|
|
echo "base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "head_ref_branch=$(eval printf "%s" "$HEAD_REF")" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "ref_branch=$(eval printf "%s" "$REF_BRANCH")" >> "$GITHUB_OUTPUT"
|
2022-08-27 09:28:16 -06:00
|
|
|
else
|
2023-12-02 22:39:12 -07:00
|
|
|
BASE_REF=$(printf "%q" "$GITHUB_EVENT_BASE_REF")
|
|
|
|
BASE_REF=${BASE_REF/refs\/heads\/$INPUTS_STRIP_TAG_PREFIX/}
|
2022-10-15 22:45:18 -06:00
|
|
|
|
2023-11-29 15:39:56 -07:00
|
|
|
echo "base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
|
2021-04-24 06:35:28 -04:00
|
|
|
fi
|
2020-12-11 08:41:21 -05:00
|
|
|
shell: bash
|
2021-02-07 19:30:56 -05:00
|
|
|
- id: current_branch
|
2023-12-02 22:39:12 -07:00
|
|
|
env:
|
|
|
|
GITHUB_REF: ${{ github.ref }}
|
|
|
|
GITHUB_EVENT_NAME: ${{ github.event_name }}
|
|
|
|
HEAD_REF_BRANCH: ${{ steps.branch.outputs.head_ref_branch }}
|
|
|
|
REF_BRANCH: ${{ steps.branch.outputs.ref_branch }}
|
2021-02-07 19:30:56 -05:00
|
|
|
run: |
|
2022-08-21 10:59:36 -06:00
|
|
|
# "Set the current branch name..."
|
2023-12-02 22:39:12 -07:00
|
|
|
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
|
|
|
|
if [[ "$GITHUB_EVENT_NAME" == *"pull_request"* ]]; then
|
|
|
|
echo "current_branch=$HEAD_REF_BRANCH" >> "$GITHUB_OUTPUT"
|
2021-05-25 12:26:52 -04:00
|
|
|
else
|
2023-12-02 22:39:12 -07:00
|
|
|
echo "current_branch=$REF_BRANCH" >> "$GITHUB_OUTPUT"
|
2021-05-25 12:26:52 -04:00
|
|
|
fi
|
2021-02-07 19:30:56 -05:00
|
|
|
fi
|
2023-12-02 22:47:24 -07:00
|
|
|
shell: bash
|
2023-12-02 22:42:21 -07:00
|
|
|
- id: default
|
2023-12-02 22:39:12 -07:00
|
|
|
env:
|
|
|
|
GITHUB_REF: ${{ github.ref }}
|
|
|
|
CURRENT_BRANCH: ${{ steps.current_branch.outputs.current_branch }}
|
|
|
|
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
|
|
|
|
FORK: ${{ github.event.pull_request.head.repo.fork }}
|
2021-02-12 16:30:56 -05:00
|
|
|
run: |
|
2022-08-21 10:59:36 -06:00
|
|
|
# "Set the default branch name..."
|
2023-12-02 22:39:12 -07:00
|
|
|
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
|
|
|
|
if [[ "$CURRENT_BRANCH" == "$DEFAULT_BRANCH" && "$FORK" != "true" ]]; then
|
2023-11-29 15:39:56 -07:00
|
|
|
echo "is_default=true" >> "$GITHUB_OUTPUT"
|
2023-12-02 22:39:12 -07:00
|
|
|
echo "default_branch=$DEFAULT_BRANCH" >> "$GITHUB_OUTPUT"
|
2021-04-24 21:16:05 -04:00
|
|
|
else
|
2023-11-29 15:39:56 -07:00
|
|
|
echo "is_default=false" >> "$GITHUB_OUTPUT"
|
2023-12-02 22:39:12 -07:00
|
|
|
echo "default_branch=$DEFAULT_BRANCH" >> "$GITHUB_OUTPUT"
|
2021-04-24 21:16:05 -04:00
|
|
|
fi
|
2021-02-12 16:30:56 -05:00
|
|
|
fi
|
2021-04-24 06:35:28 -04:00
|
|
|
shell: bash
|
|
|
|
- id: tag
|
2023-12-02 22:39:12 -07:00
|
|
|
env:
|
|
|
|
GITHUB_REF: ${{ github.ref }}
|
|
|
|
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
|
2021-04-24 06:35:28 -04:00
|
|
|
run: |
|
2022-08-21 10:59:36 -06:00
|
|
|
# "Set the tag name..."
|
2023-12-02 22:39:12 -07:00
|
|
|
if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
|
|
|
|
REF=$(printf "%q" "$GITHUB_REF")
|
2023-12-02 23:18:56 -07:00
|
|
|
TAG="${REF/refs\/tags\/$INPUTS_STRIP_TAG_PREFIX/}"
|
2021-09-14 13:38:39 -04:00
|
|
|
|
2023-11-29 15:39:56 -07:00
|
|
|
echo "tag=$(eval printf "%s" "$TAG")" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "is_tag=true" >> "$GITHUB_OUTPUT"
|
2021-05-27 08:24:26 -04:00
|
|
|
else
|
2023-11-29 15:39:56 -07:00
|
|
|
echo "is_tag=false" >> "$GITHUB_OUTPUT"
|
2021-04-24 06:35:28 -04:00
|
|
|
fi
|
|
|
|
shell: bash
|
2021-02-07 19:39:26 -05:00
|
|
|
|
2020-12-11 08:15:40 -05:00
|
|
|
branding:
|
|
|
|
icon: git-branch
|
|
|
|
color: white
|