-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaction.yml
36 lines (36 loc) · 1.43 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
name: 'Commit range'
description: 'Determine commit range'
outputs:
commit-range:
description: 'Range of commits in this run'
value: ${{ steps.commit-range.outputs.commit-range }}
runs:
using: "composite"
steps:
- name: Commit range
id: commit-range
env:
commit_list: ${{ toJson(github.event.commits) }} # Doing this inside run doesn't work because of piping
run: |
if [ "${GITHUB_EVENT_NAME}" == "push" ]
then
NUMBER_COMMITS=$(echo "${commit_list}" | jq 'length')
if [ ${NUMBER_COMMITS} -le 1 ]
then
COMMIT_RANGE=""
else
OLDEST=$(echo "${commit_list}" | jq 'first.id' | tr -d '"')
NEWEST=$(echo "${commit_list}" | jq 'last.id' | tr -d '"')
OLDEST_PARENTS=($(git show --no-patch --format="%P" ${OLDEST}))
NUMBER_OLDEST_PARENTS=${#OLDEST_PARENTS[@]}
COMMIT_RANGE="${OLDEST}^${NUMBER_OLDEST_PARENTS}...${NEWEST}" # Take second parent if possible, see https://stackoverflow.com/a/2222920
fi
elif [ "${GITHUB_EVENT_NAME}" == "pull_request" ]
then
OLDEST=${{ github.event.pull_request.base.sha }}
NEWEST=${{ github.event.pull_request.head.sha }}
COMMIT_RANGE="${OLDEST}...${NEWEST}"
fi
echo -e "\e[35;1m COMMIT_RANGE = ${COMMIT_RANGE} \e[0m"
echo "commit-range=${COMMIT_RANGE}" >> $GITHUB_OUTPUT
shell: bash