1- name : Build Random Rants +
1+ name : Build and Deploy
22
33on :
4+ # Trigger for the 'deploy_immediate' job
45 push :
56 branches : [ "main" ]
6- pull_request :
7- branches : [ "main" ]
7+
8+ # Trigger for the 'deploy_weekly' job
9+ schedule :
10+ - cron : ' 0 3 * * 0' # 3:00 AM UTC on Sunday
11+
12+ # Allows manual triggering (will run the 'deploy_weekly' logic)
13+ workflow_dispatch :
814
915permissions :
1016 contents : write
1117
1218jobs :
13- build :
19+ # ----------------------------------------------------
20+ # JOB 1: Deploys immediately on every push to main
21+ # ----------------------------------------------------
22+ deploy_immediate :
23+ name : 🚀 Deploy to 'deploy' (Immediate)
24+ # This 'if' condition is key: only run this job for 'push' events
25+ if : github.event_name == 'push'
1426 runs-on : ubuntu-latest
1527 permissions :
1628 contents : write
17-
1829 strategy :
1930 matrix :
2031 node-version : [16.x]
@@ -33,12 +44,85 @@ jobs:
3344 npm install
3445 npm run build
3546
36- - name : Commit and Push to Deploy Branch 🚀
47+ - name : Commit and Push to 'deploy' branch 🚀
3748 run : |
3849 git config --global user.name 'github-actions[bot]'
3950 git config --global user.email 'github-actions[bot]@users.noreply.github.com'
4051 git checkout -B deploy
4152 git add .
4253 git add -f public
43- git commit -m "${{ github.sha }} [Run webpack for commit ]" || echo "No changes to commit"
54+ git commit -m "${{ github.sha }} [Immediate Deploy ]" || echo "No changes to commit"
4455 git push -f origin deploy
56+
57+ # ----------------------------------------------------
58+ # JOB 2: Deploys weekly, only if new commits exist
59+ # ----------------------------------------------------
60+ deploy_weekly :
61+ name : 📅 Deploy to 'deploy-weekly' (Weekly)
62+ # This 'if' condition is key: only run for 'schedule' or 'workflow_dispatch'
63+ if : github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
64+ runs-on : ubuntu-latest
65+ permissions :
66+ contents : write
67+ strategy :
68+ matrix :
69+ node-version : [16.x]
70+
71+ steps :
72+ - name : Checkout main branch 🛎️
73+ uses : actions/checkout@v4
74+ with :
75+ # Fetch all history to compare main and deploy-weekly
76+ fetch-depth : 0
77+
78+ - name : Check for new commits vs. 'deploy-weekly' 🧐
79+ id : check_commits
80+ run : |
81+ echo "Checking for new commits..."
82+ MAIN_SHA=$(git rev-parse main)
83+
84+ # Check if origin/deploy-weekly branch exists
85+ if git rev-parse --verify origin/deploy-weekly >/dev/null 2>&1; then
86+ # Get the last commit message from the 'deploy-weekly' branch
87+ DEPLOY_MSG=$(git log origin/deploy-weekly -1 --pretty=%B)
88+ # Extract the SHA (which is the first "word" of the message)
89+ LAST_DEPLOY_SHA=$(echo "$DEPLOY_MSG" | awk '{print $1}')
90+
91+ echo "Latest main SHA: $MAIN_SHA"
92+ echo "Last deployed SHA (from deploy-weekly): $LAST_DEPLOY_SHA"
93+
94+ if [ "$MAIN_SHA" == "$LAST_DEPLOY_SHA" ]; then
95+ echo "No new commits on main since last weekly deploy. Skipping build."
96+ echo "needs_build=false" >> $GITHUB_OUTPUT
97+ else
98+ echo "New commits found. Proceeding with build."
99+ echo "needs_build=true" >> $GITHUB_OUTPUT
100+ fi
101+ else
102+ echo "Deploy-weekly branch not found. Proceeding with first build."
103+ echo "needs_build=true" >> $GITHUB_OUTPUT
104+ fi
105+ shell : bash
106+
107+ - name : Use Node.js ${{ matrix.node-version }} ⚙️
108+ if : steps.check_commits.outputs.needs_build == 'true'
109+ uses : actions/setup-node@v4
110+ with :
111+ node-version : ${{ matrix.node-version }}
112+
113+ - name : Install and Build Frontend 🏗️
114+ if : steps.check_commits.outputs.needs_build == 'true'
115+ run : |
116+ npm install
117+ npm run build
118+
119+ - name : Commit and Push to 'deploy-weekly' branch 🚀
120+ if : steps.check_commits.outputs.needs_build == 'true'
121+ run : |
122+ git config --global user.name 'github-actions[bot]'
123+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
124+ git checkout -B deploy-weekly
125+ git add .
126+ git add -f public
127+ git commit -m "${{ github.sha }} [Weekly Deploy]" || echo "No changes to commit"
128+ git push -f origin deploy-weekly
0 commit comments