From 54cfde43f026927f1109b8e0b7ef18ae85a8e0dd Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Fri, 8 Sep 2023 17:27:49 +0900 Subject: [PATCH 1/7] wip --- gh-act | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gh-act b/gh-act index 4764636..61601f1 100755 --- a/gh-act +++ b/gh-act @@ -426,11 +426,7 @@ function pull_request_event_envs() { 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) + read -r HEAD HEAD_USER BEFORE <<< $(gh repo view --json commits --templte '{{ .commits[-1].oid }} {{ .commits[-1].authors[0].login }} {{ .commits[-2].oid }}') # base repo_envs "${OWNER}/${REPO}" "BASE" @@ -1163,8 +1159,7 @@ 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) + read -r OWNER REPO <<< $(gh repo view --json owner,name --templte '{{ .owner.login }} {{ .name }}') evnet_envs From 7e0248f829c33511f9366a12d281cd6b85b03cfb Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Sun, 10 Sep 2023 10:35:16 +0900 Subject: [PATCH 2/7] up --- .github/workflows/deployment-test.yml | 2 +- gh-act | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deployment-test.yml b/.github/workflows/deployment-test.yml index 1912f0d..763a8f7 100644 --- a/.github/workflows/deployment-test.yml +++ b/.github/workflows/deployment-test.yml @@ -3,7 +3,7 @@ on: workflow_dispatch: jobs: - test: + deployment-test: runs-on: ubuntu-latest environment: gh-act-env steps: diff --git a/gh-act b/gh-act index 61601f1..30a1363 100755 --- a/gh-act +++ b/gh-act @@ -425,8 +425,16 @@ function pull_request_event_envs() { fi pr_envs "${PULL_REQUEST_SPEC}" + + # shellcheck disable=SC2086 + BEFORE=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -2 | head -1) # shellcheck disable=SC2086 - read -r HEAD HEAD_USER BEFORE <<< $(gh repo view --json commits --templte '{{ .commits[-1].oid }} {{ .commits[-1].authors[0].login }} {{ .commits[-2].oid }}') + read -r HEAD HEAD_USER <<< $(gh pr view ${PULL_REQUEST_SPEC} --json commits \ + --template '{{- $last := 0}} +{{- 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" @@ -1159,7 +1167,8 @@ function create_event_json() { if [ -f "${SCRIPT_DIR}/templates/${EVENT_NAME}.json" ]; then # common - read -r OWNER REPO <<< $(gh repo view --json owner,name --templte '{{ .owner.login }} {{ .name }}') + read -r OWNER REPO \ + <<< $(gh repo view --json owner,name --template '{{ .owner.login }} {{ .name }}') evnet_envs @@ -1325,7 +1334,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 From 465b3a81e9f9a39eb06cbdee09aec1c8b7caff9f Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Sun, 24 Sep 2023 13:41:42 +0900 Subject: [PATCH 3/7] cache user json --- gh-act | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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 } From 5c8d9ad0ab2dff1181ae5fb04816016fb4c68582 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Sun, 24 Sep 2023 14:24:55 +0900 Subject: [PATCH 4/7] fix lint --- gh-act | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gh-act b/gh-act index c045f6a..29795e5 100755 --- a/gh-act +++ b/gh-act @@ -437,9 +437,9 @@ function pull_request_event_envs() { pr_envs "${PULL_REQUEST_SPEC}" # shellcheck disable=SC2086 - BEFORE=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -2 | head -1) + 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 \ + read -r HEAD HEAD_USER <<< $(gh pr view "${PULL_REQUEST_SPEC}" --json commits \ --template '{{- $last := 0}} {{- range $index, $element := .commits}}{{$last = $index}}{{end}} {{- $commit := index .commits $last}} From fc4dd06f0d817a8ae49da3209dfa51463cfef933 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Sun, 24 Sep 2023 14:48:04 +0900 Subject: [PATCH 5/7] fix lint --- gh-act | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gh-act b/gh-act index 29795e5..287bf5c 100755 --- a/gh-act +++ b/gh-act @@ -438,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=SC2016 + # shellcheck disable=SC2046 read -r HEAD HEAD_USER <<< $(gh pr view "${PULL_REQUEST_SPEC}" --json commits \ --template '{{- $last := 0}} {{- range $index, $element := .commits}}{{$last = $index}}{{end}} From 20b50eed023223709cb3eb164b8b620e7c9196f3 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Sun, 24 Sep 2023 22:30:52 +0900 Subject: [PATCH 6/7] fix error --- gh-act | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gh-act b/gh-act index 287bf5c..a982f04 100755 --- a/gh-act +++ b/gh-act @@ -231,12 +231,11 @@ function user_json_ { } function user_json { - if [ -f "${TEMPFILE_DIR}/users/$1.json" ]; then cat "${TEMPFILE_DIR}/users/$1.json" + else + user_json_ "$1" | tee "${TEMPFILE_DIR}/users/$1.json" fi - - user_json_ "$1" | tee "${TEMPFILE_DIR}/users/$1.json" } function issue_json { From 66d8368481c60853f09214a1034931405431a824 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Mon, 25 Sep 2023 09:50:20 +0900 Subject: [PATCH 7/7] fix watchers --- templates/parts/repo.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/templates/parts/repo.json b/templates/parts/repo.json index 52594c4..331f62b 100644 --- a/templates/parts/repo.json +++ b/templates/parts/repo.json @@ -75,7 +75,6 @@ "squash_merge_commit_message": "COMMIT_MESSAGES", "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", "ssh_url": "${REPO_SSH_URL}", - "stargazers": ${REPO_STARGAZER_COUNT}, "stargazers_count": ${REPO_STARGAZER_COUNT}, "stargazers_url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}/stargazers", "statuses_url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}/statuses/{sha}", @@ -90,7 +89,7 @@ "url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}", "use_squash_pr_title_as_default": false, "visibility": "${VISIBILITY}", - "watchers": ${REPO_WATCHERS_TOTAL_COUNT}, - "watchers_count": ${REPO_WATCHERS_TOTAL_COUNT}, + "watchers": ${REPO_STARGAZER_COUNT}, + "watchers_count": ${REPO_STARGAZER_COUNT}, "web_commit_signoff_required": false }