-
Notifications
You must be signed in to change notification settings - Fork 3
65 lines (59 loc) · 2.52 KB
/
Copy pathcreate-review-branch.yml
File metadata and controls
65 lines (59 loc) · 2.52 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
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'