setup-git-repo 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "setup-git-repo",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "One command to set up a GitHub repo: Turborepo, CI workflows, README badges, and the docs for each",
5
5
  "type": "module",
6
6
  "bin": {
@@ -24,8 +24,8 @@ jobs:
24
24
  maintain-pull-requests:
25
25
  runs-on: ubuntu-latest
26
26
  env:
27
- GH_TOKEN: ${{ secrets.GIT_TOKEN }}
28
- GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
27
+ GH_TOKEN: ${{ secrets.GIT_TOKEN || secrets.GITHUB_TOKEN }}
28
+ GIT_TOKEN: ${{ secrets.GIT_TOKEN || secrets.GITHUB_TOKEN }}
29
29
  BASE_BRANCH: ${{ github.event.repository.default_branch }}
30
30
  steps:
31
31
  - name: Merge eligible existing pull requests
@@ -41,15 +41,21 @@ jobs:
41
41
  --repo "$REPOSITORY" \
42
42
  --state open \
43
43
  --json number,isDraft,mergeStateStatus,reviewDecision,statusCheckRollup \
44
- --jq '.[] | select(.isDraft == false) | select(.mergeStateStatus == "CLEAN") | select((.reviewDecision == "APPROVED") or (.reviewDecision == "")) | select(all(.statusCheckRollup[]?; (.conclusion == "SUCCESS" or .conclusion == "SKIPPED" or .conclusion == "NEUTRAL"))) | .number' \
45
- | while read -r pr_number; do
46
- echo "Attempting to merge PR #${pr_number}"
47
- gh pr merge "$pr_number" \
48
- --repo "$REPOSITORY" \
49
- --merge \
50
- --delete-branch \
51
- --auto || echo "Could not merge PR #${pr_number}; it may require review, checks, or conflict resolution."
52
- done
44
+ --jq '.[] | select(.isDraft == false) | select(.mergeStateStatus == "CLEAN") | select((.reviewDecision // "") as $decision | $decision == "APPROVED" or $decision == "") | select(all(.statusCheckRollup[]?; (.conclusion == "SUCCESS" or .conclusion == "SKIPPED" or .conclusion == "NEUTRAL"))) | .number' \
45
+ > "$RUNNER_TEMP/mergeable-prs.txt"
46
+
47
+ # The numbers go through a file rather than a pipe: a piped `while`
48
+ # runs in a subshell that shares its stdin with `gh`, and a pipeline
49
+ # under `pipefail` fails the step for a producer that merely had
50
+ # nothing to say.
51
+ while read -r pr_number; do
52
+ echo "Attempting to merge PR #${pr_number}"
53
+ gh pr merge "$pr_number" \
54
+ --repo "$REPOSITORY" \
55
+ --merge \
56
+ --delete-branch \
57
+ --auto || echo "Could not merge PR #${pr_number}; it may require review, checks, or conflict resolution."
58
+ done < "$RUNNER_TEMP/mergeable-prs.txt"
53
59
 
54
60
  - name: Create pull requests for branches without one
55
61
  env:
@@ -67,30 +73,41 @@ jobs:
67
73
 
68
74
  base_sha="$(git rev-parse "origin/${BASE_BRANCH}")"
69
75
 
76
+ # Not `for-each-ref | grep | while`: `grep` exits 1 when it filters
77
+ # every ref out, and `pipefail` turns that into a failed run on the
78
+ # ordinary "only the default branch is left" case. The refs go
79
+ # through a file, and the ones to leave alone are skipped inside the
80
+ # loop, so an empty list is a no-op.
70
81
  git for-each-ref --format='%(refname:strip=3)' refs/remotes/origin \
71
- | grep -Ev "^(HEAD|${BASE_BRANCH})$" \
72
- | while read -r branch; do
73
- open_pr="$(gh pr list --repo "$REPOSITORY" --state open --head "$branch" --json number --jq 'length')"
74
- merged_pr="$(gh pr list --repo "$REPOSITORY" --state merged --head "$branch" --json number --jq 'length')"
75
- branch_sha="$(git rev-parse "origin/${branch}")"
82
+ > "$RUNNER_TEMP/branches.txt"
83
+
84
+ while read -r branch; do
85
+ if [ "$branch" = "HEAD" ] || [ "$branch" = "$BASE_BRANCH" ]; then
86
+ continue
87
+ fi
88
+
89
+ open_pr="$(gh pr list --repo "$REPOSITORY" --state open --head "$branch" --json number --jq 'length')"
90
+ merged_pr="$(gh pr list --repo "$REPOSITORY" --state merged --head "$branch" --json number --jq 'length')"
91
+ branch_sha="$(git rev-parse "origin/${branch}")"
76
92
 
77
- # A merged PR counts: reopening one for a branch whose work
78
- # already landed would create an empty, permanently open PR.
79
- if [ "$open_pr" -gt 0 ] || [ "$merged_pr" -gt 0 ]; then
80
- echo "Skipping ${branch}: a pull request already exists or was previously merged."
81
- continue
82
- fi
93
+ # A merged PR counts: reopening one for a branch whose work
94
+ # already landed would create an empty, permanently open PR.
95
+ if [ "$open_pr" -gt 0 ] || [ "$merged_pr" -gt 0 ]; then
96
+ echo "Skipping ${branch}: a pull request already exists or was previously merged."
97
+ continue
98
+ fi
83
99
 
84
- if git merge-base --is-ancestor "$branch_sha" "$base_sha"; then
85
- echo "Skipping ${branch}: it is already contained in ${BASE_BRANCH}."
86
- continue
87
- fi
100
+ if git merge-base --is-ancestor "$branch_sha" "$base_sha"; then
101
+ echo "Skipping ${branch}: it is already contained in ${BASE_BRANCH}."
102
+ continue
103
+ fi
88
104
 
89
- echo "Creating PR for ${branch} -> ${BASE_BRANCH}"
90
- gh pr create \
91
- --repo "$REPOSITORY" \
92
- --head "$branch" \
93
- --base "$BASE_BRANCH" \
94
- --title "Merge ${branch} into ${BASE_BRANCH}" \
95
- --body "Automated pull request for branch \`${branch}\`."
96
- done
105
+ echo "Creating PR for ${branch} -> ${BASE_BRANCH}"
106
+ gh pr create \
107
+ --repo "$REPOSITORY" \
108
+ --head "$branch" \
109
+ --base "$BASE_BRANCH" \
110
+ --title "Merge ${branch} into ${BASE_BRANCH}" \
111
+ --body "Automated pull request for branch \`${branch}\`." \
112
+ || echo "Could not open a PR for ${branch}."
113
+ done < "$RUNNER_TEMP/branches.txt"