diff --git a/gh-act b/gh-act index 30a1363..c045f6a 100755 --- a/gh-act +++ b/gh-act @@ -4,6 +4,7 @@ set -euo pipefail SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" &>/dev/null && pwd -P) GH_ACT_VERSION=0.5 +TEMPFILE_DIR= msg() { echo >&2 -e "${1-}" @@ -198,7 +199,7 @@ function is_valid_user { return $? } -function user_json { +function user_json_ { # shellcheck disable=SC2016,SC2086 USER_JSON_TEMPLATE='{ "avatar_url": "{{.avatar_url}}", @@ -229,6 +230,15 @@ function user_json { fi } +function user_json { + + if [ -f "${TEMPFILE_DIR}/users/$1.json" ]; then + cat "${TEMPFILE_DIR}/users/$1.json" + fi + + user_json_ "$1" | tee "${TEMPFILE_DIR}/users/$1.json" +} + function issue_json { ISSUE_NUMBER=$1 parts_json issue @@ -428,7 +438,7 @@ function pull_request_event_envs() { # shellcheck disable=SC2086 BEFORE=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -2 | head -1) - # shellcheck disable=SC2086 + # shellcheck disable=SC2016 read -r HEAD HEAD_USER <<< $(gh pr view ${PULL_REQUEST_SPEC} --json commits \ --template '{{- $last := 0}} {{- range $index, $element := .commits}}{{$last = $index}}{{end}} @@ -1167,6 +1177,7 @@ function create_event_json() { if [ -f "${SCRIPT_DIR}/templates/${EVENT_NAME}.json" ]; then # common + # shellcheck disable=SC2046 read -r OWNER REPO \ <<< $(gh repo view --json owner,name --template '{{ .owner.login }} {{ .name }}') @@ -1270,10 +1281,10 @@ function act_post_action() { true } -TEMPFILE_DIR= function tempdir() { if [ -z "${TEMPFILE_DIR}" ] || [ ! -d "${TEMPFILE_DIR}" ]; then TEMPFILE_DIR=$(mktemp -d gh-act.XXXXXX) + mkdir "${TEMPFILE_DIR}/users" trap 'rm -rf "${TEMPFILE_DIR}"' EXIT fi }