Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: setup
description: >-
pnpm, Node, and a frozen install. On macOS the Node architecture is arm64,
so an Apple Silicon runner does not install an x64 binary under Rosetta.

inputs:
pnpm-version:
description: pnpm version. Match the calling repo's lockfile.
required: false
default: "10.14.0"
node-version:
description: Node version passed to actions/setup-node.
required: false
default: "22"
node-architecture:
description: >-
Node architecture. Empty selects arm64 on macOS and the runner default
everywhere else.
required: false
default: ""
registry-url:
description: Passed to actions/setup-node. Empty writes no registry auth.
required: false
default: ""
github-packages:
description: >-
When true, point pnpm at GitHub Packages with the job token. The caller
job needs packages:read.
required: false
default: "false"
install:
description: Run pnpm install --frozen-lockfile after setup.
required: false
default: "true"

runs:
using: composite
steps:
- uses: pnpm/action-setup@v4
with:
version: ${{ inputs.pnpm-version }}

- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
architecture: ${{ inputs.node-architecture != '' && inputs.node-architecture || (runner.os == 'macOS' && 'arm64' || '') }}
cache: pnpm
registry-url: ${{ inputs.registry-url }}

- if: inputs.github-packages == 'true'
name: Authenticate to GitHub Packages
shell: bash
env:
NODE_AUTH_TOKEN: ${{ github.token }}
run: pnpm config set "//npm.pkg.github.com/:_authToken" "$NODE_AUTH_TOKEN"

