Skip to content

Changes from CMS

Changes from CMS #60

name: Create Review Branch for Drafts Review
on:
workflow_dispatch:
inputs:
branch_name:
description: "Name of the branch to create (e.g., review)"
required: true
default: "review"
push:
branches:
- main # This line triggers the workflow whenever anything is pushed to the 'main' branch
jobs:
create_branch:
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
# For 'push' events, GITHUB_REF will already be 'refs/heads/main',
# but explicitly setting 'ref: main' ensures we're always pulling from main
# regardless of the specific commit that triggered the push.
uses: actions/checkout@v4
with:
ref: "main"
- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "github-actions@github.com"
- name: Determine Branch Name
id: set_branch_name
run: |
# If triggered by workflow_dispatch, use the input.
# Otherwise (triggered by push), default to 'review'.
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "BRANCH_NAME=${{ github.event.inputs.branch_name }}" >> "$GITHUB_OUTPUT"
else
echo "BRANCH_NAME=review" >> "$GITHUB_OUTPUT"
fi
- name: Delete existing review branch (if it exists)
run: |
git push origin --delete ${{ steps.set_branch_name.outputs.BRANCH_NAME }} || true
shell: bash
- name: Create new review branch from main
run: |
git checkout -b ${{ steps.set_branch_name.outputs.BRANCH_NAME }}
git push origin ${{ steps.set_branch_name.outputs.BRANCH_NAME }}
shell: bash
- name: Trigger Netlify Deploy (Optional, Netlify should auto-detect)
run: |
# Only attempt to curl if the environment variable is set.
# Use -s (silent) and -S (show errors) for cleaner output if it fails.
# The 'test -n' checks if the string is non-empty.
if test -n "${{ env.NETLIFY_PREVIEW_BUILD_HOOK }}"; then
echo "Triggering Netlify deploy for preview branch..."
curl -X POST -d '{}' "${{ env.NETLIFY_PREVIEW_BUILD_HOOK }}"
else
echo "NETLIFY_PREVIEW_BUILD_HOOK secret is not set or empty. Skipping Netlify deploy trigger."
fi
env:
NETLIFY_PREVIEW_BUILD_HOOK: ${{ secrets.NETLIFY_PREVIEW_BUILD_HOOK }}
# Removed the 'if' condition on the step itself, handling it inside 'run'