Skip to content

Commit

Permalink
ci: template bump workflow (#9733)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
denolfe authored Dec 4, 2024
1 parent 32f0f34 commit f5aad49
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
37 changes: 14 additions & 23 deletions .github/workflows/post-release-templates.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
name: post-release-templates

on:
# release:
# types:
# - published
release:
types:
- published
workflow_dispatch:
inputs:
tag:
description: 'Release tag to process (optional)'
required: true
# default: ''

env:
NODE_VERSION: 22.6.0
Expand All @@ -23,6 +22,10 @@ jobs:
permissions:
contents: write
pull-requests: write
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: payloadtests
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -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 "SELECT version();"
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
uses: supercharge/[email protected]
Expand Down Expand Up @@ -76,33 +80,20 @@ jobs:
set -ex
git config --global user.name "github-actions[bot]"
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 --cached --quiet --exit-code && exit 0
git diff --name-only
git commit -m "chore(templates): bump lockfiles after ${{ steps.determine_tag.outputs.release_tag }}"
git push origin $BRANCH_NAME
echo "committed=true" >> "$GITHUB_OUTPUT"
export BRANCH_NAME=templates/bump-${{ steps.determine_tag.outputs.release_tag }}
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
uses: peter-evans/create-pull-request@v7
if: steps.commit.outputs.committed == 'true'
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: 'area: templates'
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 }}
base: ${{ github.event_name != 'workflow_dispatch' && github.event.release.target_commitish || github.ref }}
title: 'chore(templates): bump lockfiles after ${{ steps.determine_tag.outputs.release_tag }}'
body: 'Automated bump of template lockfiles after release ${{ steps.determine_tag.outputs.release_tag }}'
base: main
title: 'templates: bump for ${{ steps.determine_tag.outputs.release_tag }}'
body: 'Automated bump of templates for ${{ steps.determine_tag.outputs.release_tag }}'
27 changes: 21 additions & 6 deletions scripts/generate-template-variations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ async function main() {
name: 'blank',
dirname: 'blank',
db: 'mongodb',
generateLockfile: true,
storage: 'localDisk',
sharp: true,
// The blank template is used as a base for create-payload-app functionality,
Expand Down Expand Up @@ -187,6 +188,7 @@ async function main() {
await writeEnvExample({
destDir,
envNames,
dbType: db,
})
}

Expand Down Expand Up @@ -234,7 +236,7 @@ async function main() {
...process.env,
PAYLOAD_SECRET: 'asecretsolongnotevensantacouldguessit',
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',
},
})
}
Expand Down Expand Up @@ -287,22 +289,35 @@ ${description}
async function writeEnvExample({
destDir,
envNames,
dbType,
}: {
destDir: string
envNames?: TemplateVariations['envNames']
dbType: DbType
}) {
const envExamplePath = path.join(destDir, '.env.example')
const envFileContents = await fs.readFile(envExamplePath, 'utf8')

const fileContents = envFileContents
.split('\n')
.filter((e) => e)
.map((l) =>
envNames?.dbUri && l.startsWith('DATABASE_URI')
? l.replace('DATABASE_URI', envNames.dbUri)
: l,
)
.map((l) => {
if (l.startsWith('DATABASE_URI')) {
// Use db-appropriate connection string
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')

console.log(`Writing to ${envExamplePath}`)
await fs.writeFile(envExamplePath, fileContents)
}

Expand Down

0 comments on commit f5aad49

Please sign in to comment.