forked from opendatahub-io/models-as-a-service
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (66 loc) · 2.63 KB
/
promote-main-to-stable.yml
File metadata and controls
79 lines (66 loc) · 2.63 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
# Promote Main to Stable Workflow
#
# Creates a promotional PR to sync the stable branch with main.
# Runs automatically every Sunday night (midnight UTC) and can be triggered manually.
#
# This workflow:
# 1. Checks if stable is behind main
# 2. Creates a PR from main -> stable if there are new changes
# 3. Reuses an existing open PR if one already exists
name: Promote Main to Stable
on:
schedule:
- cron: '0 0 * * 0' # Every Sunday at midnight UTC
workflow_dispatch:
permissions:
contents: read
pull-requests: write
env:
GH_USER_NAME: github-actions[bot]
GH_USER_EMAIL: github-actions[bot]@users.noreply.github.com
jobs:
promote:
name: Create Promotion PR
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "${{ env.GH_USER_NAME }}"
git config user.email "${{ env.GH_USER_EMAIL }}"
- name: Promote main to stable
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git fetch origin main stable
DIFF_COUNT=$(git rev-list --count origin/stable..origin/main)
if [ "$DIFF_COUNT" -eq 0 ]; then
echo "stable is already up to date with main. Nothing to promote."
echo "## Promote Main to Stable" >> "$GITHUB_STEP_SUMMARY"
echo "stable is already up to date with main. No PR needed." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
echo "Found $DIFF_COUNT commit(s) to promote from main to stable."
COMMIT_LOG=$(git log --oneline origin/stable..origin/main --no-merges | head -30)
BODY="Automated promotion of **${DIFF_COUNT} commit(s)** from \`main\` to \`stable\`."
BODY="${BODY}"$'\n\n'"\`\`\`"$'\n'"${COMMIT_LOG}"$'\n'"\`\`\`"
EXISTING_PR=$(gh pr list --base stable --head main --state open --json number --jq '.[0].number // empty')
if [ -n "$EXISTING_PR" ]; then
if ! echo "$BODY" | gh pr edit "$EXISTING_PR" --body-file -; then
echo "::error::Failed to update existing promotion PR #${EXISTING_PR}"
exit 1
fi
echo "Updated existing promotion PR #${EXISTING_PR}"
else
if ! echo "$BODY" | gh pr create --base stable --head main \
--title "chore: promote main to stable" \
--body-file -; then
echo "::error::Failed to create promotion PR"
exit 1
fi
echo "Created new promotion PR"
fi