Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce api call #96

Merged
merged 7 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deployment-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:

jobs:
test:
deployment-test:
runs-on: ubuntu-latest
environment: gh-act-env
steps:
Expand Down
33 changes: 24 additions & 9 deletions gh-act
Original file line number Diff line number Diff line change
Expand Up @@ -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-}"
Expand Down Expand Up @@ -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}}",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -425,12 +435,16 @@ function pull_request_event_envs() {
fi

pr_envs "${PULL_REQUEST_SPEC}"
# shellcheck disable=SC2086
HEAD=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -1)
# shellcheck disable=SC2086
HEAD_USER=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].authors[].login | tail -1)

# shellcheck disable=SC2086
BEFORE=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -2 | head -1)
# shellcheck disable=SC2016
read -r HEAD HEAD_USER <<< $(gh pr view ${PULL_REQUEST_SPEC} --json commits \
srz-zumix marked this conversation as resolved.
Show resolved Hide resolved
srz-zumix marked this conversation as resolved.
Show resolved Hide resolved
srz-zumix marked this conversation as resolved.
Show resolved Hide resolved
--template '{{- $last := 0}}
srz-zumix marked this conversation as resolved.
Show resolved Hide resolved
{{- range $index, $element := .commits}}{{$last = $index}}{{end}}
{{- $commit := index .commits $last}}
{{- $author := index $commit.authors 0}}
{{- $commit.oid }} {{ $author.login -}}')

# base
repo_envs "${OWNER}/${REPO}" "BASE"
Expand Down Expand Up @@ -1163,8 +1177,9 @@ function create_event_json() {
if [ -f "${SCRIPT_DIR}/templates/${EVENT_NAME}.json" ]; then

# common
OWNER=$(gh repo view --json owner --jq .owner.login)
REPO=$(gh repo view --json name --jq .name)
# shellcheck disable=SC2046
read -r OWNER REPO \
<<< $(gh repo view --json owner,name --template '{{ .owner.login }} {{ .name }}')
srz-zumix marked this conversation as resolved.
Show resolved Hide resolved

evnet_envs

Expand Down Expand Up @@ -1266,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
}
Expand Down Expand Up @@ -1330,7 +1345,7 @@ function main() {
ACT_OPTIONS+=(--artifact-server-path "${TEMP_ARTIFACT_DIR}")
fi

act "$@" "${ACT_OPTIONS[@]}" && act_post_action
# act "$@" "${ACT_OPTIONS[@]}" && act_post_action
}

case "${EVENT_NAME:-}" in
Expand Down