From 4088e9334d0599824ad97e994287ffac03f64c4f Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Wed, 22 Nov 2023 12:01:23 -0500 Subject: [PATCH 1/3] fix: only match open PRs --- github-actions/release-prepare/pull-request.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/github-actions/release-prepare/pull-request.sh b/github-actions/release-prepare/pull-request.sh index d2e042d..b3fd4dc 100755 --- a/github-actions/release-prepare/pull-request.sh +++ b/github-actions/release-prepare/pull-request.sh @@ -29,7 +29,13 @@ EOF # create or update PR echo "Looking for existing PR..." -pr_number=$(gh pr view "${GITHUB_REF_NAME}" --json number --jq '.number') +pr_number=$( + gh pr view "${GITHUB_REF_NAME}" \ + --json number,state \ + --template '{{.number}}{{"\t"}}{{.state}}' \ + | grep OPEN \ + | awk '{print $1}' +) if [ -n "${pr_number}" ]; then echo "Found existing PR #${pr_number}, looking for existing comment..." From 600851b068a6e7efc5baa8fec9cbb284d69eab64 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Wed, 22 Nov 2023 12:02:05 -0500 Subject: [PATCH 2/3] style: break up multiline command --- github-actions/release-prepare/pull-request.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/github-actions/release-prepare/pull-request.sh b/github-actions/release-prepare/pull-request.sh index b3fd4dc..d789c1f 100755 --- a/github-actions/release-prepare/pull-request.sh +++ b/github-actions/release-prepare/pull-request.sh @@ -42,11 +42,12 @@ if [ -n "${pr_number}" ]; then existing_comment_id=$(gh api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" --jq '.[] | select(.body | startswith("## Changelog\n\n")) | .id') else echo "Opening PR..." - pr_url=$(gh pr create \ - --base "${RELEASE_BRANCH}" \ - --head "${GITHUB_REF_NAME}" \ - --title "${pr_title}" \ - --body "${pr_body}" + pr_url=$( + gh pr create \ + --base "${RELEASE_BRANCH}" \ + --head "${GITHUB_REF_NAME}" \ + --title "${pr_title}" \ + --body "${pr_body}" ) pr_number="${pr_url##*/}" echo "Opened PR #${pr_number}" From 50f849837c68b79400c5232b5bbd61f3635ca1a4 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Wed, 22 Nov 2023 12:02:36 -0500 Subject: [PATCH 3/3] feat: add documented local test flow --- github-actions/release-prepare/.env.example | 4 ++++ github-actions/release-prepare/.gitignore | 1 + github-actions/release-prepare/README.md | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 github-actions/release-prepare/.env.example create mode 100644 github-actions/release-prepare/.gitignore create mode 100644 github-actions/release-prepare/README.md diff --git a/github-actions/release-prepare/.env.example b/github-actions/release-prepare/.env.example new file mode 100644 index 0000000..c024a67 --- /dev/null +++ b/github-actions/release-prepare/.env.example @@ -0,0 +1,4 @@ +GITHUB_TOKEN=PASTE_YOUR_TOKEN +GITHUB_REPOSITORY=exampleorg/exampleproject +RELEASE_BRANCH=main +GITHUB_REF_NAME=develop diff --git a/github-actions/release-prepare/.gitignore b/github-actions/release-prepare/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/github-actions/release-prepare/.gitignore @@ -0,0 +1 @@ +.env diff --git a/github-actions/release-prepare/README.md b/github-actions/release-prepare/README.md new file mode 100644 index 0000000..f2790ba --- /dev/null +++ b/github-actions/release-prepare/README.md @@ -0,0 +1,19 @@ +# GitHub Action: release-prepare + +## Development + +This action encapsulates most of its complexity in a standalone Bash script that accepts environment variables, making it easy to test locally with the help of a `.env` file you can point at a test repository. + +1. Create `.env` from the template: + + ```bash + cp .env.example .env + ``` + +2. Paste a GitHub token and tailor repository/branches to your test target. + +3. Run bash script with `.env` applied to emulate GitHub Actions context: + + ```bash + eval $(< .env) ./pull-request.sh + ```