Skip to content

Commit e3e8ebb

Browse files
committed
Add workflow for creating release pull requests
1 parent 2266f8f commit e3e8ebb

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
# NOTE: This workflow belongs in the github/backup-utils repository.
3+
# It is stored here for convenience and should be copied to
4+
# github/backup-utils/.github/workflows/create-release-pr.yml
5+
#
6+
# This workflow is triggered via repository_dispatch from the
7+
# build-and-release workflow in backup-utils-private. It copies
8+
# docs and README.md from backup-utils-private onto a release branch
9+
# in backup-utils, then creates a PR using GITHUB_TOKEN so that the
10+
# PR author is github-actions[bot]. This allows the app token in
11+
# backup-utils-private to approve the PR as a different actor.
12+
name: Create Release PR
13+
14+
on:
15+
repository_dispatch:
16+
types: [create-release-pr]
17+
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
22+
jobs:
23+
create-release-pr:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/create-github-app-token@v1
27+
id: app-token
28+
with:
29+
app-id: ${{ vars.RELEASE_CONTROLLER_APP_ID }}
30+
private-key: ${{ secrets.RELEASE_CONTROLLER_APP_PRIVATE_KEY }}
31+
owner: ${{ github.repository_owner }}
32+
repositories: "backup-utils-private"
33+
34+
- name: Checkout backup-utils
35+
uses: actions/checkout@v5
36+
37+
- name: Checkout backup-utils-private
38+
uses: actions/checkout@v5
39+
with:
40+
token: ${{ steps.app-token.outputs.token }}
41+
repository: github/backup-utils-private
42+
path: './backup-utils-private'
43+
44+
- name: Replace docs directory with backup-utils-private docs
45+
run: |
46+
rm -rf docs
47+
cp -r backup-utils-private/docs docs
48+
49+
- name: Replace README.md with backup-utils-private README.md
50+
run: |
51+
rm README.md
52+
cp backup-utils-private/README.md README.md
53+
54+
- name: Delete backup-utils-private
55+
run: |
56+
rm -rf backup-utils-private
57+
58+
- name: Create release branch commit
59+
run: |
60+
version="${{ github.event.client_payload.version }}"
61+
branch="release/$version"
62+
git config user.name "github-actions[bot]"
63+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
64+
git checkout -B "$branch"
65+
git add docs README.md
66+
git commit --allow-empty -m "$version release"
67+
git push --force-with-lease --set-upstream origin "$branch"
68+
69+
- name: Create or find release pull request
70+
id: release-pr
71+
env:
72+
GH_TOKEN: ${{ github.token }}
73+
run: |
74+
version="${{ github.event.client_payload.version }}"
75+
branch="release/$version"
76+
pr_number="$(gh pr list --head "$branch" --base master --json number --jq '.[0].number')"
77+
78+
if [ -z "$pr_number" ]; then
79+
pr_url="$(gh pr create \
80+
--base master \
81+
--head "$branch" \
82+
--title "$version release" \
83+
--body "Automated release PR for v$version.")"
84+
pr_number="${pr_url##*/}"
85+
fi
86+
87+
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
88+
89+
- name: Enable auto-merge on release pull request
90+
env:
91+
GH_TOKEN: ${{ github.token }}
92+
run: |
93+
gh pr merge \
94+
--squash \
95+
--auto \
96+
"${{ steps.release-pr.outputs.number }}"

0 commit comments

Comments
 (0)