-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
387 lines (329 loc) · 15.4 KB
/
action.yml
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
name: 'Hello World'
description: 'Greet someone'
inputs:
versionNumber:
description: 'Version Number (latest if blank)'
required: false
type: string
token:
description: 'The token to use for github access'
required: true
type: string
default: ${{ github.token }}
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# We have to fetch the full history so that the merge step will understand
# how to properly merge the starter repo with our local changes.
fetch-depth: 0
# We capture the SHA of the most recent commit BEFORE we make any changes.
# We'll use this later to generate some instructions for how to revert any
# change made by this workflow.
- name: Capture starting commit SHA
id: capture-starting-commit
shell: bash
run: |
echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
# TODO: It would be nice to be able to set this to be the username & email of the user who
# triggered this action. Unfortuately GitHub doesn't make the email address available.
- name: Set git config
shell: bash
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
# We set this so that any merge conflicts will show a diff in this format:
# <<<<<<< HEAD
# changed content in the downstream repo
# ||||||| the-sha-of-the-shared-common-ancestor-commit
# original content of the shared common ancestor
# =======
# changed content in the starter repo
# >>>>>>> bullet-train-update/1.x.x
git config --global merge.conflictstyle diff3
- name: Setup Ruby
uses: "ruby/setup-ruby@v1"
with:
bundler-cache: true
- name: Detect package manager
id: detect-package-manager
shell: bash
run: |
node -p "'PACKAGE_MANAGER='+require('./package.json').packageManager?.split?.('@')?.[0]" >> "$GITHUB_OUTPUT"
- name: Install package manager
shell: bash
if: ${{ steps.detect-package-manager.outputs.PACKAGE_MANAGER != '' && steps.detect-package-manager.outputs.PACKAGE_MANAGER != 'undefined'}}
run: |
corepack enable ${{ steps.detect-package-manager.outputs.PACKAGE_MANAGER }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
#cache: ${{ steps.detect-package-manager.outputs.PACKAGE_MANAGER != '' && steps.detect-package-manager.outputs.PACKAGE_MANAGER != 'undefined' && steps.detect-package-manager.outputs.PACKAGE_MANAGER || 'yarn' }}
#cache-dependency-path: yarn.lock
- name: Fetch Bullet Train Starter Repo
shell: bash
run: |
git remote add bullet-train https://github.com/bullet-train-co/bullet_train.git
git fetch --tags bullet-train
# This step is run when a version was passed in
- name: Target the passed in version
shell: bash
run: |
echo "TARGET_VERSION=${{ inputs.versionNumber }}" >> "$GITHUB_ENV"
if: inputs.versionNumber != ''
# This step is run if a version was not passed in
- name: Target the latest version
shell: bash
run: |
echo "TARGET_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))" >> "$GITHUB_ENV"
if: inputs.versionNumber == ''
# Allow for versions to be pass in either with or without the leading 'v'
- name: Strip leading 'v'
shell: bash
run: |
echo "TARGET_VERSION=$(echo $TARGET_VERSION | sed 's/v//g')" >> "$GITHUB_ENV"
if: startsWith(env.TARGET_VERSION, 'v')
- name: Check for version
id: version-check
shell: bash
run: |
echo "TAG=$(git tag -l v${{ env.TARGET_VERSION }})" >> $GITHUB_OUTPUT
- name: Verify version exists
if: ${{ steps.version-check.outputs.TAG == '' }}
shell: bash
run: |
echo >&2 "::error:: Version v${{ env.TARGET_VERSION }} not found in bullet-train repo."
exit 1
- name: Merge version tag
# If there's a merge conflict it exits with an error code and would cause the workflow to fail,
# but we don't want that. We want to continue and we'll mark the PR as containing a conflict.
continue-on-error: true
shell: bash
run: git merge v${{ env.TARGET_VERSION }}
####################################################################################################
#
# De-conflicting Gemfile.lock
#
####################################################################################################
- name: Check for conflicts in Gemfile.lock
id: gemfile-lock-conflicts
shell: bash
run: |
echo "GEMFILE_LOCK_CONFLICT=$(git status --porcelain Gemfile.lock | grep '^UU')" >> $GITHUB_OUTPUT
# Gemfile.lock is often a source of conflicts, and it's hard to sort out by hand.
# Since it's an auto-generated file we can just use whatever is in the downstreadm app
# and then run `bundle install` to ensure that it's in sync with Gemfile
- name: Fix Gemfile.lock - Part 1
shell: bash
if: ${{ steps.gemfile-lock-conflicts.outputs.GEMFILE_LOCK_CONFLICT != '' }}
run: |
git checkout HEAD -- Gemfile.lock
# We have to do this so that a subsequent `bundle install` will work without complaining
# that we have changed Gemfile.lock in a deployment context.
bundle config unset deployment
# After merging the latest changes from the start repo the ruby version might have changed. We
# run setup-ruby again to ensure that we have the right version.
- name: Setup Ruby - Redux
continue-on-error: true # It will complain about the lock file being out of date, but we don't want to stop here
uses: "ruby/setup-ruby@v1"
if: ${{ steps.gemfile-lock-conflicts.outputs.GEMFILE_LOCK_CONFLICT != '' }}
with:
bundler-cache: true
# Now Gemfile.lock should be de-conflicted
- name: Fix Gemfile.lock - Part 2
shell: bash
if: ${{ steps.gemfile-lock-conflicts.outputs.GEMFILE_LOCK_CONFLICT != '' }}
run: |
bundle config unset deployment
bundle install
# Now we add the changes
git add Gemfile.lock
####################################################################################################
#
# De-conflicting yarn.lock
#
####################################################################################################
- name: Check for conflicts in package.json
id: package-json-conflicts
shell: bash
run: |
echo "PACKAGE_JSON_CONFLICT=$(git status --porcelain package.json | grep '^UU')" >> $GITHUB_OUTPUT
- name: Check for conflicts in yarn.lock
id: yarn-lock-conflicts
shell: bash
if: ${{ steps.package-json-conflicts.outputs.PACKAGE_JSON_CONFLICT == '' }}
run: |
echo "YARN_LOCK_CONFLICT=$(git status --porcelain yarn.lock | grep '^UU')" >> $GITHUB_OUTPUT
# yarn.lock is often a source of conflicts, and it's hard to sort out by hand.
# Since it's an auto-generated file we can just use whatever is in the downstreadm app
# and then run `bundle install` to ensure that it's in sync with yarn
- name: Fix yarn.lock - Part 1
shell: bash
if: ${{ steps.package-json-conflicts.outputs.PACKAGE_JSON_CONFLICT == '' && steps.yarn-lock-conflicts.outputs.YARN_LOCK_CONFLICT != '' }}
run: |
git checkout HEAD -- yarn.lock
- name: Detect package manager
id: detect-package-manager-redux
shell: bash
if: ${{ steps.package-json-conflicts.outputs.PACKAGE_JSON_CONFLICT == '' }}
run: |
node -p "'PACKAGE_MANAGER='+require('./package.json').packageManager?.split?.('@')?.[0]" >> "$GITHUB_OUTPUT"
- name: Install package manager
shell: bash
if: ${{ steps.package-json-conflicts.outputs.PACKAGE_JSON_CONFLICT == '' && steps.detect-package-manager-redux.outputs.PACKAGE_MANAGER != '' && steps.detect-package-manager-redux.outputs.PACKAGE_MANAGER != 'undefined' }}
run: |
corepack enable ${{ steps.detect-package-manager-redux.outputs.PACKAGE_MANAGER }}
# After merging the latest changes from the start repo the node version might have changed. We
# run setup-node again to ensure that we have the right version.
- name: Setup node
#continue-on-error: true # It will complain about the lock file being out of date, but we don't want to stop here
uses: actions/setup-node@v4
if: ${{ steps.package-json-conflicts.outputs.PACKAGE_JSON_CONFLICT == '' }}
with:
node-version-file: .nvmrc
#cache: ${{ steps.detect-package-manager-redux.outputs.PACKAGE_MANAGER != '' && steps.detect-package-manager-redux.outputs.PACKAGE_MANAGER != 'undefined' && steps.detect-package-manager-redux.outputs.PACKAGE_MANAGER || 'yarn' }}
#cache-dependency-path: yarn.lock
# Now yarn.lock should be de-conflicted
- name: Fix yarn.lock - Part 2
shell: bash
if: ${{ steps.package-json-conflicts.outputs.PACKAGE_JSON_CONFLICT == '' && steps.yarn-lock-conflicts.outputs.YARN_LOCK_CONFLICT != '' }}
run: |
yarn install --no-immutable
# Now we add the changes
git add yarn.lock
####################################################################################################
#
# Check for other conflicts
#
####################################################################################################
- name: Check for conflicts
id: conflicts
shell: bash
continue-on-error: true
run: |
{
echo 'CONFLICTED_FILES<<EOF'
git status --porcelain | grep '^[U|A|D][U|A|D]' | sed 's/^[U|A|D][U|A|D]/*/g'
echo EOF
} >> "$GITHUB_ENV"
- name: Inspect conflict output
run: echo "${{ env.CONFLICTED_FILES }}"
shell: bash
# This step is run when there are no conflicts
- name: Set PR conflict message for no conflicts
shell: bash
run: |
{
echo 'PR_CONFLICT_MESSAGE<<EOF'
echo '🎉 There are no conflicts detected in this PR!'
echo EOF
} >> "$GITHUB_ENV"
if: env.CONFLICTED_FILES == ''
# This step is run when there are conflicts that need to be resolved
- name: Set PR conflict message for conflicts
shell: bash
run: |
{
echo 'PR_CONFLICT_MESSAGE<<EOF'
echo '⚠️ **There are conflicts in the following files:**'
echo '${{ env.CONFLICTED_FILES }}'
echo ' '
echo '**You should pull down this branch, resolve the conflicts, and then push the branch.**'
echo ' '
echo 'Get started by pulling the branch:'
echo '```'
echo 'git fetch origin'
echo 'git checkout -b bullet-train-update/${{ env.TARGET_VERSION }} --track origin/bullet-train-update/${{ env.TARGET_VERSION }}'
echo '```'
echo 'Then resolve conflicts. Once you have done that you can commit the changes and then push.'
echo '```'
echo 'git add .'
echo 'git commit -m "resolved conflicts"'
echo 'git push origin bullet-train-update/${{ env.TARGET_VERSION }}'
echo '```'
echo EOF
} >> "$GITHUB_ENV"
if: ${{ env.CONFLICTED_FILES != '' }}
# This step is run when there are no conflicts
- name: Set draft status = false
shell: bash
run: |
echo "DRAFT_STATUS=false" >> "$GITHUB_ENV"
if: env.CONFLICTED_FILES == ''
# This step is run when there are conflicts that need to be resolved
- name: Set draft status = true
shell: bash
run: |
echo "DRAFT_STATUS=true" >> "$GITHUB_ENV"
if: ${{ env.CONFLICTED_FILES != '' }}
# This is an artifact of installing the gems, and we don't want to add it to the PR.
- name: Remove vendor/bundle
run: rm -rf vendor/bundle
shell: bash
# This is an artifact of installing npm packages, and we don't want to add it to the PR.
# TODO: Maybe we don't need to do this. We have .yarn/cache in .gitignore, so it should
# be ignored by default.
#- name: Remove .yarn/cache
#run: rm -rf .yarn/cache
#shell: bash
- name: Add conflicted files
if: ${{ env.CONFLICTED_FILES != '' }}
run: git add .
shell: bash
- name: Commit changes
if: ${{ env.CONFLICTED_FILES != '' || steps.gemfile-lock-conflicts.outputs.GEMFILE_LOCK_CONFLICT != '' || steps.yarn-lock-conflicts.outputs.YARN_LOCK_CONFLICT != '' }}
run: git commit --no-edit
shell: bash
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
# We use a different token so that the PR that gets created will auto-trigger additional
# workflows. The normal token is prevented from triggering other workflows. If you don't
# have additional workflows that you want to trigger you can comment out this next line.
token: ${{ inputs.token }}
author: "${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
committer: "${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
commit-message: "Bullet Train Update: ${{ env.TARGET_VERSION }}"
branch: "bullet-train-update/${{ env.TARGET_VERSION }}"
delete-branch: true
title: "Bullet Train Update: ${{ env.TARGET_VERSION }}"
add-paths: "."
# If your repo supports Draft PRs you may want to uncomment this next line so that we can
# open the PR as a draft when we detect merge conflicts.
# draft: ${{ env.DRAFT_STATUS }}
body: |
Update of the Bullet Train Starter Repo to version `${{ env.TARGET_VERSION }}`
**Please note:** You should thorougly review this PR.
${{env.PR_CONFLICT_MESSAGE}}
#### Rejecting portions of this PR
The SHA of the commit that this PR was started from is: **${{steps.capture-starting-commit.outputs.SHA}}**
If there are changes in some files in this PR that you'd like to reject you can do the following:
First pull down the branch for this PR:
```
git fetch origin
git checkout -b bullet-train-update/${{ env.TARGET_VERSION }} --track origin/bullet-train-update/${{ env.TARGET_VERSION }}
```
Use the SHA of the starting commit to revert all of the changes in a particular file:
```
git checkout ${{steps.capture-starting-commit.outputs.SHA}} -- path/to/file
```
Or use the `-p` option to selectively choose which portions of the file to revert:
```
git checkout -p ${{steps.capture-starting-commit.outputs.SHA}} -- path/to/file
```
You can also just edit any file directly to make whatever changes you want.
After getthing things the way you want them, commit the changes and push the branch:
```
git add .
git commit -m "reject some changes from starter repo"
git push origin bullet-train-update/${{ env.TARGET_VERSION }}
```
#### Release Notes
[Starter Repo ${{ env.TARGET_VERSION }}](https://github.com/bullet-train-co/bullet_train/releases/tag/v${{ env.TARGET_VERSION }})
[`core` Gems ${{ env.TARGET_VERSION }}](https://github.com/bullet-train-co/bullet_train-core/releases/tag/v${{ env.TARGET_VERSION }})
> Auto-generated by `.github/workflows/update-bullet-train.yml`
#labels: |
#core bump