-
Notifications
You must be signed in to change notification settings - Fork 3
145 lines (126 loc) · 4.25 KB
/
Copy pathrelease.yml
File metadata and controls
145 lines (126 loc) · 4.25 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Promote Main to Release Branches
permissions:
contents: write
on:
workflow_dispatch:
inputs:
target:
description: "Promote target (both keeps the legacy web+admin selection)"
required: true
default: "both"
type: choice
options:
- all
- both
- web
- admin
- university
force_redeploy:
description: "When up to date, skip divergence and print manual redeploy guidance"
required: true
default: false
type: boolean
jobs:
generate_tag:
name: Generate HeadVer Tag
uses: ./.github/workflows/headver-tagging.yml
with: {}
create_release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: generate_tag
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create Release
uses: ncipollo/release-action@v1
with:
tag: "v${{ needs.generate_tag.outputs.version }}"
release_name: "Release v${{ needs.generate_tag.outputs.version }}"
body: "Automated release created for build v${{ needs.generate_tag.outputs.version }}"
token: ${{ secrets.GITHUB_TOKEN }}
promote_release_branch:
name: Promote main -> release branch(es)
runs-on: ubuntu-latest
needs: create_release
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Promote main branch to selected release branch(es)
run: |
set -euo pipefail
git fetch origin main
MAIN_SHA=$(git rev-parse origin/main)
TARGET="${{ github.event.inputs.target }}"
FORCE_REDEPLOY="${{ github.event.inputs.force_redeploy }}"
case "$TARGET" in
web)
RELEASE_BRANCHES="release-web"
;;
admin)
RELEASE_BRANCHES="release-admin"
;;
university)
RELEASE_BRANCHES="release-university"
;;
all)
RELEASE_BRANCHES="release-web release-admin release-university"
;;
both)
RELEASE_BRANCHES="release-web release-admin"
;;
*)
echo "Unsupported target: $TARGET" >&2
exit 1
;;
esac
{
echo "## Release Promotion"
echo "- Selected target: $TARGET"
echo "- Promoted main SHA: $MAIN_SHA"
} >> "$GITHUB_STEP_SUMMARY"
for BRANCH in $RELEASE_BRANCHES; do
git fetch origin "$BRANCH" || true
if git show-ref --verify --quiet "refs/remotes/origin/$BRANCH"; then
RELEASE_SHA=$(git rev-parse "origin/$BRANCH")
else
RELEASE_SHA=""
fi
if [ -z "$RELEASE_SHA" ]; then
git push origin origin/main:"refs/heads/$BRANCH"
{
echo "- $BRANCH: created from main"
} >> "$GITHUB_STEP_SUMMARY"
continue
fi
if [ "$MAIN_SHA" = "$RELEASE_SHA" ]; then
if [ "$FORCE_REDEPLOY" = "true" ]; then
{
echo "- $BRANCH: already up to date"
echo " - force_redeploy=true requested"
echo " - skipped empty commit to keep release branch ancestry clean"
echo " - trigger redeploy manually in Vercel if needed"
} >> "$GITHUB_STEP_SUMMARY"
continue
fi
{
echo "- $BRANCH: already up to date"
} >> "$GITHUB_STEP_SUMMARY"
continue
fi
if ! git merge-base --is-ancestor "origin/$BRANCH" origin/main; then
{
echo "- $BRANCH: non-ancestor detected, forcing reset to main"
} >> "$GITHUB_STEP_SUMMARY"
fi
git push --force-with-lease origin origin/main:"refs/heads/$BRANCH"
{
echo "- $BRANCH: updated"
} >> "$GITHUB_STEP_SUMMARY"
done
{
echo "- Note: Vercel production deploy is triggered by corresponding release branch update"
} >> "$GITHUB_STEP_SUMMARY"