Skip to content

Commit f5aad49

Browse files
authored
ci: template bump workflow (#9733)
This create a workflow that will trigger upon every release and do the following: - Re-generate all template lockfiles as needed (only blank and website need them for payload cloud) - Re-generate all postgres migrations for any pg-based template - Commit changes - Create PR
1 parent 32f0f34 commit f5aad49

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

Diff for: .github/workflows/post-release-templates.yml

+14-23
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
name: post-release-templates
22

33
on:
4-
# release:
5-
# types:
6-
# - published
4+
release:
5+
types:
6+
- published
77
workflow_dispatch:
88
inputs:
99
tag:
1010
description: 'Release tag to process (optional)'
1111
required: true
12-
# default: ''
1312

1413
env:
1514
NODE_VERSION: 22.6.0
@@ -23,6 +22,10 @@ jobs:
2322
permissions:
2423
contents: write
2524
pull-requests: write
25+
env:
26+
POSTGRES_USER: postgres
27+
POSTGRES_PASSWORD: postgres
28+
POSTGRES_DB: payloadtests
2629
steps:
2730
- name: Checkout
2831
uses: actions/checkout@v4
@@ -48,6 +51,7 @@ jobs:
4851
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "CREATE ROLE runner SUPERUSER LOGIN;"
4952
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "SELECT version();"
5053
echo "POSTGRES_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" >> $GITHUB_ENV
54+
echo "DATABASE_URI=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" >> $GITHUB_ENV
5155
5256
- name: Start MongoDB
5357
uses: supercharge/[email protected]
@@ -76,33 +80,20 @@ jobs:
7680
set -ex
7781
git config --global user.name "github-actions[bot]"
7882
git config --global user.email "github-actions[bot]@users.noreply.github.com"
79-
export BRANCH_NAME=chore/templates-${{ steps.determine_tag.outputs.release_tag }}
80-
git checkout -b $BRANCH_NAME
81-
git add -A
8283
83-
# If no files have changed, exit early with success
84-
git diff --cached --quiet --exit-code && exit 0
84+
git diff --name-only
8585
86-
git commit -m "chore(templates): bump lockfiles after ${{ steps.determine_tag.outputs.release_tag }}"
87-
git push origin $BRANCH_NAME
88-
echo "committed=true" >> "$GITHUB_OUTPUT"
86+
export BRANCH_NAME=templates/bump-${{ steps.determine_tag.outputs.release_tag }}
8987
echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
9088
91-
- name: Debug Branches
92-
run: |
93-
echo "Target Commitish: ${{ github.event.release.target_commitish }}"
94-
echo "Branch: ${{ steps.commit.outputs.branch }}"
95-
echo "Ref: ${{ github.ref }}"
96-
9789
- name: Create pull request
9890
uses: peter-evans/create-pull-request@v7
99-
if: steps.commit.outputs.committed == 'true'
10091
with:
10192
token: ${{ secrets.GITHUB_TOKEN }}
10293
labels: 'area: templates'
10394
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
104-
commit-message: 'Automated update after release'
95+
commit-message: 'templates: bump templates for ${{ steps.determine_tag.outputs.release_tag }}'
10596
branch: ${{ steps.commit.outputs.branch }}
106-
base: ${{ github.event_name != 'workflow_dispatch' && github.event.release.target_commitish || github.ref }}
107-
title: 'chore(templates): bump lockfiles after ${{ steps.determine_tag.outputs.release_tag }}'
108-
body: 'Automated bump of template lockfiles after release ${{ steps.determine_tag.outputs.release_tag }}'
97+
base: main
98+
title: 'templates: bump for ${{ steps.determine_tag.outputs.release_tag }}'
99+
body: 'Automated bump of templates for ${{ steps.determine_tag.outputs.release_tag }}'

Diff for: scripts/generate-template-variations.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ async function main() {
129129
name: 'blank',
130130
dirname: 'blank',
131131
db: 'mongodb',
132+
generateLockfile: true,
132133
storage: 'localDisk',
133134
sharp: true,
134135
// The blank template is used as a base for create-payload-app functionality,
@@ -187,6 +188,7 @@ async function main() {
187188
await writeEnvExample({
188189
destDir,
189190
envNames,
191+
dbType: db,
190192
})
191193
}
192194

@@ -234,7 +236,7 @@ async function main() {
234236
...process.env,
235237
PAYLOAD_SECRET: 'asecretsolongnotevensantacouldguessit',
236238
BLOB_READ_WRITE_TOKEN: 'vercel_blob_rw_TEST_asdf',
237-
DATABASE_URI: 'postgres://localhost:5432/payloadtests',
239+
DATABASE_URI: process.env.POSTGRES_URL || 'postgres://localhost:5432/payloadtests',
238240
},
239241
})
240242
}
@@ -287,22 +289,35 @@ ${description}
287289
async function writeEnvExample({
288290
destDir,
289291
envNames,
292+
dbType,
290293
}: {
291294
destDir: string
292295
envNames?: TemplateVariations['envNames']
296+
dbType: DbType
293297
}) {
294298
const envExamplePath = path.join(destDir, '.env.example')
295299
const envFileContents = await fs.readFile(envExamplePath, 'utf8')
300+
296301
const fileContents = envFileContents
297302
.split('\n')
298303
.filter((e) => e)
299-
.map((l) =>
300-
envNames?.dbUri && l.startsWith('DATABASE_URI')
301-
? l.replace('DATABASE_URI', envNames.dbUri)
302-
: l,
303-
)
304+
.map((l) => {
305+
if (l.startsWith('DATABASE_URI')) {
306+
// Use db-appropriate connection string
307+
if (dbType.includes('postgres')) {
308+
l = 'DATABASE_URI=postgresql://127.0.0.1:5432/payloadtests'
309+
}
310+
311+
// Replace DATABASE_URI with the correct env name if set
312+
if (envNames?.dbUri) {
313+
l = l.replace('DATABASE_URI', envNames.dbUri)
314+
}
315+
}
316+
return l
317+
})
304318
.join('\n')
305319

320+
console.log(`Writing to ${envExamplePath}`)
306321
await fs.writeFile(envExamplePath, fileContents)
307322
}
308323

0 commit comments

Comments
 (0)