Skip to content

Commit d245439

Browse files
committed
build: move logic to standalone script and clean-up
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent d85208a commit d245439

File tree

2 files changed

+134
-45
lines changed

2 files changed

+134
-45
lines changed

.github/workflows/merge_ready_prs.yml

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,56 +47,23 @@ jobs:
4747
- name: 'Checkout repository'
4848
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
4949

50+
# Import GPG key to sign commits:
51+
- name: 'Import GPG key to sign commits'
52+
uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
53+
with:
54+
gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
55+
passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
56+
git_user_signingkey: true
57+
git_commit_gpgsign: true
58+
5059
# Merge PRs with Ready to Merge label:
5160
- name: 'Merge PRs'
5261
env:
5362
GH_TOKEN: ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }}
5463
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }}
5564
run: |
56-
# Get all PRs with the "Ready to Merge" label:
57-
prs=$(gh pr list --label "Ready to Merge" --json number --jq '.[].number')
58-
59-
if [ -z "$prs" ]; then
60-
echo "No PRs found with 'Ready to Merge' label."
61-
exit 0
62-
fi
63-
64-
echo "Found PRs to merge: $prs"
65-
echo ""
66-
67-
# If dry run, just print the PRs and exit:
6865
if [ "${{ inputs.dry-run }}" == "true" ]; then
69-
echo "Dry run mode. PRs that would be merged:"
70-
for pr in $prs; do
71-
echo " - PR #$pr"
72-
done
73-
exit 0
74-
fi
75-
76-
# Track results:
77-
succeeded=""
78-
failed=""
79-
80-
# Merge each PR:
81-
for pr in $prs; do
82-
echo "Merging PR #$pr..."
83-
if ./.github/workflows/scripts/merge_pr "$pr"; then
84-
echo "Successfully merged PR #$pr"
85-
succeeded="$succeeded $pr"
86-
else
87-
echo "Failed to merge PR #$pr"
88-
failed="$failed $pr"
89-
fi
90-
echo ""
91-
done
92-
93-
# Print summary:
94-
echo "================================"
95-
echo "Summary:"
96-
if [ -n "$succeeded" ]; then
97-
echo "Merged:$succeeded"
98-
fi
99-
if [ -n "$failed" ]; then
100-
echo "Failed:$failed"
101-
exit 1
66+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/merge_ready_prs" --dry-run
67+
else
68+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/merge_ready_prs"
10269
fi
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
#/
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2025 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#/
19+
20+
# Script to merge all PRs with the "Ready to Merge" label.
21+
#
22+
# Usage: merge_ready_prs [--dry-run]
23+
#
24+
# Options:
25+
#
26+
# --dry-run Only print PRs that would be merged without merging them.
27+
#
28+
# Environment variables:
29+
#
30+
# GH_TOKEN GitHub token for gh CLI authentication.
31+
# GITHUB_TOKEN GitHub token for API calls (used by merge_pr script).
32+
33+
# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails:
34+
set -o pipefail
35+
36+
37+
# VARIABLES #
38+
39+
# Determine the script's directory:
40+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
41+
42+
# Parse arguments:
43+
dry_run=false
44+
if [ "${1}" = "--dry-run" ]; then
45+
dry_run=true
46+
fi
47+
48+
# Track results:
49+
succeeded=""
50+
failed=""
51+
52+
53+
# FUNCTIONS #
54+
55+
# Main execution sequence.
56+
main() {
57+
local succeeded_count
58+
local failed_count
59+
local prs
60+
local pr
61+
62+
# Get all PRs with the "Ready to Merge" label:
63+
prs=$(gh pr list --label "Ready to Merge" --json number --jq '.[].number')
64+
65+
if [ -z "${prs}" ]; then
66+
echo "No PRs found with 'Ready to Merge' label."
67+
exit 0
68+
fi
69+
70+
echo "Found PRs to merge: ${prs}"
71+
echo ""
72+
73+
# If dry run, just print the PRs and exit:
74+
if [ "${dry_run}" = true ]; then
75+
echo "Dry run mode. PRs that would be merged:"
76+
for pr in ${prs}; do
77+
echo " - PR #${pr}"
78+
done
79+
exit 0
80+
fi
81+
82+
# Merge each PR:
83+
for pr in ${prs}; do
84+
echo "Merging PR #${pr}..."
85+
if "${script_dir}/merge_pr" "${pr}"; then
86+
echo "Successfully merged PR #${pr}"
87+
succeeded="${succeeded} ${pr}"
88+
else
89+
echo "Failed to merge PR #${pr}"
90+
failed="${failed} ${pr}"
91+
fi
92+
echo ""
93+
done
94+
95+
# Print summary:
96+
echo ""
97+
echo "Results"
98+
echo "-------"
99+
100+
# Count results:
101+
succeeded_count=0
102+
failed_count=0
103+
if [ -n "${succeeded}" ]; then
104+
succeeded_count=$(echo "${succeeded}" | wc -w | tr -d ' ')
105+
fi
106+
if [ -n "${failed}" ]; then
107+
failed_count=$(echo "${failed}" | wc -w | tr -d ' ')
108+
fi
109+
110+
echo "Succeeded: ${succeeded_count}"
111+
echo "Failed: ${failed_count}"
112+
113+
if [ -n "${failed}" ]; then
114+
echo ""
115+
echo "The following PRs failed to merge:${failed}"
116+
exit 1
117+
fi
118+
exit 0
119+
}
120+
121+
# Call main with all command-line arguments:
122+
main "${@}"

0 commit comments

Comments
 (0)