forked from redhat-actions/common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·53 lines (42 loc) · 1.43 KB
/
entrypoint.sh
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
#!/bin/sh -l
set -e -o pipefail
if [[ $INPUT_WORKING_DIRECTORY ]]; then
echo "Working directory is $INPUT_WORKING_DIRECTORY"
cd $INPUT_WORKING_DIRECTORY
fi
# log the latest commit data
git log -1
commit_sha=$(git rev-parse HEAD)
echo "HEAD commit SHA is $commit_sha"
short_sha=$(echo $commit_sha | cut -c -7)
echo "Short commit SHA is $short_sha"
branch=$(git branch --show-current)
echo "HEAD branch is $branch"
# not set if not in an action workflow. https://docs.github.com/en/actions/reference/environment-variables
if [ -n "${GITHUB_HEAD_REF:-}" ]; then
is_pr=true
pr_head=${GITHUB_HEAD_REF}
pr_base=${GITHUB_BASE_REF}
echo "This workflow is a PR from ${GITHUB_HEAD_REF} targeting ${GITHUB_BASE_REF}"
else
is_pr=false
echo "Not a PR workflow"
fi
tags=$(git tag --points-at HEAD | xargs)
tag=$(echo $tags | awk '{ print $1 }')
tags_count=$(echo $tags | wc -w | xargs)
if [ -z "$tags" ]; then
echo "No tags point to this commit"
elif [ 1 -eq "$tags_count" ]; then
echo "Tag $tags points to this commit"
else
echo "$tags_count tags point to this commit: $tags"
fi
echo "::set-output name=branch::${branch}"
echo "::set-output name=is_pr::${is_pr}"
echo "::set-output name=pr_head::${pr_head}"
echo "::set-output name=pr_base::${pr_base}"
echo "::set-output name=short_sha::$short_sha"
echo "::set-output name=tag::$tag"
echo "::set-output name=tags::$tags"
echo "::set-output name=tag_count::$tags_count"