-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.sh
executable file
·30 lines (27 loc) · 1.14 KB
/
action.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
#!/bin/bash
echo "Note: GITHUB_REF=${GITHUB_REF}"
if [[ "${GITHUB_REF}" == "refs/heads"* ]]; then
echo "Note: This is a push to a local branch -> using branch name"
BRANCH=${GITHUB_REF#refs/heads/}
BRANCH_SLUG=$(echo $BRANCH | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z)
else
if [[ "${GITHUB_REF}" == "refs/pull/"* ]]; then
# usually the format for PRs is: refs/pull/1234/merge
echo "Note: This is a Pull Request -> using PR ID"
tmp=${GITHUB_REF#refs/pull/}
# remove the last "/merge"
# Branch name is basically the PR id
BRANCH=PR-${tmp%/merge}
# And Slug is "PR-${PRID}"
BRANCH_SLUG=${BRANCH}
else
echo "::error This is neither a push, nor a PR, probably something else... Exiting"
exit 1
fi
fi
GIT_SHA="$(git rev-parse --short HEAD)"
# print GIT_SHA, BRANCH and BRANCH_SLUG (make sure they are also set in needs.prepare_ci_run.outputs !!!)
# shellcheck disable=SC2129
echo "BRANCH=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "BRANCH_SLUG=${BRANCH_SLUG}" >> "$GITHUB_OUTPUT"
echo "GIT_SHA=${GIT_SHA}" >> "$GITHUB_OUTPUT"