Skip to content

Preview reconcile

Preview reconcile #13

name: Preview reconcile
on:
schedule:
- cron: "0 4 * * *"
workflow_dispatch:
permissions: {}
concurrency:
group: preview-reconcile-inventory
cancel-in-progress: false
jobs:
inventory:
name: "Preview / Inventory"
if: vars.COOLIFY_URL != '' && vars.COOLIFY_APP_UUID != ''
runs-on: ubuntu-latest
permissions:
contents: read
deployments: read
timeout-minutes: 5
outputs:
previews: ${{ steps.candidates.outputs.previews }}
steps:
- name: Load the trusted preview controller
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
sparse-checkout: |
.github/actions/setup-node-pnpm
package.json
pnpm-lock.yaml
pnpm-workspace.yaml
scripts
- name: Set up the repository's Node.js and pnpm versions
uses: ./.github/actions/setup-node-pnpm
with:
install: "none"
- name: Find the previews that still hold a slot
id: candidates
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const controller = await import(`${process.env.GITHUB_WORKSPACE}/scripts/preview-controller.ts`);
await controller.inventory({ github, context, core });
cleanup:
name: "Preview / Reconcile PR ${{ matrix.pr }}"
needs: inventory
if: needs.inventory.result == 'success' && needs.inventory.outputs.previews != '[]'
permissions:
contents: read
deployments: write
pull-requests: read
strategy:
fail-fast: false
max-parallel: 5
matrix:
pr: ${{ fromJSON(needs.inventory.outputs.previews) }}
concurrency:
group: hephaestus-preview-lifecycle-${{ matrix.pr }}
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 8
env:
COOLIFY_URL: ${{ vars.COOLIFY_URL }}
COOLIFY_APP_UUID: ${{ vars.COOLIFY_APP_UUID }}
PR_NUMBER: ${{ matrix.pr }}
ENVIRONMENT: preview/pr-${{ matrix.pr }}
steps:
- name: Load the trusted preview adapter
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
sparse-checkout: |
.github/actions/setup-node-pnpm
package.json
pnpm-lock.yaml
pnpm-workspace.yaml
scripts
- name: Set up the repository's Node.js and pnpm versions
uses: ./.github/actions/setup-node-pnpm
with:
install: "none"
- name: Recheck pull request state
id: pull
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const controller = await import(`${process.env.GITHUB_WORKSPACE}/scripts/preview-controller.ts`);
await controller.assess({ github, context, core });
- name: Request Coolify cleanup through the signed close event
id: close
if: steps.pull.outputs.stale == 'true'
env:
COOLIFY_WEBHOOK_SECRET: ${{ secrets.COOLIFY_PREVIEW_WEBHOOK_SECRET }}
PR_URL: ${{ steps.pull.outputs.url }}
PR_TITLE: ${{ steps.pull.outputs.title }}
AUTHOR_ASSOCIATION: ${{ steps.pull.outputs.association }}
HEAD_REF: ${{ steps.pull.outputs.head_ref }}
HEAD_SHA: ${{ steps.pull.outputs.head_sha }}
BASE_REF: ${{ steps.pull.outputs.base_ref }}
run: node scripts/coolify-preview.ts close
- name: Retire the GitHub preview deployments
if: steps.pull.outputs.stale == 'true' && steps.close.outcome == 'success'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const controller = await import(`${process.env.GITHUB_WORKSPACE}/scripts/preview-controller.ts`);
await controller.retire({ github, context, core });