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
This commit is contained in:
Elliot DeNolf
2024-12-03 23:06:32 -05:00
committed by GitHub
parent 32f0f340ac
commit f5aad49ba7
2 changed files with 35 additions and 29 deletions

View File

@@ -1,15 +1,14 @@
name: post-release-templates name: post-release-templates
on: on:
# release: release:
# types: types:
# - published - published
workflow_dispatch: workflow_dispatch:
inputs: inputs:
tag: tag:
description: 'Release tag to process (optional)' description: 'Release tag to process (optional)'
required: true required: true
# default: ''
env: env:
NODE_VERSION: 22.6.0 NODE_VERSION: 22.6.0
@@ -23,6 +22,10 @@ jobs:
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: payloadtests
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -48,6 +51,7 @@ jobs:
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "CREATE ROLE runner SUPERUSER LOGIN;" psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "CREATE ROLE runner SUPERUSER LOGIN;"
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "SELECT version();" psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" -c "SELECT version();"
echo "POSTGRES_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" >> $GITHUB_ENV echo "POSTGRES_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" >> $GITHUB_ENV
echo "DATABASE_URI=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB" >> $GITHUB_ENV
- name: Start MongoDB - name: Start MongoDB
uses: supercharge/mongodb-github-action@1.11.0 uses: supercharge/mongodb-github-action@1.11.0
@@ -76,33 +80,20 @@ jobs:
set -ex set -ex
git config --global user.name "github-actions[bot]" git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.email "github-actions[bot]@users.noreply.github.com"
export BRANCH_NAME=chore/templates-${{ steps.determine_tag.outputs.release_tag }}
git checkout -b $BRANCH_NAME
git add -A
# If no files have changed, exit early with success git diff --name-only
git diff --cached --quiet --exit-code && exit 0
git commit -m "chore(templates): bump lockfiles after ${{ steps.determine_tag.outputs.release_tag }}" export BRANCH_NAME=templates/bump-${{ steps.determine_tag.outputs.release_tag }}
git push origin $BRANCH_NAME
echo "committed=true" >> "$GITHUB_OUTPUT"
echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT" echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
- name: Debug Branches
run: |
echo "Target Commitish: ${{ github.event.release.target_commitish }}"
echo "Branch: ${{ steps.commit.outputs.branch }}"
echo "Ref: ${{ github.ref }}"
- name: Create pull request - name: Create pull request
uses: peter-evans/create-pull-request@v7 uses: peter-evans/create-pull-request@v7
if: steps.commit.outputs.committed == 'true'
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
labels: 'area: templates' labels: 'area: templates'
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
commit-message: 'Automated update after release' commit-message: 'templates: bump templates for ${{ steps.determine_tag.outputs.release_tag }}'
branch: ${{ steps.commit.outputs.branch }} branch: ${{ steps.commit.outputs.branch }}
base: ${{ github.event_name != 'workflow_dispatch' && github.event.release.target_commitish || github.ref }} base: main
title: 'chore(templates): bump lockfiles after ${{ steps.determine_tag.outputs.release_tag }}' title: 'templates: bump for ${{ steps.determine_tag.outputs.release_tag }}'
body: 'Automated bump of template lockfiles after release ${{ steps.determine_tag.outputs.release_tag }}' body: 'Automated bump of templates for ${{ steps.determine_tag.outputs.release_tag }}'

View File

@@ -129,6 +129,7 @@ async function main() {
name: 'blank', name: 'blank',
dirname: 'blank', dirname: 'blank',
db: 'mongodb', db: 'mongodb',
generateLockfile: true,
storage: 'localDisk', storage: 'localDisk',
sharp: true, sharp: true,
// The blank template is used as a base for create-payload-app functionality, // The blank template is used as a base for create-payload-app functionality,
@@ -187,6 +188,7 @@ async function main() {
await writeEnvExample({ await writeEnvExample({
destDir, destDir,
envNames, envNames,
dbType: db,
}) })
} }
@@ -234,7 +236,7 @@ async function main() {
...process.env, ...process.env,
PAYLOAD_SECRET: 'asecretsolongnotevensantacouldguessit', PAYLOAD_SECRET: 'asecretsolongnotevensantacouldguessit',
BLOB_READ_WRITE_TOKEN: 'vercel_blob_rw_TEST_asdf', BLOB_READ_WRITE_TOKEN: 'vercel_blob_rw_TEST_asdf',
DATABASE_URI: 'postgres://localhost:5432/payloadtests', DATABASE_URI: process.env.POSTGRES_URL || 'postgres://localhost:5432/payloadtests',
}, },
}) })
} }
@@ -287,22 +289,35 @@ ${description}
async function writeEnvExample({ async function writeEnvExample({
destDir, destDir,
envNames, envNames,
dbType,
}: { }: {
destDir: string destDir: string
envNames?: TemplateVariations['envNames'] envNames?: TemplateVariations['envNames']
dbType: DbType
}) { }) {
const envExamplePath = path.join(destDir, '.env.example') const envExamplePath = path.join(destDir, '.env.example')
const envFileContents = await fs.readFile(envExamplePath, 'utf8') const envFileContents = await fs.readFile(envExamplePath, 'utf8')
const fileContents = envFileContents const fileContents = envFileContents
.split('\n') .split('\n')
.filter((e) => e) .filter((e) => e)
.map((l) => .map((l) => {
envNames?.dbUri && l.startsWith('DATABASE_URI') if (l.startsWith('DATABASE_URI')) {
? l.replace('DATABASE_URI', envNames.dbUri) // Use db-appropriate connection string
: l, if (dbType.includes('postgres')) {
) l = 'DATABASE_URI=postgresql://127.0.0.1:5432/payloadtests'
}
// Replace DATABASE_URI with the correct env name if set
if (envNames?.dbUri) {
l = l.replace('DATABASE_URI', envNames.dbUri)
}
}
return l
})
.join('\n') .join('\n')
console.log(`Writing to ${envExamplePath}`)
await fs.writeFile(envExamplePath, fileContents) await fs.writeFile(envExamplePath, fileContents)
} }