-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
action.yml
121 lines (114 loc) · 4.72 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Branch Names
description: Retrieve github branch or tag information without the /ref/* prefix
author: tj-actions
inputs:
strip_tag_prefix:
description: 'The prefix that should be stripped from the tag e.g `v` -> with a tag `v0.0.1` -> returns `0.0.1`'
default: ''
required: false
outputs:
is_default:
value: ${{ steps.default.outputs.is_default }}
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"`.'
default_branch:
value: ${{ steps.default.outputs.default_branch }}
description: 'The default branch name e.g `main` OR `master`'
current_branch:
value: ${{ steps.current_branch.outputs.current_branch }}
description: 'The current branch name regardless of event_type e.g `main`, `feature/test`'
base_ref_branch:
value: ${{ steps.branch.outputs.base_ref_branch }}
description: 'The target branch of a pull request or tag e.g `main`'
head_ref_branch:
value: ${{ steps.branch.outputs.head_ref_branch }}
description: 'The source branch of a pull request e.g `feature/test`'
ref_branch:
value: ${{ steps.branch.outputs.ref_branch }}
description: 'The branch that triggered the workflow run. e.g `1/merge`, `main`'
tag:
value: ${{ steps.tag.outputs.tag }}
description: 'The tag that triggered the workflow run. e.g `v0.0.1`, `0.0.1`'
runs:
using: "composite"
steps:
- id: branch
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 }}
run: |
# "Set branch names..."
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")
BASE_REF=${BASE_REF/refs\/heads\//}
HEAD_REF=${HEAD_REF/refs\/heads\//}
REF_BRANCH=${REF/refs\/pull\//}
REF_BRANCH=${REF_BRANCH/refs\/heads\//}
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"
else
BASE_REF=$(printf "%q" "$GITHUB_EVENT_BASE_REF")
BASE_REF=${BASE_REF/refs\/heads\/$INPUTS_STRIP_TAG_PREFIX/}
echo "base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
fi
shell: bash
- id: current_branch
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 }}
run: |
# "Set the current branch name..."
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
if [[ "$GITHUB_EVENT_NAME" == *"pull_request"* ]]; then
echo "current_branch=$HEAD_REF_BRANCH" >> "$GITHUB_OUTPUT"
else
echo "current_branch=$REF_BRANCH" >> "$GITHUB_OUTPUT"
fi
fi
shell: bash
- id: default
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 }}
run: |
# "Set the default branch name..."
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
if [[ "$CURRENT_BRANCH" == "$DEFAULT_BRANCH" && "$FORK" != "true" ]]; then
echo "is_default=true" >> "$GITHUB_OUTPUT"
echo "default_branch=$DEFAULT_BRANCH" >> "$GITHUB_OUTPUT"
else
echo "is_default=false" >> "$GITHUB_OUTPUT"
echo "default_branch=$DEFAULT_BRANCH" >> "$GITHUB_OUTPUT"
fi
fi
shell: bash
- id: tag
env:
GITHUB_REF: ${{ github.ref }}
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
run: |
# "Set the tag name..."
if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
REF=$(printf "%q" "$GITHUB_REF")
TAG="${REF/refs\/tags\/$INPUTS_STRIP_TAG_PREFIX/}"
echo "tag=$(eval printf "%s" "$TAG")" >> "$GITHUB_OUTPUT"
echo "is_tag=true" >> "$GITHUB_OUTPUT"
else
echo "is_tag=false" >> "$GITHUB_OUTPUT"
fi
shell: bash
branding:
icon: git-branch
color: white