generated from StaticJsCMS/static-cms-next-vercel-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Github action for pushing to main from cms
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Auto Merge CMS Branch | ||
|
||
on: | ||
schedule: | ||
# Run every 5 minutes to check for inactivity | ||
- cron: '*/5 * * * *' | ||
|
||
# Allow manual triggering | ||
workflow_dispatch: | ||
|
||
jobs: | ||
auto-merge: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Fetch all history for all branches | ||
|
||
- name: Check CMS branch and merge if inactive | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
if git fetch origin cms; then | ||
last_commit_time=$(git log -1 --format=%ct "origin/cms") | ||
current_time=$(date +%s) | ||
time_diff=$(( ($current_time - $last_commit_time) / 60 )) | ||
if [ $time_diff -gt 20 ]; then | ||
echo "CMS branch has been inactive for $time_diff minutes" | ||
git config user.name "GitHub Actions Bot" | ||
git config user.email "[email protected]" | ||
git checkout cms | ||
if git merge origin/main --no-edit; then | ||
echo "Successfully merged main into cms" | ||
git checkout main | ||
git merge cms --no-edit | ||
git push origin main | ||
echo "Successfully merged cms into main" | ||
else | ||
echo "Merge conflicts detected in cms branch, skipping..." | ||
git merge --abort | ||
fi | ||
else | ||
echo "CMS branch has been active within the last 20 minutes, skipping..." | ||
fi | ||
else | ||
echo "CMS branch not found" | ||
fi | ||
permissions: | ||
contents: write | ||
pull-requests: write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters