Skip to content

Commit 1604d19

Browse files
committed
fix: graceful handling when DEMO_REPO_PAT secret is not configured
1 parent 51686c4 commit 1604d19

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

.github/workflows/sync-demo-template.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,32 @@ jobs:
2424
runs-on: ubuntu-latest
2525
permissions:
2626
contents: read
27+
outputs:
28+
secret_configured: ${{ steps.check-secret.outputs.configured }}
2729

2830
steps:
31+
- name: Check for required secret
32+
id: check-secret
33+
env:
34+
DEMO_REPO_PAT: ${{ secrets.DEMO_REPO_PAT }}
35+
run: |
36+
if [ -z "$DEMO_REPO_PAT" ]; then
37+
echo "::warning::DEMO_REPO_PAT secret is not configured. Skipping sync to target repository."
38+
echo "To enable syncing, add a DEMO_REPO_PAT secret with a GitHub PAT that has access to ${{ env.TARGET_REPO }}"
39+
echo "configured=false" >> $GITHUB_OUTPUT
40+
exit 0
41+
fi
42+
echo "configured=true" >> $GITHUB_OUTPUT
43+
echo "secret_configured=true" >> $GITHUB_ENV
44+
2945
- name: Checkout source repository
46+
if: env.secret_configured == 'true'
3047
uses: actions/checkout@v4
3148
with:
3249
path: source
3350

3451
- name: Validate source files exist
52+
if: env.secret_configured == 'true'
3553
run: |
3654
echo "Validating source demo directory exists..."
3755
if [ ! -d "source/${{ env.DEMO_SOURCE_PATH }}" ]; then
@@ -43,6 +61,7 @@ jobs:
4361
ls -la "source/${{ env.DEMO_SOURCE_PATH }}"
4462
4563
- name: Validate required files
64+
if: env.secret_configured == 'true'
4665
run: |
4766
DEMO_PATH="source/${{ env.DEMO_SOURCE_PATH }}"
4867
MISSING_FILES=""
@@ -70,6 +89,7 @@ jobs:
7089
echo "All required files present!"
7190
7291
- name: Checkout target repository
92+
if: env.secret_configured == 'true'
7393
uses: actions/checkout@v4
7494
with:
7595
repository: ${{ env.TARGET_REPO }}
@@ -78,6 +98,7 @@ jobs:
7898
fetch-depth: 0
7999

80100
- name: Sync demo files to target
101+
if: env.secret_configured == 'true'
81102
run: |
82103
DEMO_PATH="source/${{ env.DEMO_SOURCE_PATH }}"
83104
@@ -104,6 +125,7 @@ jobs:
104125
fi
105126
106127
- name: Check for changes
128+
if: env.secret_configured == 'true'
107129
id: changes
108130
working-directory: target
109131
run: |
@@ -118,7 +140,7 @@ jobs:
118140
fi
119141
120142
- name: Commit and push changes
121-
if: steps.changes.outputs.has_changes == 'true' && (github.event.inputs.dry_run != 'true')
143+
if: env.secret_configured == 'true' && steps.changes.outputs.has_changes == 'true' && (github.event.inputs.dry_run != 'true')
122144
working-directory: target
123145
run: |
124146
git config user.name "github-actions[bot]"
@@ -137,7 +159,7 @@ jobs:
137159
echo "✓ Changes pushed to ${{ env.TARGET_REPO }}"
138160
139161
- name: Dry run summary
140-
if: github.event.inputs.dry_run == 'true'
162+
if: env.secret_configured == 'true' && github.event.inputs.dry_run == 'true'
141163
run: |
142164
echo "DRY RUN: Changes were not pushed"
143165
echo "The following changes would have been made:"
@@ -148,7 +170,7 @@ jobs:
148170
name: Smoke Test Demo
149171
runs-on: ubuntu-latest
150172
needs: sync
151-
if: always() && needs.sync.result == 'success'
173+
if: always() && needs.sync.result == 'success' && needs.sync.outputs.secret_configured == 'true'
152174

153175
steps:
154176
- name: Checkout synced demo repository

0 commit comments

Comments
 (0)