Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/weekly-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Weekly Release PR

on:
schedule:
# 週六 10:00 UTC+8 = 週六 02:00 UTC
- cron: "0 2 * * 6"
workflow_dispatch:

permissions:
contents: read
pull-requests: write
actions: write

jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if develop is ahead of main
id: check
run: |
git fetch origin main develop
COMMITS_AHEAD=$(git rev-list --count origin/main..origin/develop)
echo "commits_ahead=$COMMITS_AHEAD" >> "$GITHUB_OUTPUT"
echo "develop is $COMMITS_AHEAD commits ahead of main"

- name: Skip if nothing to release
if: steps.check.outputs.commits_ahead == '0'
run: echo "develop is up to date with main, skipping."

# 以下 step 全由 if: 條件守衛,不依賴上方 skip step 的 exit 狀態
- name: Check for existing open release PR
if: steps.check.outputs.commits_ahead != '0'
id: existing
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
EXISTING=$(gh pr list --base main --head develop --state open --json number --jq '.[0].number // ""')
echo "existing_pr=$EXISTING" >> "$GITHUB_OUTPUT"
if [ -n "$EXISTING" ]; then
echo "Release PR #$EXISTING already open, skipping."
fi

- name: Create release PR
if: steps.check.outputs.commits_ahead != '0' && steps.existing.outputs.existing_pr == ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DATE=$(TZ=Asia/Taipei date +%Y-%m-%d)
COMMITS_AHEAD=${{ steps.check.outputs.commits_ahead }}
cat > /tmp/release-pr-body.md <<EOF
## Weekly Release — $DATE

Auto-generated by weekly-release-pr workflow.

**Commits ahead:** $COMMITS_AHEAD

## Scope 對齊

- Source of truth: develop release promotion on $DATE.
- Depends on PR: none

Backend contract already in develop:
- [x] yes
- [ ] no

If no, this PR is:
- [ ] stacked on dependency branch
- [ ] intentionally blocked until dependency merges

## 本 PR 明確不做

- 不新增任何程式碼變更,僅將 develop promote 到 main。
- 不修改任何未在 develop 上的內容。

## Checklist

- [ ] CI 通過(CI 由 workflow dispatch 觸發,請到 Actions tab 查看結果,不會顯示在此 PR 的 Checks tab)
- [ ] 確認無 half-finished feature
- [ ] Merge

> Note: weekly-release-pr workflow 的 schedule / workflow_dispatch 需等此 workflow 檔案存在於 default branch(main)後才會啟用。
EOF
gh pr create \
--base main \
--head develop \
--title "[release] develop → main ($DATE)" \
--body-file /tmp/release-pr-body.md

- name: Dispatch CI against develop
if: steps.check.outputs.commits_ahead != '0' && steps.existing.outputs.existing_pr == ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh workflow run ci.yml --ref develop
2 changes: 1 addition & 1 deletion scripts/pr-metadata-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ main() {
fi

local depends_on_raw=""
depends_on_raw=$(grep -iE '^[[:space:]-]*Depends on PR[::][[:space:]]*' "$body_file" | head -n1 | sed -E 's/^[^::]*[::][[:space:]]*//' | sed 's/[[:space:]]*$//')
depends_on_raw=$(grep -iE '^[[:space:]-]*Depends on PR[::][[:space:]]*' "$body_file" | head -n1 | sed -E 's/^[^::]*[::][[:space:]]*//' | sed 's/[[:space:]]*$//' || true)

if [ "$is_infra_or_chore" -eq 0 ] && [ "$is_release_promotion" -eq 0 ]; then
grep -Eq '#[0-9]+' "$body_file" || failures+=("PR body 必須引用至少一個 issue 或 PR 編號,例如 #123")
Expand Down
Loading