-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (83 loc) · 3.3 KB
/
Copy pathcreate-release-pr.yml
File metadata and controls
94 lines (83 loc) · 3.3 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Create Release PR
on:
push:
branches: [ develop ]
permissions:
contents: write
pull-requests: write
jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for existing release PR
id: check
run: |
EXISTING_PR=$(gh pr list --base main --head develop --state open --json number -q '.[0].number' 2>/dev/null || echo "")
echo "existing_pr=$EXISTING_PR" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate changelog
run: |
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
LOG=$(git log "${LAST_TAG}..HEAD" --pretty=format:"- %s" --no-merges || true)
else
MAIN_HEAD=$(git rev-parse origin/main 2>/dev/null || echo "")
if [ -n "$MAIN_HEAD" ]; then
LOG=$(git log "origin/main..HEAD" --pretty=format:"- %s" --no-merges || true)
else
LOG=$(git log --pretty=format:"- %s" --no-merges -20 || true)
fi
fi
# Always write to a fixed temp file. Never pass arbitrary commit
# messages through GITHUB_OUTPUT or expression interpolation.
printf '%s\n' "$LOG" > /tmp/release-changelog.txt
- name: Build PR body
run: |
# Build the PR body using only hardcoded paths. This guarantees
# the workflow file itself never contains expression syntax inside
# a run: block (the cause of previous "An expression was expected" errors).
{
echo "## Release: develop → main"
echo ""
echo "develop 브랜치의 변경사항을 main으로 배포합니다."
echo "버전은 main 머지 시점에 자동으로 확정됩니다."
echo ""
echo "### Changes"
if [ -f /tmp/release-changelog.txt ]; then
cat /tmp/release-changelog.txt
fi
} > /tmp/release-pr-body.txt
- name: Update existing PR
if: steps.check.outputs.existing_pr != ''
run: |
gh pr edit ${{ steps.check.outputs.existing_pr }} \
--title "release: develop → main" \
--body-file /tmp/release-pr-body.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create release PR
id: create
if: steps.check.outputs.existing_pr == ''
run: |
PR_URL=$(gh pr create \
--base main \
--head develop \
--title "release: develop → main" \
--body-file /tmp/release-pr-body.txt \
--label release)
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add reviewers
if: steps.create.outputs.pr_number != ''
run: |
gh api repos/${{ github.repository }}/pulls/${{ steps.create.outputs.pr_number }}/requested_reviewers \
--method POST \
-f "reviewers[]=Junhyukkkk" -f "reviewers[]=KII1ua" -f "reviewers[]=tlarbals824" || echo "Failed to add reviewers"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}