- if: inputs.install == 'true'
name: Install
shell: bash
run: pnpm install --frozen-lockfile
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ci

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
guard-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: script unit tests
run: node --test scripts/*.test.mjs

guard:
if: github.event_name == 'pull_request'
uses: ./.github/workflows/pr-guard.yml
with:
require-verification: true
require-refs: true
128 changes: 128 additions & 0 deletions .github/workflows/coolify-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: coolify-deploy

# The job runs in the caller, on the caller's minutes. Secrets are read from
# Infisical with this workflow's GitHub OIDC token. Callers pass the identity
# id and project slug; they do not pass repository secrets.
#
# The job goes green only once Coolify reports the deployment finished, and,
# when health-url is set, once that URL serves expected-version (FACT-1910).
on:
workflow_call:
inputs:
runner:
description: JSON array of runs-on labels.
required: false
type: string
default: '["ubuntu-latest"]'
infisical-domain:
required: false
type: string
default: https://secrets.practical.works
infisical-identity-id:
description: Infisical machine identity id allowed to assume via GitHub OIDC.
required: true
type: string
infisical-project-slug:
required: true
type: string
infisical-env-slug:
required: false
type: string
default: prod
infisical-secret-path:
required: false
type: string
default: /
oidc-audience:
required: false
type: string
default: ""
webhook-secret-name:
description: Shell-safe name of the secret that holds the Coolify webhook URL.
required: false
type: string
default: COOLIFY_WEBHOOK_URL
token-secret-name:
description: >-
Shell-safe name of the Coolify API token secret. It authorizes the
webhook and the deployment status polls, so it is required.
required: false
type: string
default: COOLIFY_API_TOKEN
timeout-minutes:
description: >-
Job timeout. The deploy, the wait for Coolify's outcome, and the
health-url wait share it, less one minute so the job fails by name.
required: false
type: number
default: 10
health-url:
description: >-
Optional URL polled after Coolify reports finished, until its body
contains expected-version. Pass both or neither.
required: false
type: string
default: ""
expected-version:
description: Optional text (e.g. the git sha) health-url must serve.
required: false
type: string
default: ""
outputs:
deployment-uuid:
description: Coolify deployment uuid from the webhook response.
value: ${{ jobs.deploy.outputs.deployment-uuid }}

permissions:
id-token: write
contents: read

jobs:
deploy:
runs-on: ${{ fromJSON(inputs.runner) }}
timeout-minutes: ${{ inputs.timeout-minutes }}
outputs:
deployment-uuid: ${{ steps.webhook.outputs.deployment-uuid }}
steps:
- uses: Infisical/secrets-action@v1.0.18
with:
method: oidc
identity-id: ${{ inputs.infisical-identity-id }}
oidc-audience: ${{ inputs.oidc-audience }}
project-slug: ${{ inputs.infisical-project-slug }}
env-slug: ${{ inputs.infisical-env-slug }}
domain: ${{ inputs.infisical-domain }}
secret-path: ${{ inputs.infisical-secret-path }}
export-type: env

# The deploy script comes from the same commit as this workflow file.
# The fallback is only for a runner that leaves job.workflow_sha empty;
# bump it with each release tag.
- uses: actions/checkout@v4
with:
repository: ${{ job.workflow_repository || 'PracticalWorks/.github' }}
ref: ${{ job.workflow_sha || 'v1.1.0' }}
path: .pw-shared

# Self-hosted runners (Proxmox ephemeral) ship without node.
- uses: actions/setup-node@v4
with:
node-version: 22

- id: webhook
name: Deploy on Coolify and prove it is live
env:
WEBHOOK_SECRET_NAME: ${{ inputs.webhook-secret-name }}
TOKEN_SECRET_NAME: ${{ inputs.token-secret-name }}
HEALTH_URL: ${{ inputs.health-url }}
EXPECTED_VERSION: ${{ inputs.expected-version }}
TIMEOUT_MINUTES: ${{ inputs.timeout-minutes }}
run: |
set -euo pipefail
# Mask both values before anything can print them. printenv does
# not echo; the ::add-mask:: line itself is not shown in the log.
for name in "${WEBHOOK_SECRET_NAME:-COOLIFY_WEBHOOK_URL}" "${TOKEN_SECRET_NAME:-COOLIFY_API_TOKEN}"; do
value="$(printenv "${name}" || true)"
if [ -n "${value}" ]; then echo "::add-mask::${value}"; fi
done
node .pw-shared/scripts/coolify-deploy.mjs
101 changes: 101 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: image

on:
workflow_call:
inputs:
image:
description: GHCR image name, without a tag.
required: true
type: string
runner:
description: JSON array of runs-on labels.
required: false
type: string
default: '["ubuntu-latest"]'
context:
required: false
type: string
default: "."
file:
description: Dockerfile path.
required: false
type: string
default: Dockerfile
platforms:
description: buildx platforms. Empty builds the runner's own architecture.
required: false
type: string
default: ""
push:
required: false
type: boolean
default: true
npmrc:
description: >-
Mount the job token as an npmrc build secret so a Dockerfile can
install private packages. Not a build-arg, so it stays out of image
history. The job token is not a repository secret.
required: false
type: boolean
default: false
cache:
description: inline, gha, or none.
required: false
type: string
default: inline
extra-tags:
description: Extra image tags, one per line, after latest and the commit sha.
required: false
type: string
default: ""
timeout-minutes:
required: false
type: number
default: 30

permissions:
contents: read
packages: write

jobs:
image:
runs-on: ${{ fromJSON(inputs.runner) }}
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- uses: actions/checkout@v4

- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- uses: docker/setup-buildx-action@v3

- id: tags
env:
IMAGE: ${{ inputs.image }}
SHA: ${{ github.sha }}
EXTRA: ${{ inputs.extra-tags }}
run: |
set -euo pipefail
{
echo "tags<<EOF"
echo "${IMAGE}:latest"
echo "${IMAGE}:${SHA}"
if [ -n "${EXTRA}" ]; then
printf '%s\n' "${EXTRA}"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"

- uses: docker/build-push-action@v6
with:
context: ${{ inputs.context }}
file: ${{ inputs.file }}
push: ${{ inputs.push }}
platforms: ${{ inputs.platforms }}
tags: ${{ steps.tags.outputs.tags }}
secrets: ${{ inputs.npmrc && format('npmrc=//npm.pkg.github.com/:_authToken={0}', github.token) || '' }}
cache-from: ${{ inputs.cache == 'inline' && format('type=registry,ref={0}:latest', inputs.image) || (inputs.cache == 'gha' && 'type=gha' || '') }}
cache-to: ${{ inputs.cache == 'inline' && 'type=inline' || (inputs.cache == 'gha' && 'type=gha,mode=max' || '') }}
68 changes: 68 additions & 0 deletions .github/workflows/pr-guard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: pr-guard

on:
workflow_call:
inputs:
require-verification:
description: Fail unless the body has a ## Verification heading.
required: false
type: boolean
default: true
require-refs:
description: Fail unless the body has a Refs line naming an uppercase KEY-123.
required: false
type: boolean
default: true
scan-secrets:
description: Fail if the pull request diff adds a high-confidence secret shape.
required: false
type: boolean
default: false
runner:
description: JSON array of runs-on labels.
required: false
type: string
default: '["ubuntu-latest"]'

permissions:
contents: read

jobs:
check:
runs-on: ${{ fromJSON(inputs.runner) }}
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
if: inputs.scan-secrets
with:
fetch-depth: 0

# The script comes from the same commit as this workflow file, so a caller
# pinned to a tag runs that tag's script. job.workflow_sha names the commit
# of the file that defines this job (the reusable workflow, not the caller).
# The fallback is only for a runner that leaves it empty; bump it with
# each release tag.
- uses: actions/checkout@v4
with:
repository: ${{ job.workflow_repository || 'PracticalWorks/.github' }}
ref: ${{ job.workflow_sha || 'v1.1.0' }}
path: .pw-shared

- name: Warn when the runner gave no workflow sha
if: job.workflow_sha == ''
run: echo "::warning::job.workflow_sha is empty on this runner, so pr-guard ran the v1.1.0 script"

# Self-hosted runners (Proxmox ephemeral) ship without node.
- uses: actions/setup-node@v4
with:
node-version: 22

- name: PR body and guardrails
env:
PR_BODY: ${{ github.event.pull_request.body }}
REQUIRE_VERIFICATION: ${{ inputs.require-verification }}
REQUIRE_REFS: ${{ inputs.require-refs }}
SCAN_SECRETS: ${{ inputs.scan-secrets }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.sha }}
run: node .pw-shared/scripts/pr-guard.mjs
Loading
Loading