diff --git a/.github/workflows/weekly-release-pr.yml b/.github/workflows/weekly-release-pr.yml new file mode 100644 index 00000000..215bc709 --- /dev/null +++ b/.github/workflows/weekly-release-pr.yml @@ -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 < 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 diff --git a/scripts/pr-metadata-check.sh b/scripts/pr-metadata-check.sh index 2bd4e4a6..43310335 100755 --- a/scripts/pr-metadata-check.sh +++ b/scripts/pr-metadata-check.sh @@ -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")