mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 05:24:06 +03:00
* ci: move to pnpm 12, pnpm/setup v3 and faster, pinned CI
pnpm 12.6.0 is declared in devEngines.packageManager instead of
packageManager, so pnpm/setup, the Dockerfile and local installs all pick
the same version; the lockfile records the resolved binary. Every workflow
moves to pnpm/setup v3, and the Vercel workflows gain a setup step so
`vercel build` runs with that pnpm rather than whatever is on the runner.
CI time:
- ci runs format check, lint, unit tests, typecheck and build as parallel
steps instead of one after another.
- E2E builds the app once and shares dist with the three browser jobs
instead of rebuilding it in each.
- ci and E2E cancel superseded runs on the same ref.
- The Docker latest/baseurl workflows no longer repeat ci's checks. They
run on workflow_run after ci succeeds for a push, and build the commit
ci tested.
Runners are pinned to ubuntu-26.04-arm. CodeQL stays on x64
(ubuntu-26.04): only the x64 image ships the CodeQL bundle in its tool
cache. The Playwright cache key now includes the runner architecture.
Every action is pinned to its latest release by commit SHA with a version
comment, the Dockerfile base images by digest, and the pnpm and Vercel CLI
installs to exact versions, matching the Renovate presets already enabled
(helpers:pinGitHubActionDigests, docker:pinDigests).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017s2w39tKNdBdD8kyfThuLy
* ci: deploy to Vercel from one workflow with previews and a concurrency group
Replaces sharevb-vercel-preview.yml and sharevb-vercel-prod.yml with
deploy.yaml, which builds here and deploys the prebuilt output:
- One concurrency group per ref with cancel-in-progress, so a burst of
pushes costs one deployment instead of one per push.
- A GitHub environment per run (Production or Preview), which restores the
Environments sidebar and the PR's "View deployment" button.
- Pull requests build their own head commit, named after the PR branch so
Vercel shows the branch rather than "HEAD"; runs from forks are skipped,
since they get no secrets.
- Fails early on missing secrets, refuses to deploy a build without
index.html, and pins the Vercel CLI.
The production hostname for sitemap.xml and robots.txt comes from the
VERCEL_PRODUCTION_URL repository variable instead of being hardcoded, so
the same file serves any deployment. Secrets can live on the repository
or on the Production/Preview environments.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017s2w39tKNdBdD8kyfThuLy
* build: stop compiling tree-sitter's native addon
curlconverter depends on tree-sitter and tree-sitter-bash for its Node
shell parser, but the app only uses curlconverter in the browser, where its
`browser` field swaps in web-tree-sitter (WASM). The native addon is never
loaded.
Building it anyway broke installs: tree-sitter 0.21 ships prebuilds only for
darwin-x64 and win32-x64, so Linux compiles it from source, and its C++17
flags fail against Node 24.21's headers, which require C++20. That is what
failed pnpm install on the arm64 runners.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017s2w39tKNdBdD8kyfThuLy
* ci(e2e): run the browser jobs on x64
On ubuntu-26.04-arm the Playwright suite ran over 7x slower: chromium was
still in the test step after 27 minutes, against under 4 on x64. The build
job stays on arm; its output is architecture-independent.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017s2w39tKNdBdD8kyfThuLy
* test(e2e): stop the preview server with SIGTERM so runs exit
pnpm 12 starts the script it runs in its own process group. Playwright
stops its webServer by SIGKILLing the `pnpm preview` process group, which
no longer contains vite: vite survives, keeps the output pipes open, and
Playwright waits on it forever. The E2E jobs finished every test and then
hung until the job timeout.
pnpm 12.6 forwards SIGTERM to the script it runs, so stop the server with
SIGTERM instead. Locally with pnpm 12.6.0: 112 tests in 1.8 min, clean
exit, nothing left listening on the port.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017s2w39tKNdBdD8kyfThuLy
* Revert "ci(e2e): run the browser jobs on x64"
The slowdown blamed on arm was the Playwright webServer hang fixed in the
previous commit: every test had finished and the job was waiting on an
orphaned vite process. The suite is not slower on arm, so the browser jobs
go back to ubuntu-26.04-arm like the rest.
This reverts commit 9f5af383.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017s2w39tKNdBdD8kyfThuLy
* ci(docker): publish one image at a time, newest wins
Two workflow_run publishes could overlap, and whichever finished last set
the tags, even if it built the older commit. A single concurrency group per
workflow with cancel-in-progress fixes that: ci already cancels superseded
runs on the branch, so publishes arrive in commit order and cancelling the
older one leaves the newest commit on the tags. Raised in review.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017s2w39tKNdBdD8kyfThuLy
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: sharevb <sharevb@gmail.com>
241 lines
12 KiB
YAML
241 lines
12 KiB
YAML
---
|
|
name: Deploy
|
|
|
|
# Builds here and deploys the result to Vercel. The Git integration is off for this project
|
|
# (`git.deploymentEnabled: false` in vercel.json), so this workflow is what deploys it.
|
|
#
|
|
# chore/all-my-stuffs goes to production. Every pull request gets a preview, linked from the
|
|
# PR's "View deployment" button through the GitHub environment set on the job.
|
|
#
|
|
# Setup: VERCEL_TOKEN, VERCEL_ORG_ID and VERCEL_PROJECT_ID as secrets, on the repository or on
|
|
# the Production and Preview environments. Optionally the VERCEL_PRODUCTION_URL repository
|
|
# variable (e.g. https://it-tools.example.com/): production builds generate sitemap.xml and
|
|
# robots.txt for it, and without it they are left out.
|
|
#
|
|
# Replaces sharevb-vercel-preview.yml and sharevb-vercel-prod.yml, which deployed the same two
|
|
# targets without a concurrency group or a GitHub environment. One deployment per burst of
|
|
# pushes keeps Vercel's daily deployment and upload caps, and Deployment Storage, in check.
|
|
permissions:
|
|
contents: read
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- chore/all-my-stuffs
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
# Per ref, cancelling in progress: pushing three times in a minute should cost one
|
|
# deployment, not three. Production is grouped per ref too, so a rapid merge sequence
|
|
# collapses the same way.
|
|
group: deploy-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
deploy:
|
|
# Same-repository events only. GitHub withholds secrets from `pull_request` runs on forks,
|
|
# so a fork would fail the credentials check on every push — and more to the point, this
|
|
# job runs the checked-out branch's build scripts with VERCEL_TOKEN in the environment.
|
|
# That is fine for branches in this repository, whose authors already have the secrets, and
|
|
# is not something to offer an arbitrary fork.
|
|
if: >-
|
|
github.event_name != 'pull_request' ||
|
|
github.event.pull_request.head.repo.full_name == github.repository
|
|
runs-on: ubuntu-26.04-arm
|
|
timeout-minutes: 15
|
|
# Records a GitHub Deployment per run, which is what puts the Environments sidebar, the
|
|
# "deployed to Preview" PR timeline entry and its "View deployment" button back — the parts
|
|
# of the Vercel Git integration lost when building moved here. The names match the
|
|
# environments that integration created, so their history carries on. The condition has to
|
|
# be restated rather than read from the `target` step: the environment is fixed before any
|
|
# step runs. `url` is evaluated at the end, so it can use the deploy step's output.
|
|
environment:
|
|
name: >-
|
|
${{ github.ref == 'refs/heads/chore/all-my-stuffs' && github.event_name != 'pull_request'
|
|
&& 'Production' || 'Preview' }}
|
|
url: ${{ steps.deploy.outputs.url }}
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Fail early if the Vercel credentials are missing
|
|
env:
|
|
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
|
|
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
|
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
run: |
|
|
set -euo pipefail
|
|
missing=""
|
|
for name in VERCEL_TOKEN VERCEL_ORG_ID VERCEL_PROJECT_ID; do
|
|
[ -z "${!name}" ] && missing="$missing $name"
|
|
done
|
|
if [ -n "$missing" ]; then
|
|
# Either place works, so name both rather than send anyone to the wrong settings
|
|
# page.
|
|
echo "::error::Missing secrets:$missing — set them on the repository (Settings > Secrets and variables > Actions) or on the Production and Preview environments (Settings > Environments). See .github/workflows/deploy.yaml"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Checkout repository
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
# On pull requests, the exact commit that triggered the run, not GitHub's detached
|
|
# merge commit: this builds the PR's own head, as Vercel's Git integration did.
|
|
# Pinned to the event's SHA rather than the branch name, so a push that lands while
|
|
# this run is queued, or a re-run of an old run, can't deploy a different commit
|
|
# under this run's deployment. Empty on push and workflow_dispatch, which keeps the
|
|
# default ref.
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
# The Vercel CLI reads the deployment's branch and commit message from git. A detached
|
|
# checkout shows up in Vercel as branch "HEAD", so name the commit after the PR branch.
|
|
- name: Name the checked-out commit after the PR branch
|
|
if: github.event_name == 'pull_request'
|
|
env:
|
|
# From the environment, not interpolated: branch names can contain shell
|
|
# metacharacters.
|
|
HEAD_REF: ${{ github.head_ref }}
|
|
run: git checkout -B "$HEAD_REF"
|
|
|
|
- uses: pnpm/setup@fbda4c85fc2e1e08721cd8763afea8f48d60f024 # v3.0.0
|
|
with:
|
|
cache: true
|
|
|
|
- name: Install Vercel CLI
|
|
# Into a scratch directory outside the repository, not globally: `pnpm add --global`
|
|
# needs a global bin directory that `pnpm/setup` does not configure, and it failed
|
|
# immediately on the first run with the secrets in place. Installing here also keeps
|
|
# package.json and the lockfile untouched, so the tree the build sees is the tree that
|
|
# was committed.
|
|
#
|
|
# Pinned: an unpinned CLI changes how this workflow builds and deploys with no commit
|
|
# here to explain it.
|
|
run: |
|
|
set -euo pipefail
|
|
mkdir -p "$RUNNER_TEMP/vercel-cli"
|
|
cd "$RUNNER_TEMP/vercel-cli"
|
|
pnpm init >/dev/null
|
|
# Build approvals as config rather than --allow-build flags, matching how the
|
|
# repository declares its own. This directory is outside the repository so it
|
|
# inherits nothing; both packages that run install scripts are named here. esbuild
|
|
# is the one that actually needs it — a transitive dependency of the CLI whose
|
|
# postinstall links its native binary.
|
|
#
|
|
# minimumReleaseAge is deliberately not set: pnpm's built-in default is already
|
|
# 1440 minutes, so restating it would only create a second place to keep in sync.
|
|
printf 'allowBuilds:\n vercel: true\n esbuild: true\n' > pnpm-workspace.yaml
|
|
pnpm add vercel@60.1.3
|
|
echo "$RUNNER_TEMP/vercel-cli/node_modules/.bin" >> "$GITHUB_PATH"
|
|
|
|
# Environment is decided once and reused, so the pull, the build and the deploy cannot
|
|
# disagree about which one they are targeting.
|
|
- name: Resolve target environment
|
|
id: target
|
|
env:
|
|
# Read from the environment, not interpolated into the script. workflow_dispatch can
|
|
# run on any branch, and a branch name containing shell metacharacters would
|
|
# otherwise be pasted straight into this `if` as source.
|
|
REF: ${{ github.ref }}
|
|
EVENT: ${{ github.event_name }}
|
|
PRODUCTION_URL: ${{ vars.VERCEL_PRODUCTION_URL }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ "$REF" = "refs/heads/chore/all-my-stuffs" ] && [ "$EVENT" != "pull_request" ]; then
|
|
{
|
|
echo "environment=production"
|
|
echo "prod_flag=--prod"
|
|
echo "hostname=$PRODUCTION_URL"
|
|
} >> "$GITHUB_OUTPUT"
|
|
else
|
|
{
|
|
echo "environment=preview"
|
|
echo "prod_flag="
|
|
# No sitemap or robots.txt for previews: they would advertise the preview URL.
|
|
echo "hostname="
|
|
} >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Pull Vercel project settings
|
|
env:
|
|
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
|
|
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
|
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
run: |
|
|
set -euo pipefail
|
|
# The link is written out rather than left to the CLI to infer from environment
|
|
# variables. Relying on VERCEL_ORG_ID/VERCEL_PROJECT_ID alone failed here with
|
|
# "Could not retrieve Project Settings", and which variables a given CLI version
|
|
# honours is not something to guess at from a workflow. This file is exactly what
|
|
# `vercel link` produces, so the CLI has nothing left to work out.
|
|
mkdir -p .vercel
|
|
# printf rather than a heredoc: a heredoc's terminator has to sit at column zero,
|
|
# which it cannot inside an indented YAML block, and %s keeps the ids out of the
|
|
# shell's word splitting.
|
|
printf '{"projectId":"%s","orgId":"%s"}\n' "$VERCEL_PROJECT_ID" "$VERCEL_ORG_ID" \
|
|
> .vercel/project.json
|
|
# Shape only — the ids are secrets and are not printed.
|
|
python3 -c "import json;d=json.load(open('.vercel/project.json'));print('link written, keys:', sorted(d))"
|
|
vercel pull --yes \
|
|
--environment="${{ steps.target.outputs.environment }}" \
|
|
--token="$VERCEL_TOKEN"
|
|
|
|
- name: Build
|
|
env:
|
|
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
|
|
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
|
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
# What sharevb-vercel-*.yml set, kept so the build is the same:
|
|
# VITE_VERCEL_ENV is the env label the app reports (src/config.ts), and
|
|
# VITE_VERCEL_DEPLOY turns off full PWA precaching (vite.config.ts).
|
|
VITE_VERCEL_ENV: ${{ steps.target.outputs.environment }}
|
|
VITE_VERCEL_DEPLOY: true
|
|
# HOSTNAME is what vite.config.ts generates sitemap.xml and robots.txt from, so it is
|
|
# set for production only, from the VERCEL_PRODUCTION_URL repository variable.
|
|
HOSTNAME: ${{ steps.target.outputs.hostname }}
|
|
run: |
|
|
set -euo pipefail
|
|
vercel build ${{ steps.target.outputs.prod_flag }} --token="$VERCEL_TOKEN"
|
|
# A build that produces nothing would otherwise deploy an empty site over a working
|
|
# one. Checked before anything is uploaded.
|
|
test -s .vercel/output/static/index.html || {
|
|
echo "::error::Build produced no .vercel/output/static/index.html — refusing to deploy"
|
|
exit 1
|
|
}
|
|
|
|
- name: Deploy
|
|
id: deploy
|
|
env:
|
|
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
|
|
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
|
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
run: |
|
|
set -euo pipefail
|
|
# --archive=tgz uploads the output as one archive instead of file by file. The Hobby
|
|
# plan caps CLI uploads at 5000 files a day across the whole account
|
|
# ("api-upload-free"), and per-file uploads hit that after a busy
|
|
# day of deploys.
|
|
url=$(vercel deploy --prebuilt --archive=tgz ${{ steps.target.outputs.prod_flag }} --token="$VERCEL_TOKEN")
|
|
# `vercel deploy` prints the URL on stdout and progress on stderr, so this is the URL
|
|
# and nothing else. Empty means the deploy did not produce one, which is a failure
|
|
# even if the CLI exited 0.
|
|
[ -n "$url" ] || { echo "::error::Deploy returned no URL"; exit 1; }
|
|
echo "url=$url" >> "$GITHUB_OUTPUT"
|
|
echo "Deployed to $url"
|
|
|
|
- name: Summary
|
|
if: always()
|
|
env:
|
|
ENVIRONMENT: ${{ steps.target.outputs.environment }}
|
|
URL: ${{ steps.deploy.outputs.url }}
|
|
STATUS: ${{ job.status }}
|
|
run: |
|
|
{
|
|
echo "### Deploy"
|
|
echo ""
|
|
if [ "$STATUS" = "success" ]; then
|
|
echo "Deployed to **$ENVIRONMENT**: $URL"
|
|
else
|
|
echo "**Deploy failed.** See the failing step above."
|
|
fi
|
|
} >> "$GITHUB_STEP_SUMMARY"
|