Skip to content
Closed
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
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: ci

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
guard-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: pr-guard unit tests
run: node --test scripts/pr-guard.test.mjs

guard:
if: github.event_name == 'pull_request'
uses: ./.github/workflows/pr-guard.yml
with:
require-verification: true
require-refs: true
115 changes: 115 additions & 0 deletions .github/workflows/coolify-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
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.
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. Empty sends the
webhook with no bearer token.
required: false
type: string
default: COOLIFY_API_TOKEN
timeout-minutes:
required: false
type: number
default: 10
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

- id: webhook
name: Post the Coolify deploy webhook
env:
WEBHOOK_SECRET_NAME: ${{ inputs.webhook-secret-name }}
TOKEN_SECRET_NAME: ${{ inputs.token-secret-name }}
run: |
set -euo pipefail
url="$(printenv "${WEBHOOK_SECRET_NAME}" || true)"
token=""
if [ -n "${TOKEN_SECRET_NAME}" ]; then
token="$(printenv "${TOKEN_SECRET_NAME}" || true)"
fi
if [ -z "${url}" ]; then
echo "::error::Infisical did not export ${WEBHOOK_SECRET_NAME}"
exit 1
fi
body="${RUNNER_TEMP}/coolify-webhook.json"
if [ -n "${token}" ]; then
curl --fail-with-body -sS -X POST -H "Authorization: Bearer ${token}" -o "${body}" "${url}"
else
curl --fail-with-body -sS -X POST -o "${body}" "${url}"
fi
if ! uuid="$(node -e '
const fs = require("node:fs");
let parsed;
try { parsed = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); }
catch { process.exit(2); }
const id = parsed.deployments?.[0]?.deployment_uuid ?? parsed.deployment_uuid ?? "";
if (!id) process.exit(2);
process.stdout.write(String(id));
' "${body}")"; then
echo "::error::Coolify response missing deployment_uuid"
exit 1
fi
echo "deployment-uuid=${uuid}" >> "$GITHUB_OUTPUT"
echo "deployment ${uuid}"
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' || '') }}
54 changes: 54 additions & 0 deletions .github/workflows/pr-guard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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

- uses: actions/checkout@v4
with:
repository: PracticalWorks/.github
ref: ${{ github.repository == 'PracticalWorks/.github' && github.sha || 'v1' }}
path: .pw-shared

- 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