-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (152 loc) · 6.66 KB
/
build_site.yml
File metadata and controls
165 lines (152 loc) · 6.66 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Build and Deploy (3-Tier with Force Push)
on:
push:
branches: ["main"]
schedule:
# Weekly: Sunday at 3:00 AM UTC (for Beta)
- cron: "0 3 * * 0"
# Monthly: 1st of the month at 4:00 AM UTC (for Production)
- cron: "0 4 1 * *"
workflow_dispatch:
permissions:
contents: write
jobs:
#----------------------------------------------------
# JOB 1: DEVELOPMENT (Always runs on push)
#----------------------------------------------------
deploy_dev:
name: 🚀 Deploy to 'deploy-dev' (Dev)
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 16.x }
- run: |
npm install
npm run build
- name: Commit and Push to 'deploy-dev'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -B deploy-dev
git add .
git add -f public
git commit -m "${{ github.sha }} [Dev Deploy]" || echo "No changes to commit"
git push -f origin deploy-dev
#----------------------------------------------------
# JOB 2: BETA (Runs weekly OR on "Immediate:" push)
#----------------------------------------------------
deploy_beta:
name: spoilers 📅 Deploy to 'deploy-beta' (Beta)
# 1. CHANGED: Now also triggers on 'push' to check the commit message
if: (github.event_name == 'schedule' && github.event.schedule == '0 3 * * 0') || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: Check Beta deploy logic 🧐
id: check_commits
run: |
echo "needs_build=false" >> $GITHUB_OUTPUT # Default to false
COMMIT_MSG="${{ github.event.head_commit.message }}"
# 2. NEW LOGIC: Check for force command first
if echo "$COMMIT_MSG" | grep -qi "^Immediate:"; then
echo "✅ Force deploy triggered by commit message."
echo "needs_build=true" >> $GITHUB_OUTPUT
# 3. OLD LOGIC: Check for schedule
elif [ "${{ github.event_name }}" == "schedule" ]; then
echo "Running on schedule, checking for new commits..."
MAIN_SHA=$(git rev-parse main)
if git rev-parse --verify origin/deploy-beta >/dev/null 2>&1; then
DEPLOY_MSG=$(git log origin/deploy-beta -1 --pretty=%B)
LAST_DEPLOY_SHA=$(echo "$DEPLOY_MSG" | awk '{print $1}')
if [ "$MAIN_SHA" == "$LAST_DEPLOY_SHA" ]; then
echo "No new commits for Beta. Skipping."
else
echo "New commits found for Beta. Building."
echo "needs_build=true" >> $GITHUB_OUTPUT
fi
else
echo "First Beta build. Proceeding."
echo "needs_build=true" >> $GITHUB_OUTPUT
fi
else
echo "Regular push, no force command. Skipping Beta."
fi
shell: bash
- uses: actions/setup-node@v4
if: steps.check_commits.outputs.needs_build == 'true'
with: { node-version: 16.x }
- run: |
npm install
npm run build
if: steps.check_commits.outputs.needs_build == 'true'
- name: Commit and Push to 'deploy-beta'
if: steps.check_commits.outputs.needs_build == 'true'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -B deploy-beta
git add .
git add -f public
git commit -m "${{ github.sha }} [Weekly Beta Deploy]" || echo "No changes to commit"
git push -f origin deploy-beta
#----------------------------------------------------
# JOB 3: PRODUCTION (Runs monthly, on dispatch, OR on "Immediate:" push)
#----------------------------------------------------
deploy_production:
name: 🌍 Deploy to 'deploy-monthly' (Production)
# 4. CHANGED: Also triggers on 'push' to check commit message
if: (github.event_name == 'schedule' && github.event.schedule == '0 4 1 * *') || github.event_name == 'workflow_dispatch' || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: Check Production deploy logic 🧐
id: check_commits
run: |
echo "needs_build=false" >> $GITHUB_OUTPUT # Default to false
COMMIT_MSG="${{ github.event.head_commit.message }}"
# 5. NEW LOGIC: Check for force command first
if echo "$COMMIT_MSG" | grep -qi "^Immediate:"; then
echo "✅ Force deploy triggered by commit message."
echo "needs_build=true" >> $GITHUB_OUTPUT
# 6. OLD LOGIC: Check for schedule or dispatch
elif [ "${{ github.event_name }}" == "schedule" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "Running on schedule/dispatch, checking for new commits..."
MAIN_SHA=$(git rev-parse main)
if git rev-parse --verify origin/deploy-monthly >/dev/null 2>&1; then
DEPLOY_MSG=$(git log origin/deploy-monthly -1 --pretty=%B)
LAST_DEPLOY_SHA=$(echo "$DEPLOY_MSG" | awk '{print $1}')
if [ "$MAIN_SHA" == "$LAST_DEPLOY_SHA" ]; then
echo "No new commits for Production. Skipping."
else
echo "New commits found for Production. Building."
echo "needs_build=true" >> $GITHUB_OUTPUT
fi
else
echo "First Production build. Proceeding."
echo "needs_build=true" >> $GITHUB_OUTPUT
fi
else
echo "Regular push, no force command. Skipping Production."
fi
shell: bash
- uses: actions/setup-node@v4
if: steps.check_commits.outputs.needs_build == 'true'
with: { node-version: 16.x }
- run: |
npm install
npm run build
if: steps.check_commits.outputs.needs_build == 'true'
- name: Commit and Push to 'deploy-monthly'
if: steps.check_commits.outputs.needs_build == 'true'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -B deploy-monthly
git add .
git add -f public
git commit -m "${{ github.sha }} [Monthly Production Deploy]" || echo "No changes to commit"
git push -f origin deploy-monthly