forked from ublue-os/bluefin-lts
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (68 loc) · 2.24 KB
/
create-lts-pr.yml
File metadata and controls
78 lines (68 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Create LTS Promotion PR
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: create-lts-pr
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: main
fetch-depth: 0
- name: Fetch lts
run: git fetch origin lts
- name: Check content diff
id: diff
run: |
if git diff --quiet origin/lts origin/main; then
echo "No content difference between lts and main. Nothing to promote."
echo "has_diff=false" >> "$GITHUB_OUTPUT"
else
echo "has_diff=true" >> "$GITHUB_OUTPUT"
fi
- name: Build commit list
if: steps.diff.outputs.has_diff == 'true'
id: commits
run: |
LIST=$(git log origin/lts..origin/main --oneline)
{
echo "list<<EOF"
echo "$LIST"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create or update promote PR
if: steps.diff.outputs.has_diff == 'true'
env:
GH_TOKEN: ${{ github.token }}
COMMIT_LIST: ${{ steps.commits.outputs.list }}
run: |
# Build body with printf so commit messages containing quotes are safe
BODY=$(printf '## Commits pending promotion to `lts`\n\n%s\n\n---\n_Squash-merge this PR to promote. The PR body updates automatically as `main` advances._\n' "${COMMIT_LIST}")
EXISTING=$(gh pr list \
--base lts \
--head main \
--state open \
--json number \
--jq '.[0].number' \
2>/dev/null || echo "")
if [ -n "$EXISTING" ]; then
echo "Updating existing promote PR #${EXISTING}"
printf '%s\n' "${BODY}" | gh pr edit "$EXISTING" --body-file - || true
else
echo "Creating new draft promote PR"
printf '%s\n' "${BODY}" | gh pr create \
--draft \
--base lts \
--head main \
--title "promote: main → lts" \
--body-file -
fi