Skip to content

Commit

Permalink
Merge pull request #36 from JarvusInnovations/releases/github-actions…
Browse files Browse the repository at this point in the history
…/release-prepare/r5

fix: only match open PRs
  • Loading branch information
themightychris authored Nov 22, 2023
2 parents f7bfab0 + 50f8498 commit 286bb97
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions github-actions/release-prepare/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GITHUB_TOKEN=PASTE_YOUR_TOKEN
GITHUB_REPOSITORY=exampleorg/exampleproject
RELEASE_BRANCH=main
GITHUB_REF_NAME=develop
1 change: 1 addition & 0 deletions github-actions/release-prepare/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
19 changes: 19 additions & 0 deletions github-actions/release-prepare/README.md
Original file line number Diff line number Diff line change
@@ -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
```
19 changes: 13 additions & 6 deletions github-actions/release-prepare/pull-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,25 @@ 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..."
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}"
Expand Down

0 comments on commit 286bb97

Please sign in to comment.