-
Notifications
You must be signed in to change notification settings - Fork 104
164 lines (141 loc) · 6.73 KB
/
sync-react-samples.yml
File metadata and controls
164 lines (141 loc) · 6.73 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Syncs React sample packages from npm into samples/:
# - @salesforce/ui-bundle-template-app-react-sample-b2e
# - @salesforce/ui-bundle-template-app-react-sample-b2x
#
# Opens a single PR when either (or both) npm package versions have changed.
# Same steps as running locally: npm install && npm run sync-react-b2e-sample
# and npm run sync-react-b2x-sample.
#
# Uses IDEE_GH_TOKEN (bot) for checkout and PR creation; same pattern as
# salesforcedx-vscode-einstein-gpt/.github/workflows/build.yml
name: Sync React samples from npm
on:
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.IDEE_GH_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: npm
# ── B2E version check ──────────────────────────────────────────
- name: Get latest B2E npm version
id: npm-version-b2e
run: |
LATEST=$(npm view @salesforce/ui-bundle-template-app-react-sample-b2e version)
if [ -z "$LATEST" ]; then
echo "ERROR: npm view returned empty version for B2E package" >&2
exit 1
fi
echo "latest=$LATEST" >> $GITHUB_OUTPUT
- name: Read current synced B2E version
id: current-version-b2e
run: |
VERSION_FILE="samples/ui-bundle-template-app-react-sample-b2e/.version"
if [ -f "$VERSION_FILE" ]; then
CURRENT=$(cat "$VERSION_FILE" | tr -d '[:space:]')
echo "current=$CURRENT" >> $GITHUB_OUTPUT
else
echo "current=" >> $GITHUB_OUTPUT
fi
# ── B2X version check ──────────────────────────────────────────
- name: Get latest B2X npm version
id: npm-version-b2x
run: |
LATEST=$(npm view @salesforce/ui-bundle-template-app-react-sample-b2x version)
if [ -z "$LATEST" ]; then
echo "ERROR: npm view returned empty version for 2x package" >&2
exit 1
fi
echo "latest=$LATEST" >> $GITHUB_OUTPUT
- name: Read current synced B2X version
id: current-version-b2x
run: |
VERSION_FILE="samples/ui-bundle-template-app-react-sample-b2x/.version"
if [ -f "$VERSION_FILE" ]; then
CURRENT=$(cat "$VERSION_FILE" | tr -d '[:space:]')
echo "current=$CURRENT" >> $GITHUB_OUTPUT
else
echo "current=" >> $GITHUB_OUTPUT
fi
# ── Skip logic ─────────────────────────────────────────────────
- name: Check for version changes
id: skip
run: |
B2E_CHANGED="false"
B2X_CHANGED="false"
if [ "${{ steps.current-version-b2e.outputs.current }}" != "${{ steps.npm-version-b2e.outputs.latest }}" ]; then
B2E_CHANGED="true"
fi
if [ "${{ steps.current-version-b2x.outputs.current }}" != "${{ steps.npm-version-b2x.outputs.latest }}" ]; then
B2X_CHANGED="true"
fi
echo "b2e_changed=$B2E_CHANGED" >> $GITHUB_OUTPUT
echo "b2x_changed=$B2X_CHANGED" >> $GITHUB_OUTPUT
if [ "$B2E_CHANGED" = "false" ] && [ "$B2X_CHANGED" = "false" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "No version changes detected."
else
echo "skip=false" >> $GITHUB_OUTPUT
echo "Changes detected — B2E=$B2E_CHANGED B2X=$B2X_CHANGED"
fi
# ── Install + sync ─────────────────────────────────────────────
- name: Install dependencies
if: steps.skip.outputs.skip != 'true'
run: npm install
- name: Install latest B2E package
if: steps.skip.outputs.skip != 'true' && steps.skip.outputs.b2e_changed == 'true'
run: npm install @salesforce/ui-bundle-template-app-react-sample-b2e@latest
- name: Install latest B2X package
if: steps.skip.outputs.skip != 'true' && steps.skip.outputs.b2x_changed == 'true'
run: npm install @salesforce/ui-bundle-template-app-react-sample-b2x@latest
- name: Sync B2E sample
if: steps.skip.outputs.skip != 'true'
run: npm run sync-react-b2e-sample
- name: Sync B2X sample
if: steps.skip.outputs.skip != 'true'
run: npm run sync-react-b2x-sample
# ── PR creation ────────────────────────────────────────────────
- name: Build PR metadata
if: steps.skip.outputs.skip != 'true'
id: pr-meta
run: |
BODY=""
if [ "${{ steps.skip.outputs.b2e_changed }}" = "true" ]; then
BODY="${BODY}- **B2E** \`@salesforce/ui-bundle-template-app-react-sample-b2e\`: ${{ steps.current-version-b2e.outputs.current || 'none' }} → ${{ steps.npm-version-b2e.outputs.latest }}"$'\n'
fi
if [ "${{ steps.skip.outputs.b2x_changed }}" = "true" ]; then
BODY="${BODY}- **B2X** \`@salesforce/ui-bundle-template-app-react-sample-b2x\`: ${{ steps.current-version-b2x.outputs.current || 'none' }} → ${{ steps.npm-version-b2x.outputs.latest }}"$'\n'
fi
echo "branch=chore/sync-react-samples" >> $GITHUB_OUTPUT
# Multi-line body via heredoc
{
echo "body<<EOFBODY"
echo "Synced React sample packages into \`samples/\`."
echo ""
echo "${BODY}"
echo "Same flow as running locally: \`npm install\` then the sync scripts."
echo "Below line is used in automated scripts to avoid internal SF validation on this PR"
echo "[skip-validate-pr]"
echo "EOFBODY"
} >> $GITHUB_OUTPUT
echo "title=chore: sync React samples from npm" >> $GITHUB_OUTPUT
- name: Create PR on version change
if: steps.skip.outputs.skip != 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.IDEE_GH_TOKEN }}
branch: ${{ steps.pr-meta.outputs.branch }}
base: main
title: ${{ steps.pr-meta.outputs.title }}
body: ${{ steps.pr-meta.outputs.body }}
commit-message: ${{ steps.pr-meta.outputs.title }}
committer: svc-idee-bot <svc_idee_bot@salesforce.com>
author: svc-idee-bot <svc_idee_bot@salesforce.com>