chore(build): get last completed run to check whether to rebuild docker

This commit is contained in:
Arthur Meyre
2021-09-22 12:46:51 +02:00
parent 5e8cacd9ea
commit 98bf595324
2 changed files with 85 additions and 3 deletions

View File

@@ -45,12 +45,33 @@ jobs:
steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
fetch-depth: 0
- name: Get changed files
if: ${{ (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/')) || github.event_name == 'pull_request' }}
uses: Ana06/get-changed-files@ea75ed777daf24d6e95f43957bd26b1eab20806c
id: files
with:
format: 'space-delimited'
env:
IS_PR: ${{ github.event_name == 'pull_request' }}
run: |
CURRENT_SHA="${{ github.sha }}"
if [[ "${IS_PR}" == "true" ]]; then
BEFORE_SHA="${{ github.event.pull_request.base.sha }}"
else
BEFORE_SHA="$(./script/actions_utils/get_latest_run.sh \
--token ${{ secrets.BOT_TOKEN }} \
--org-repo ${{ github.repository }} \
--event-types 'push workflow_dispatch repository_dispatch')"
fi
ALL_CHANGED_FILES=$(git diff --name-only "${CURRENT_SHA}" "${BEFORE_SHA}")
echo "Before sha1 ${BEFORE_SHA}"
echo "Current sha1 ${CURRENT_SHA}"
echo "Changed files:"
echo "${ALL_CHANGED_FILES}"
echo "::set-output name=all::${ALL_CHANGED_FILES//$'\n'/ }"
- name: Should rebuild docker check
run: |
set +e

View File

@@ -0,0 +1,61 @@
#!/bin/bash
TOKEN=
ORG_REPO=
EVENTS_TO_CHECK=
while [ -n "$1" ]
do
case "$1" in
"--token" )
shift
TOKEN="$1"
;;
"--org-repo" )
shift
ORG_REPO="$1"
;;
"--event-types" )
shift
EVENTS_TO_CHECK="$1"
;;
*)
echo "Unknown param : $1"
exit 1
;;
esac
shift
done
# Store the workflows that come in jsons in a file per event type
declare -a JSON_FILES_ARRAY=()
for EVENT in $EVENTS_TO_CHECK; do
CURR_FILE="$(mktemp --suffix=.json)"
curl \
-X GET \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${TOKEN}" \
"https://api.github.com/repos/${ORG_REPO}/actions/runs?branch=main&event=${EVENT}&status=success" | \
jq -rc '.workflow_runs | sort_by(.updated_at)[-1]' > "${CURR_FILE}"
JSON_FILES_ARRAY+=("${CURR_FILE}")
done
# Put all the workflows in the same json and dump that
CONCAT_FILE="$(mktemp --suffix=.json)"
jq -sr '.' "${JSON_FILES_ARRAY[@]}" > "${CONCAT_FILE}"
# Sort by updated_at, get the last and get the sha1 for this last one
BEFORE_SHA=$(jq -rc 'sort_by(.updated_at)[-1].head_sha' "${CONCAT_FILE}")
# Remove files
rm "${CONCAT_FILE}"
for FILE_TO_RM in "${JSON_FILES_ARRAY[@]}"; do
rm "${FILE_TO_RM}"
done
# Echo for the outside world
echo "${BEFORE_SHA}"