mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
Wires Vale into docs CI as an advisory (non-blocking) prose-lint step. Closes [DOCS-40](https://linear.app/codercom/issue/DOCS-40). > **Integration update (rebased onto `main`).** Since this branch was opened, `main` consolidated docs linting into the **required** `lint-docs` job in `ci.yaml` and removed the standalone `docs-ci.yaml` ([#25608](https://github.com/coder/coder/pull/25608)). This PR adds Vale to that `lint-docs` job instead of resurrecting `docs-ci.yaml`, and the `docs/.style/` scaffold defers to the merged [#25466](https://github.com/coder/coder/pull/25466) (DOCS-180). Vale stays advisory. > **Post-review refactor.** Following the Coder Agents review, Vale is now invoked through `mise exec "aqua:errata-ai/vale"` (the same pattern as `actionlint`/`zizmor`) instead of a bespoke `curl`/`tar` download. This removed the GNU-only `grep -oP` version extraction and `uname`/arch mapping that broke on macOS BSD grep, and the prose step now skips paths a PR deletes. See the resolved review threads for CRF-17/19/20/21/22. A sample of what this check does is as follows: <img width="1443" height="1293" alt="image" src="https://github.com/user-attachments/assets/cf68dbf9-d9df-49ba-8dbf-200875bc289e" /> ## What changes - `.vale.ini` at the repo root: Google base + Coder (custom, empty in v1) + curated write-good. `alex` rules are pulled in a la carte. Inline comments justify every enable/disable. - `mise.toml`: pin Vale `3.7.1` via aqua. `mise.lock`: lock that pin across all platforms so `mise install --locked` (used by `build_image`) resolves it. - `Makefile`: a `docs/.style/.vale-synced` sentinel that gates `vale sync`, and a `lint/prose` target that runs `vale --no-exit`. Both invoke Vale via `mise exec "aqua:errata-ai/vale" -- vale ...`, so mise owns the version and the OS/arch download (no hand-rolled install path). - `.github/workflows/ci.yaml`: append Vale steps to the existing required `lint-docs` job: `Detect changed Markdown`, `Restore Vale styles`, `Prepare Vale styles` (`make docs/.style/.vale-synced`), `Vale prose lint`, and a default-branch-only `Save Vale styles`. They lint only changed Markdown under `docs/` that still exists on disk, with a problem matcher for inline PR annotations. - `.github/vale-problem-matcher.json`: parses `vale --output=line` so alerts surface as annotations on the Files Changed tab. - `.gitignore` and the workflow cache `path:`: use `docs/.style/styles/*` plus a `!docs/.style/styles/Coder` negation so adding a package does not require parallel edits. - `.markdownlint-cli2.jsonc`: ignore the synced styles so `make lint/markdown` does not lint upstream READMEs. Scaffold prose under `docs/.style/` and `.claude/docs/DOCS_STYLE_GUIDE.md` / `AGENTS.md` come from the merged DOCS-180; this PR no longer touches them. Net diff against `main` is the 8 Vale-wiring files only. ## Severity policy (v1) Rule severity reflects two things together: the rule's false-positive rate against real Coder docs and the gravity of the rule. Low FPs plus high gravity argues for `error`; lower gravity or more judgment calls argue for `warning` or `suggestion`. v1 lands most rules at `warning` and the wordiness rules at `suggestion`. A rule promotes to `error` only when (a) its false-positive rate against real content is effectively zero and (b) the existing-content violation count for that rule is also zero. Vale exits non-zero only on error-level alerts regardless of `MinAlertLevel`; the Makefile and CI invoke Vale with `--no-exit` so the baseline error count from un-overridden Google rules does not fail the build while real failures (bad config, missing files) still propagate. ## CI integration Vale runs as steps appended to the required `lint-docs` job in `ci.yaml`, gated on changed Markdown: 1. **`Detect changed Markdown`** (`tj-actions/changed-files`) scopes to changed `**.md`; the prose step re-filters to `docs/` (the `docs/**.md` glob silently skips dot-prefixed dirs and would miss `docs/.style/style-guide.md`). 2. **`Restore Vale styles`** (`actions/cache/restore`), keyed off `hashFiles('.vale.ini', 'mise.toml', 'docs/.style/styles/Coder/**')`. mise manages the Vale binary, so only the synced styles are cached. 3. **`Prepare Vale styles`** runs `make docs/.style/.vale-synced` (`mise exec ... vale sync`). 4. **`Vale prose lint`** filters the changed set to `docs/` paths still present on disk, then runs `mise exec ... vale --no-exit --output=line`, emitting inline annotations via the problem matcher. 5. **`Save Vale styles`** writes the cache, gated to `refs/heads/main` only so PR runs cannot poison the cache other branches restore from (the zizmor `cache-poisoning` concern). **Every Vale step is `continue-on-error: true`.** This is a deliberate change from the original standalone-workflow design: now that Vale lives inside the *required* `lint-docs` job, a transient `vale sync` network failure (or first-use `mise` install blip) would otherwise block merges. `continue-on-error` keeps Vale advisory, so only the markdownlint / table-formatter checks above (`pnpm check-docs`) remain merge-blocking. `vale --no-exit` additionally keeps the baseline error count from un-overridden Google rules from failing the step. ## Verification - `actionlint` clean on `ci.yaml` (local + `make lint/actions/actionlint`); `zizmor --persona regular` reports no findings. - `make lint/prose` on the full `docs/` corpus: ~406 errors, ~5,346 warnings, ~7,928 suggestions across 461 files, exit 0 (`--no-exit`), Vale `3.7.1` installed by mise. - Net diff vs `main` is the 8 Vale-wiring files only; the `docs/.style/` scaffold already matches `main`. <details> <summary>Implementation plan and decision log</summary> ### Why this rule set The Vale evaluation against the full docs corpus (measured 2026-05-18) produced ~43,940 raw violations across six candidate base styles. The selection here drops Microsoft and RedHat (overlap with Google, and RedHat's Spacing rule hammers technical IDs), and proselint (Annotations rule treats `> [!NOTE]` admonitions as TODO markers). Within the kept styles: - **Google** is the base. Disables: `EmDash` (conflicts with `make lint/emdash`), `Latin` (i.e./e.g. are fine for our audience), `Spacing` (4,500 errors on `codersdk.SomeType` patterns in the auto-generated API reference). Softened: `Parens` to `suggestion`, `WordList` to `warning`. - **write-good** is the base, with `Passive` and `E-Prime` off. `TooWordy` and `ThereIs` are suggestions; `Weasel` is a warning. - **alex** is cherry-picked (not in `BasedOnStyles`): `Ablist`, `Condescending`, `LGBTQ`, `ProfanityLikely`, `Race`, `Suicide` at warning. The `ProfanityMaybe`/`ProfanityUnlikely` rules trip on `execute`, `kill`, `failed`, and `attack`, which read as technical vocabulary in our context. - **Coder** is in `BasedOnStyles` but the directory is empty in v1. Rules land through the per-rule tickets in the [Docs style guide](https://linear.app/codercom/project/docs-style-guide-7828445b9afc) project. ### Why `mise exec` instead of a download block Vale is pinned in `mise.toml` like `actionlint` and `zizmor`, so invoking it via `mise exec "aqua:errata-ai/vale" -- vale ...` makes the pin the single source of truth and lets mise handle the OS/arch-specific download. This replaced an earlier ~30-line `curl`/`tar` block whose GNU-only `grep -oP ...\K` version extraction returned empty on macOS BSD grep. Note: the bare `vale` short name in `mise exec` ignores the pin and resolves to the latest release, so the full aqua key is required. ### Why `vale sync` instead of vendoring The three style packages weigh ~272 KB combined, so vendoring is cheap. But Vale's ecosystem treats `Packages = ` + `vale sync` as canonical, the upstream LICENSE files are not in the package tarballs (would need to be added manually), and the CI cache makes the sync nearly free after the first run. Sticking with the canonical pattern keeps the repo lean and the upgrade path obvious. ### Why `lint/prose` is not in `lint:` or `lint-light:` Vale on the full docs corpus takes ~20s on cold caches. Forcing every pre-commit through that would be aggressive for a feature that ships as warnings. `make lint/typos` follows the same pattern (it is in `lint-light` but not `lint`; CI invokes it directly). v1 keeps Vale opt-in locally and CI-only by default; promote to `lint:` once the rule set stabilizes. ### Exit-code handling Two mechanisms combine, and the choice changed when the step moved into the required `lint-docs` job: - `vale --no-exit` suppresses Vale's non-zero exit on alerts, so the baseline error-level violations from un-overridden Google rules do not fail the step while the cleanup PRs land. Real failures (config invalid, file missing) still exit non-zero. - `continue-on-error: true` on every Vale step. Because the steps now run inside the *required* `lint-docs` job, a `vale sync` download/network blip must not block merges. The original (standalone, non-required) design rejected `continue-on-error` for showing a misleading yellow badge; in a required job that tradeoff flips, and advisory-yellow is strictly preferable to merge-blocking-red on an infrastructure flake. `|| true` in the Makefile was also rejected: it swallows missing-config failures indiscriminately. ### Pre-mortem - **Generated docs noise**: `docs/reference/` is dominated by auto-generated content (clidocgen, apidocgen, auditdocgen, metricsdocgen). The architectural decision is to fix the generators, not exclude paths in Vale. Google.Spacing is the only rule silenced specifically to defer the generator fix; everything else surfaces as warnings. - **First-run cost**: `mise` installs the pinned Vale (a single small binary) and `vale sync` pulls the style packages on a cold run. The Actions cache keyed off `hashFiles('.vale.ini', 'mise.toml', 'docs/.style/styles/Coder/**')` makes subsequent runs near-instant; the `Coder/**` hash is defense-in-depth against [actions/toolkit#713](https://github.com/actions/toolkit/issues/713) so a future cache release that regresses path-negation cannot serve a stale `Coder/` from cache. - **Required-job blast radius**: moving Vale into the required `lint-docs` job means any Vale step failure would gate merges. Mitigated by `continue-on-error` on all Vale steps plus a clean skip when no changed `docs/` Markdown remains on disk, so only `pnpm check-docs` stays blocking. - **Cross-platform install**: handled by mise (aqua backend) rather than a hand-rolled `uname`/arch map, which removes the macOS BSD-grep break the review flagged. - **Deleted files**: `all_changed_files` is ACMRD and lists paths a PR removes; the prose step filters to files still present on disk so Vale does not error on a missing file. - **Local-vs-CI parity**: CI lints changed files only; local `make lint/prose` lints the full tree. This mirrors `make lint/markdown` (full tree) vs the changed-files CI step. Acceptable for v1. </details> --- *Filed via [Coder Agents](https://coder.com/docs/ai-coder/agents) on Nick's behalf.*
1768 lines
68 KiB
YAML
1768 lines
68 KiB
YAML
name: ci
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- release/*
|
|
|
|
# GitHub Actions does not reliably trigger push-based CI when a new
|
|
# branch is created at a commit that already has a workflow run (e.g.
|
|
# from main). The create event fires separately and ensures CI runs
|
|
# on newly cut release branches. Non-release branch creations are
|
|
# filtered out by the changes job condition.
|
|
create:
|
|
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
# Cancel in-progress runs for pull requests when developers push
|
|
# additional changes
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
|
|
|
jobs:
|
|
changes:
|
|
runs-on: ubuntu-latest
|
|
# For create events, only run on release branches to avoid
|
|
# triggering CI for every feature branch creation.
|
|
if: |
|
|
github.event_name != 'create' || (
|
|
github.event.ref_type == 'branch' &&
|
|
startsWith(github.event.ref, 'release/')
|
|
)
|
|
outputs:
|
|
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
|
|
docs: ${{ steps.filter.outputs.docs }}
|
|
go: ${{ steps.filter.outputs.go }}
|
|
site: ${{ steps.filter.outputs.site }}
|
|
k8s: ${{ steps.filter.outputs.k8s }}
|
|
ci: ${{ steps.filter.outputs.ci }}
|
|
db: ${{ steps.filter.outputs.db }}
|
|
gomod: ${{ steps.filter.outputs.gomod }}
|
|
offlinedocs-only: ${{ steps.filter.outputs.offlinedocs_count == steps.filter.outputs.all_count }}
|
|
offlinedocs: ${{ steps.filter.outputs.offlinedocs }}
|
|
tailnet-integration: ${{ steps.filter.outputs.tailnet-integration }}
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
- name: check changed files
|
|
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
all:
|
|
- "**"
|
|
docs:
|
|
- "docs/**"
|
|
- ".claude/docs/**"
|
|
- "*.md"
|
|
- "examples/web-server/**"
|
|
- "examples/monitoring/**"
|
|
- "examples/lima/**"
|
|
db:
|
|
- "**.sql"
|
|
- "coderd/database/**"
|
|
go:
|
|
- "**.sql"
|
|
- "**.go"
|
|
- "**.golden"
|
|
- "go.mod"
|
|
- "go.sum"
|
|
# Other non-Go files that may affect Go code:
|
|
- "**.rego"
|
|
- "**.sh"
|
|
- "**.tpl"
|
|
- "**.gotmpl"
|
|
- "**.gotpl"
|
|
- "Makefile"
|
|
- "site/static/error.html"
|
|
# Icon and theme files tested by Go (scripts/gensite):
|
|
- "site/static/icon/**"
|
|
- "site/src/theme/**"
|
|
# Main repo directories for completeness in case other files are
|
|
# touched:
|
|
- "agent/**"
|
|
- "aibridge/**"
|
|
- "cli/**"
|
|
- "cmd/**"
|
|
- "coderd/**"
|
|
- "enterprise/**"
|
|
- "examples/**"
|
|
- "helm/**"
|
|
- "provisioner/**"
|
|
- "provisionerd/**"
|
|
- "provisionersdk/**"
|
|
- "pty/**"
|
|
- "scaletest/**"
|
|
- "tailnet/**"
|
|
- "testutil/**"
|
|
gomod:
|
|
- "go.mod"
|
|
- "go.sum"
|
|
site:
|
|
- "site/**"
|
|
k8s:
|
|
- "helm/**"
|
|
- "scripts/Dockerfile"
|
|
- "scripts/Dockerfile.base"
|
|
- "scripts/helm.sh"
|
|
ci:
|
|
- ".github/actions/**"
|
|
- ".github/workflows/**"
|
|
offlinedocs:
|
|
- "offlinedocs/**"
|
|
tailnet-integration:
|
|
- "tailnet/**"
|
|
- "go.mod"
|
|
- "go.sum"
|
|
|
|
- id: debug
|
|
run: |
|
|
echo "$FILTER_JSON"
|
|
env:
|
|
FILTER_JSON: ${{ toJSON(steps.filter.outputs) }}
|
|
|
|
lint-docs:
|
|
needs: changes
|
|
if: needs.changes.outputs.docs == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "node pnpm"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- name: Check docs
|
|
run: pnpm check-docs
|
|
|
|
# Vale prose linter, advisory only. Scoped to changed Markdown under
|
|
# docs/. Every Vale step is `continue-on-error` so this section can
|
|
# never block the required `lint-docs` job: a `vale sync` network
|
|
# blip or a baseline rule violation surfaces as an annotation, not a
|
|
# merge gate. Only markdownlint/table-formatter above stay blocking.
|
|
# `vale --no-exit` additionally keeps the baseline error count from
|
|
# un-overridden upstream Google rules from failing the step. Lives
|
|
# here rather than a standalone workflow so docs lint stays in the
|
|
# single required CI umbrella (see #25608). See DOCS-40.
|
|
- name: Detect changed Markdown
|
|
id: changed-md
|
|
continue-on-error: true
|
|
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v45.0.7
|
|
with:
|
|
files: |
|
|
**.md
|
|
separator: ","
|
|
|
|
# `**.md` (not `docs/**.md`) because the action's globber collapses a
|
|
# `**` adjacent to `.md` to a single path segment, so `docs/**.md`
|
|
# only matches top-level docs/*.md and misses nested pages such as
|
|
# docs/.style/style-guide.md. The prose step below re-filters to
|
|
# docs/ paths.
|
|
# Cache split into restore + conditional save to avoid letting PR
|
|
# runs populate a cache that other branches restore from (the
|
|
# zizmor `cache-poisoning` concern). Only pushes to the default
|
|
# branch may write the cache; PRs may only read it.
|
|
- name: Restore Vale styles
|
|
id: vale-cache
|
|
if: steps.changed-md.outputs.any_changed == 'true'
|
|
continue-on-error: true
|
|
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
# Negation excludes the hand-authored Coder rules from the cache;
|
|
# the key also hashes them so a rule change always invalidates it.
|
|
# mise manages the Vale binary, so only the synced styles cache.
|
|
path: |
|
|
docs/.style/styles/*
|
|
!docs/.style/styles/Coder
|
|
docs/.style/.vale-synced
|
|
key: vale-${{ hashFiles('.vale.ini', 'mise.toml', 'docs/.style/styles/Coder/**') }}
|
|
restore-keys: |
|
|
vale-
|
|
|
|
- name: Prepare Vale styles
|
|
if: steps.changed-md.outputs.any_changed == 'true'
|
|
continue-on-error: true
|
|
env:
|
|
# Non-interactive: let mise auto-install the pinned Vale on first use.
|
|
MISE_YES: "1"
|
|
run: make docs/.style/.vale-synced
|
|
|
|
- name: Vale prose lint
|
|
if: steps.changed-md.outputs.any_changed == 'true'
|
|
continue-on-error: true
|
|
env:
|
|
ALL_CHANGED_FILES: ${{ steps.changed-md.outputs.all_changed_files }}
|
|
# Non-interactive: let mise auto-install the pinned Vale on first use.
|
|
MISE_YES: "1"
|
|
run: |
|
|
# all_changed_files is ACMRD and so lists paths this PR deleted.
|
|
# Vale errors on a missing file (--no-exit only suppresses alert
|
|
# exits, not runtime errors), so keep only docs/ paths still on
|
|
# disk. See DOCS-40.
|
|
files=$(printf '%s\n' "$ALL_CHANGED_FILES" \
|
|
| tr ',' '\n' \
|
|
| grep -E '^docs/' \
|
|
| while IFS= read -r f; do [ -f "$f" ] && printf '%s\n' "$f"; done || true)
|
|
if [ -z "$files" ]; then
|
|
echo "No changed Markdown files under docs/ on disk; skipping Vale."
|
|
exit 0
|
|
fi
|
|
echo "::add-matcher::.github/vale-problem-matcher.json"
|
|
printf '%s\n' "$files" | xargs -d '\n' mise exec "aqua:errata-ai/vale" -- vale --no-exit --output=line
|
|
echo "::remove-matcher owner=vale::"
|
|
|
|
- name: Save Vale styles
|
|
# Only the default branch is trusted to write the cache, so PR
|
|
# runs cannot poison the cache that subsequent runs restore from.
|
|
# Skip when the cache already had an exact key hit (no new content).
|
|
if: github.ref == 'refs/heads/main' && steps.changed-md.outputs.any_changed == 'true' && steps.vale-cache.outputs.cache-hit != 'true'
|
|
continue-on-error: true
|
|
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
path: |
|
|
docs/.style/styles/*
|
|
!docs/.style/styles/Coder
|
|
docs/.style/.vale-synced
|
|
key: ${{ steps.vale-cache.outputs.cache-primary-key }}
|
|
|
|
# Disabled due to instability. See: https://github.com/coder/coder/issues/14553
|
|
# Re-enable once the flake hash calculation is stable.
|
|
# update-flake:
|
|
# needs: changes
|
|
# if: needs.changes.outputs.gomod == 'true'
|
|
# runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
# steps:
|
|
# - name: Checkout
|
|
# uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
# with:
|
|
# fetch-depth: 1
|
|
# # See: https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#commits-made-by-this-action-do-not-trigger-new-workflow-runs
|
|
# token: ${{ secrets.CDRCI_GITHUB_TOKEN }}
|
|
|
|
# - name: Set up mise tools
|
|
# uses: ./.github/actions/setup-mise
|
|
# with:
|
|
# install-args: "go"
|
|
|
|
# - name: Update Nix Flake SRI Hash
|
|
# run: ./scripts/update-flake.sh
|
|
|
|
# # auto update flake for dependabot
|
|
# - uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5.0.1
|
|
# if: github.actor == 'dependabot[bot]'
|
|
# with:
|
|
# # Allows dependabot to still rebase!
|
|
# commit_message: "[dependabot skip] Update Nix Flake SRI Hash"
|
|
# commit_user_name: "dependabot[bot]"
|
|
# commit_user_email: "49699333+dependabot[bot]@users.noreply.github.com>"
|
|
# commit_author: "dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>"
|
|
|
|
# # require everyone else to update it themselves
|
|
# - name: Ensure No Changes
|
|
# if: github.actor != 'dependabot[bot]'
|
|
# run: git diff --exit-code
|
|
|
|
lint:
|
|
needs: changes
|
|
if: needs.changes.outputs.offlinedocs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go node pnpm helm actionlint aqua:crate-ci/typos"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:github.com/golangci/golangci-lint/cmd/golangci-lint go:github.com/coder/paralleltestctx/cmd/paralleltestctx
|
|
|
|
- name: Get golangci-lint cache dir
|
|
run: |
|
|
dir=$(golangci-lint cache status | awk '/Dir/ { print $2 }')
|
|
echo "LINT_CACHE_DIR=$dir" >> "$GITHUB_ENV"
|
|
|
|
# Cache split into restore + conditional save to avoid letting PR
|
|
# runs populate a cache that other branches restore from (the
|
|
# zizmor `cache-poisoning` concern). Only pushes to the default
|
|
# branch may write the cache; PRs may only read it.
|
|
- name: Restore golangci-lint cache
|
|
id: golangci-lint-cache
|
|
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
path: |
|
|
${{ env.LINT_CACHE_DIR }}
|
|
key: golangci-lint-${{ runner.os }}-${{ hashFiles('**/*.go') }}
|
|
restore-keys: |
|
|
golangci-lint-${{ runner.os }}-
|
|
|
|
# Check for any typos
|
|
- name: Check for typos
|
|
run: typos --config .github/workflows/typos.toml
|
|
|
|
- name: Fix the typos
|
|
if: ${{ failure() }}
|
|
run: |
|
|
echo "::notice:: you can automatically fix typos from your CLI:
|
|
mise exec aqua:crate-ci/typos -- typos -c .github/workflows/typos.toml -w"
|
|
|
|
- name: Verify helm version
|
|
run: helm version --short
|
|
|
|
- name: make lint
|
|
run: make --output-sync=line -j lint
|
|
|
|
- name: Save golangci-lint cache
|
|
# Only the default branch is trusted to write the cache, so PR
|
|
# runs cannot poison the cache that subsequent runs restore from.
|
|
# Skip when the cache already had an exact key hit (no new content).
|
|
if: github.ref == 'refs/heads/main' && steps.golangci-lint-cache.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
path: |
|
|
${{ env.LINT_CACHE_DIR }}
|
|
key: ${{ steps.golangci-lint-cache.outputs.cache-primary-key }}
|
|
|
|
- name: Check workflow files
|
|
run: actionlint -color -shellcheck= -ignore "set-output"
|
|
shell: bash
|
|
|
|
- name: Check for unstaged files
|
|
run: ./scripts/check_unstaged.sh
|
|
shell: bash
|
|
|
|
lint-actions:
|
|
needs: changes
|
|
# Only run this job if changes to CI workflow files are detected. This job
|
|
# can flake as it reaches out to GitHub to check referenced actions.
|
|
if: needs.changes.outputs.ci == 'true'
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-24.04-8' || 'ubuntu-24.04' }}
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "actionlint zizmor"
|
|
|
|
- name: make lint/actions
|
|
run: make --output-sync=line -j lint/actions
|
|
env:
|
|
# Used by zizmor to lint third-party GitHub actions.
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
gen:
|
|
timeout-minutes: 20
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
if: ${{ !cancelled() }}
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go node pnpm terraform protoc protoc-gen-go"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:storj.io/drpc/cmd/protoc-gen-go-drpc go:github.com/coder/sqlc/cmd/sqlc
|
|
|
|
- name: Start PostgreSQL container
|
|
run: make test-postgres-docker
|
|
|
|
- name: make gen
|
|
timeout-minutes: 8
|
|
run: |
|
|
# Remove golden files to detect discrepancy in generated files.
|
|
make clean/golden-files
|
|
# Notifications require DB, we could start a DB instance here but
|
|
# let's just restore for now.
|
|
git checkout -- coderd/notifications/testdata/rendered-templates
|
|
make -j --output-sync -B gen
|
|
|
|
- name: Check for unstaged files
|
|
run: ./scripts/check_unstaged.sh
|
|
|
|
- name: Collect PostgreSQL logs
|
|
if: always()
|
|
run: make test-postgres-docker-logs > postgres.log 2>&1
|
|
|
|
- name: Upload PostgreSQL logs
|
|
if: always()
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: gen-postgres-logs
|
|
path: postgres.log
|
|
|
|
fmt:
|
|
needs: changes
|
|
if: needs.changes.outputs.offlinedocs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Check Go version
|
|
run: IGNORE_NIX=true ./scripts/check_go_versions.sh
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go node pnpm terraform"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:mvdan.cc/sh/v3/cmd/shfmt
|
|
|
|
- name: make fmt
|
|
timeout-minutes: 7
|
|
run: make --output-sync -j -B fmt
|
|
|
|
- name: Check for unstaged files
|
|
run: ./scripts/check_unstaged.sh
|
|
|
|
test-go-pg:
|
|
# make sure to adjust NUM_PARALLEL_PACKAGES and NUM_PARALLEL_TESTS below
|
|
# when changing runner sizes
|
|
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || matrix.os && matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'depot-windows-2022-16' || matrix.os }}
|
|
needs: changes
|
|
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
# This timeout must be greater than the timeout set by `go test` in
|
|
# `make test` to ensure we receive a trace of running goroutines.
|
|
# Setting this to the timeout +5m should work quite well even if
|
|
# some of the preceding steps are slow.
|
|
timeout-minutes: 25
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os:
|
|
- ubuntu-latest
|
|
- macos-latest
|
|
- windows-2022
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
# macOS indexes all new files in the background. Our Postgres tests
|
|
# create and destroy thousands of databases on disk, and Spotlight
|
|
# tries to index all of them, seriously slowing down the tests.
|
|
- name: Disable Spotlight Indexing
|
|
if: runner.os == 'macOS'
|
|
run: |
|
|
enabled=$(sudo mdutil -a -s | { grep -Fc "Indexing enabled" || true; })
|
|
if [ "$enabled" -eq 0 ]; then
|
|
echo "Spotlight indexing is already disabled"
|
|
exit 0
|
|
fi
|
|
sudo mdutil -a -i off
|
|
sudo mdutil -X /
|
|
sudo launchctl bootout system /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
|
|
|
|
# Set up RAM disks to speed up the rest of the job. This action is in
|
|
# a separate repository to allow its use before actions/checkout.
|
|
- name: Setup RAM Disks
|
|
if: runner.os == 'Windows'
|
|
uses: coder/setup-ramdisk-action@e1100847ab2d7bcd9d14bcda8f2d1b0f07b36f1b # v0.1.0
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Setup Go Paths
|
|
id: go-paths
|
|
uses: ./.github/actions/setup-go-paths
|
|
|
|
- name: Setup GNU tools (macOS)
|
|
uses: ./.github/actions/setup-gnu-tools
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go terraform"
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
with:
|
|
cache-path: ${{ steps.go-paths.outputs.cached-dirs }}
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:gotest.tools/gotestsum go:github.com/slsyy/mtimehash/cmd/mtimehash
|
|
|
|
- name: Download Test Cache
|
|
id: download-cache
|
|
uses: ./.github/actions/test-cache/download
|
|
with:
|
|
key-prefix: test-go-pg-${{ runner.os }}-${{ runner.arch }}
|
|
|
|
- name: Setup Embedded Postgres Cache Paths
|
|
id: embedded-pg-cache
|
|
uses: ./.github/actions/setup-embedded-pg-cache-paths
|
|
|
|
- name: Download Embedded Postgres Cache
|
|
id: download-embedded-pg-cache
|
|
uses: ./.github/actions/embedded-pg-cache/download
|
|
with:
|
|
key-prefix: embedded-pg-${{ runner.os }}-${{ runner.arch }}
|
|
cache-path: ${{ steps.embedded-pg-cache.outputs.cached-dirs }}
|
|
|
|
- name: Normalize File and Directory Timestamps
|
|
shell: bash
|
|
# Normalize file modification timestamps so that go test can use the
|
|
# cache from the previous CI run. See https://github.com/golang/go/issues/58571
|
|
# for more details.
|
|
run: |
|
|
find . -type f ! -path ./.git/\*\* | mtimehash
|
|
find . -type d ! -path ./.git/\*\* -exec touch -t 200601010000 {} +
|
|
|
|
- name: Normalize Terraform Path for Caching
|
|
shell: bash
|
|
# Terraform gets installed in a random directory, so we need to normalize
|
|
# the path or many cached tests will be invalidated.
|
|
run: |
|
|
mkdir -p "$RUNNER_TEMP/sym"
|
|
source scripts/normalize_path.sh
|
|
normalize_path_with_symlinks "$RUNNER_TEMP/sym" "$(dirname "$(which terraform)")"
|
|
|
|
- name: Setup RAM disk for Embedded Postgres (Windows)
|
|
if: runner.os == 'Windows'
|
|
shell: bash
|
|
# The default C: drive is extremely slow:
|
|
# https://github.com/actions/runner-images/issues/8755
|
|
run: mkdir -p "R:/temp/embedded-pg"
|
|
|
|
- name: Setup RAM disk for Embedded Postgres (macOS)
|
|
if: runner.os == 'macOS'
|
|
shell: bash
|
|
run: |
|
|
# Postgres runs faster on a ramdisk on macOS.
|
|
mkdir -p /tmp/tmpfs
|
|
sudo mount_tmpfs -o noowners -s 8g /tmp/tmpfs
|
|
|
|
# macOS will output "The default interactive shell is now zsh" intermittently in CI.
|
|
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
|
|
|
|
- name: Increase PTY limit (macOS)
|
|
if: runner.os == 'macOS'
|
|
shell: bash
|
|
run: |
|
|
# Increase PTY limit to avoid exhaustion during tests.
|
|
# Default is 511; 999 is the maximum value on CI runner.
|
|
sudo sysctl -w kern.tty.ptmx_max=999
|
|
|
|
- name: Test with PostgreSQL Database (Linux)
|
|
if: runner.os == 'Linux'
|
|
uses: ./.github/actions/test-go-pg
|
|
with:
|
|
postgres-version: "13"
|
|
# Our Linux runners have 8 cores.
|
|
test-parallelism-packages: "8"
|
|
test-parallelism-tests: "8"
|
|
# By default, run tests with cache for improved speed (possibly at the expense of correctness).
|
|
# On main, run tests without cache for the inverse.
|
|
test-count: ${{ github.ref == 'refs/heads/main' && '1' || '' }}
|
|
gotestsum-json-file: default
|
|
|
|
- name: Test with PostgreSQL Database (macOS)
|
|
if: runner.os == 'macOS'
|
|
uses: ./.github/actions/test-go-pg
|
|
with:
|
|
postgres-version: "13"
|
|
# Our macOS runners have 8 cores.
|
|
# Even though this parallelism seems high, we've observed relatively low flakiness in the past.
|
|
# See https://github.com/coder/coder/pull/21091#discussion_r2609891540.
|
|
test-parallelism-packages: "8"
|
|
test-parallelism-tests: "16"
|
|
# By default, run tests with cache for improved speed (possibly at the expense of correctness).
|
|
# On main, run tests without cache for the inverse.
|
|
test-count: ${{ github.ref == 'refs/heads/main' && '1' || '' }}
|
|
# Only the CLI and Agent are officially supported on macOS; the rest are too flaky.
|
|
test-packages: "./cli/... ./enterprise/cli/... ./agent/..."
|
|
embedded-pg-path: "/tmp/tmpfs/embedded-pg"
|
|
embedded-pg-cache: ${{ steps.embedded-pg-cache.outputs.embedded-pg-cache }}
|
|
|
|
- name: Test with PostgreSQL Database (Windows)
|
|
if: runner.os == 'Windows'
|
|
uses: ./.github/actions/test-go-pg
|
|
with:
|
|
postgres-version: "13"
|
|
# Our Windows runners have 16 cores.
|
|
# On Windows Postgres chokes up when we have 16x16=256 tests
|
|
# running in parallel, and dbtestutil.NewDB starts to take more than
|
|
# 10s to complete sometimes causing test timeouts. With 16x8=128 tests
|
|
# Postgres tends not to choke.
|
|
test-parallelism-packages: "8"
|
|
test-parallelism-tests: "16"
|
|
# By default, run tests with cache for improved speed (possibly at the expense of correctness).
|
|
# On main, run tests without cache for the inverse.
|
|
test-count: ${{ github.ref == 'refs/heads/main' && '1' || '' }}
|
|
# Only the CLI and Agent are officially supported on Windows; the rest are too flaky.
|
|
test-packages: "./cli/... ./enterprise/cli/... ./agent/..."
|
|
embedded-pg-path: "R:/temp/embedded-pg"
|
|
embedded-pg-cache: ${{ steps.embedded-pg-cache.outputs.embedded-pg-cache }}
|
|
|
|
- name: Publish Go test failure report
|
|
if: failure() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork)
|
|
uses: ./.github/actions/go-test-failure-report
|
|
with:
|
|
artifact-name: go-test-failures-${{ github.job }}-${{ github.sha }}
|
|
|
|
- name: Upload failed test db dumps
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: failed-test-db-dump-${{matrix.os}}
|
|
path: "**/*.test.sql"
|
|
|
|
- name: Upload Test Cache
|
|
uses: ./.github/actions/test-cache/upload
|
|
with:
|
|
cache-key: ${{ steps.download-cache.outputs.cache-key }}
|
|
|
|
- name: Upload Embedded Postgres Cache
|
|
uses: ./.github/actions/embedded-pg-cache/upload
|
|
# We only use the embedded Postgres cache on macOS and Windows runners.
|
|
if: runner.OS == 'macOS' || runner.OS == 'Windows'
|
|
with:
|
|
cache-key: ${{ steps.download-embedded-pg-cache.outputs.cache-key }}
|
|
cache-path: "${{ steps.embedded-pg-cache.outputs.embedded-pg-cache }}"
|
|
|
|
- name: Upload test stats to Datadog
|
|
timeout-minutes: 1
|
|
continue-on-error: true
|
|
uses: ./.github/actions/upload-datadog
|
|
if: success() || failure()
|
|
with:
|
|
api-key: ${{ secrets.DATADOG_API_KEY }}
|
|
|
|
test-go-pg-17:
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
needs:
|
|
- changes
|
|
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
# This timeout must be greater than the timeout set by `go test` in
|
|
# `make test` to ensure we receive a trace of running goroutines.
|
|
# Setting this to the timeout +5m should work quite well even if
|
|
# some of the preceding steps are slow.
|
|
timeout-minutes: 25
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go terraform"
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:gotest.tools/gotestsum
|
|
|
|
- name: Download Test Cache
|
|
id: download-cache
|
|
uses: ./.github/actions/test-cache/download
|
|
with:
|
|
key-prefix: test-go-pg-17-${{ runner.os }}-${{ runner.arch }}
|
|
|
|
- name: Normalize Terraform Path for Caching
|
|
shell: bash
|
|
# Terraform gets installed in a random directory, so we need to normalize
|
|
# the path or many cached tests will be invalidated.
|
|
run: |
|
|
mkdir -p "$RUNNER_TEMP/sym"
|
|
source scripts/normalize_path.sh
|
|
normalize_path_with_symlinks "$RUNNER_TEMP/sym" "$(dirname "$(which terraform)")"
|
|
|
|
- name: Test with PostgreSQL Database
|
|
uses: ./.github/actions/test-go-pg
|
|
with:
|
|
postgres-version: "17"
|
|
# Our Linux runners have 8 cores.
|
|
test-parallelism-packages: "8"
|
|
test-parallelism-tests: "8"
|
|
# By default, run tests with cache for improved speed (possibly at the expense of correctness).
|
|
# On main, run tests without cache for the inverse.
|
|
test-count: ${{ github.ref == 'refs/heads/main' && '1' || '' }}
|
|
gotestsum-json-file: default
|
|
|
|
- name: Publish Go test failure report
|
|
if: failure() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork)
|
|
uses: ./.github/actions/go-test-failure-report
|
|
with:
|
|
artifact-name: go-test-failures-${{ github.job }}-${{ github.sha }}
|
|
|
|
- name: Upload Test Cache
|
|
uses: ./.github/actions/test-cache/upload
|
|
with:
|
|
cache-key: ${{ steps.download-cache.outputs.cache-key }}
|
|
|
|
- name: Upload test stats to Datadog
|
|
timeout-minutes: 1
|
|
continue-on-error: true
|
|
uses: ./.github/actions/upload-datadog
|
|
if: success() || failure()
|
|
with:
|
|
api-key: ${{ secrets.DATADOG_API_KEY }}
|
|
|
|
test-go-race-pg:
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-16' || 'ubuntu-latest' }}
|
|
needs: changes
|
|
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
timeout-minutes: 25
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go terraform"
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:gotest.tools/gotestsum
|
|
|
|
- name: Download Test Cache
|
|
id: download-cache
|
|
uses: ./.github/actions/test-cache/download
|
|
with:
|
|
key-prefix: test-go-race-pg-${{ runner.os }}-${{ runner.arch }}
|
|
|
|
- name: Normalize Terraform Path for Caching
|
|
shell: bash
|
|
# Terraform gets installed in a random directory, so we need to normalize
|
|
# the path or many cached tests will be invalidated.
|
|
run: |
|
|
mkdir -p "$RUNNER_TEMP/sym"
|
|
source scripts/normalize_path.sh
|
|
normalize_path_with_symlinks "$RUNNER_TEMP/sym" "$(dirname "$(which terraform)")"
|
|
|
|
# We run race tests with reduced parallelism because they use more CPU and we were finding
|
|
# instances where tests appear to hang for multiple seconds, resulting in flaky tests when
|
|
# short timeouts are used.
|
|
# c.f. discussion on https://github.com/coder/coder/pull/15106
|
|
# Our Linux runners have 16 cores, but we reduce parallelism since race detection adds a lot of overhead.
|
|
# We aim to have parallelism match CPU count (4*4=16) to avoid making flakes worse.
|
|
- name: Run Tests
|
|
uses: ./.github/actions/test-go-pg
|
|
with:
|
|
postgres-version: "17"
|
|
test-parallelism-packages: "4"
|
|
test-parallelism-tests: "4"
|
|
race-detection: "true"
|
|
gotestsum-json-file: default
|
|
|
|
- name: Publish Go test failure report
|
|
if: failure() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork)
|
|
uses: ./.github/actions/go-test-failure-report
|
|
with:
|
|
artifact-name: go-test-failures-${{ github.job }}-${{ github.sha }}
|
|
|
|
- name: Upload Test Cache
|
|
uses: ./.github/actions/test-cache/upload
|
|
with:
|
|
cache-key: ${{ steps.download-cache.outputs.cache-key }}
|
|
|
|
- name: Upload test stats to Datadog
|
|
timeout-minutes: 1
|
|
continue-on-error: true
|
|
uses: ./.github/actions/upload-datadog
|
|
if: always()
|
|
with:
|
|
api-key: ${{ secrets.DATADOG_API_KEY }}
|
|
|
|
# Tailnet integration tests only run when the `tailnet` directory or `go.sum`
|
|
# and `go.mod` are changed. These tests are to ensure we don't add regressions
|
|
# to tailnet, either due to our code or due to updating dependencies.
|
|
#
|
|
# These tests are skipped in the main go test jobs because they require root
|
|
# and mess with networking.
|
|
test-go-tailnet-integration:
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
needs: changes
|
|
# Unnecessary to run on main for now
|
|
if: needs.changes.outputs.tailnet-integration == 'true' || needs.changes.outputs.ci == 'true'
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go"
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
# Used by some integration tests.
|
|
- name: Install Nginx
|
|
run: sudo apt-get update && sudo apt-get install -y nginx
|
|
|
|
- name: Run Tests
|
|
run: make test-tailnet-integration
|
|
|
|
test-js:
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
needs: changes
|
|
if: needs.changes.outputs.site == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
timeout-minutes: 20
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "node pnpm"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- run: pnpm test:ci --max-workers "$(nproc)"
|
|
working-directory: site
|
|
|
|
test-e2e:
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || 'ubuntu-latest' }}
|
|
needs: changes
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
variant:
|
|
- premium: false
|
|
name: test-e2e
|
|
#- premium: true
|
|
# name: test-e2e-premium
|
|
# Skip test-e2e on forks as they don't have access to CI secrets
|
|
if: (needs.changes.outputs.go == 'true' || needs.changes.outputs.site == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main') && !(github.event.pull_request.head.repo.fork)
|
|
timeout-minutes: 20
|
|
name: ${{ matrix.variant.name }}
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go node pnpm"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
# Assume that the checked-in versions are up-to-date
|
|
- run: make gen/mark-fresh
|
|
name: make gen
|
|
|
|
- run: make site/e2e/bin/coder
|
|
name: make coder
|
|
|
|
- run: pnpm build
|
|
env:
|
|
NODE_OPTIONS: ${{ github.repository_owner == 'coder' && '--max_old_space_size=8192' || '' }}
|
|
working-directory: site
|
|
|
|
- run: pnpm playwright:install
|
|
working-directory: site
|
|
|
|
# Run tests that don't require a premium license without a premium license
|
|
- run: pnpm playwright:test --forbid-only --workers 1
|
|
if: ${{ !matrix.variant.premium }}
|
|
env:
|
|
DEBUG: pw:api
|
|
working-directory: site
|
|
|
|
# Run all of the tests with a premium license
|
|
- run: pnpm playwright:test --forbid-only --workers 1
|
|
if: ${{ matrix.variant.premium }}
|
|
env:
|
|
DEBUG: pw:api
|
|
CODER_E2E_LICENSE: ${{ secrets.CODER_E2E_LICENSE }}
|
|
CODER_E2E_REQUIRE_PREMIUM_TESTS: "1"
|
|
working-directory: site
|
|
|
|
- name: Upload Playwright failure artifacts
|
|
if: failure() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: playwright-artifacts-${{ matrix.variant.name }}-${{ github.sha }}
|
|
path: |
|
|
./site/test-results/**
|
|
./site/playwright-report/**
|
|
retention-days: 7
|
|
|
|
- name: Publish Playwright failure summary
|
|
if: failure() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
|
|
env:
|
|
MATRIX_VARIANT: ${{ matrix.variant.name }}
|
|
GITHUB_SHA_SHORT: ${{ github.sha }}
|
|
run: bash scripts/playwright-failure-summary.sh site/test-results/results.json >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
- name: Upload debug log
|
|
if: failure() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coderd-debug-logs-${{ matrix.variant.name }}-${{ github.sha }}
|
|
path: ./site/e2e/test-results/debug.log
|
|
retention-days: 7
|
|
|
|
- name: Upload pprof dumps
|
|
if: failure() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: debug-pprof-dumps-${{ matrix.variant.name }}-${{ github.sha }}
|
|
path: ./site/test-results/**/debug-pprof-*.txt
|
|
retention-days: 7
|
|
|
|
storybook:
|
|
name: Storybook
|
|
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-24.04-16' || 'ubuntu-latest' }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
name: Checkout
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
|
|
name: Install dependencies
|
|
with:
|
|
run_install: true
|
|
cache: true
|
|
|
|
- run: pnpm storybook:build
|
|
working-directory: site/
|
|
name: Build Storybook
|
|
|
|
- run: pnpm playwright:install
|
|
working-directory: site/
|
|
name: Install Chromium
|
|
|
|
- run: pnpm pixel-storybook
|
|
working-directory: site/
|
|
name: Snapshot
|
|
env:
|
|
PIXEL_KEY: ${{ secrets.PIXEL_KEY }}
|
|
|
|
# Reference guide:
|
|
# https://www.chromatic.com/docs/turbosnap-best-practices/#run-with-caution-when-using-the-pull_request-event
|
|
chromatic:
|
|
# REMARK: this is only used to build storybook and deploy it to Chromatic.
|
|
runs-on: ubuntu-latest
|
|
needs: changes
|
|
if: needs.changes.outputs.site == 'true' || needs.changes.outputs.ci == 'true'
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
# 👇 Ensures Chromatic can read your full git history
|
|
fetch-depth: 0
|
|
# 👇 Tells the checkout which commit hash to reference
|
|
ref: ${{ github.event.pull_request.head.ref }}
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "node pnpm"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
# This step is not meant for mainline because any detected changes to
|
|
# storybook snapshots will require manual approval/review in order for
|
|
# the check to pass. This is desired in PRs, but not in mainline.
|
|
- name: Publish to Chromatic (non-mainline)
|
|
if: github.ref != 'refs/heads/main' && github.repository_owner == 'coder'
|
|
uses: chromaui/action@5c6ec06f45a2117a25f07b1bf2b2f3009233fac8 # v16.3.0
|
|
env:
|
|
NODE_OPTIONS: "--max_old_space_size=4096"
|
|
STORYBOOK: true
|
|
with:
|
|
# Do a fast, testing build for change previews
|
|
buildScriptName: "storybook:ci"
|
|
exitOnceUploaded: true
|
|
# This will prevent CI from failing when Chromatic detects visual changes
|
|
exitZeroOnChanges: true
|
|
# Chromatic states its fine to make this token public. See:
|
|
# https://www.chromatic.com/docs/github-actions#forked-repositories
|
|
projectToken: 695c25b6cb65
|
|
workingDir: "./site"
|
|
storybookBaseDir: "./site"
|
|
storybookConfigDir: "./site/.storybook"
|
|
# Prevent excessive build runs on minor version changes
|
|
skip: "@(renovate/**|dependabot/**)"
|
|
# Run TurboSnap to trace file dependencies to related stories
|
|
# and tell chromatic to only take snapshots of relevant stories
|
|
onlyChanged: true
|
|
# Avoid uploading single files, because that's very slow
|
|
zip: true
|
|
|
|
# This is a separate step for mainline only that auto accepts and changes
|
|
# instead of holding CI up. Since we squash/merge, this is defensive to
|
|
# avoid the same changeset from requiring review once squashed into
|
|
# main. Chromatic is supposed to be able to detect that we use squash
|
|
# commits, but it's good to be defensive in case, otherwise CI remains
|
|
# infinitely "in progress" in mainline unless we re-review each build.
|
|
- name: Publish to Chromatic (mainline)
|
|
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
|
|
uses: chromaui/action@5c6ec06f45a2117a25f07b1bf2b2f3009233fac8 # v16.3.0
|
|
env:
|
|
NODE_OPTIONS: "--max_old_space_size=4096"
|
|
STORYBOOK: true
|
|
with:
|
|
autoAcceptChanges: true
|
|
# This will prevent CI from failing when Chromatic detects visual changes
|
|
exitZeroOnChanges: true
|
|
# Do a full build with documentation for mainline builds
|
|
buildScriptName: "storybook:build"
|
|
projectToken: 695c25b6cb65
|
|
workingDir: "./site"
|
|
storybookBaseDir: "./site"
|
|
storybookConfigDir: "./site/.storybook"
|
|
# Run TurboSnap to trace file dependencies to related stories
|
|
# and tell chromatic to only take snapshots of relevant stories
|
|
onlyChanged: true
|
|
# Avoid uploading single files, because that's very slow
|
|
zip: true
|
|
|
|
offlinedocs:
|
|
name: offlinedocs
|
|
needs: changes
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
if: needs.changes.outputs.offlinedocs == 'true' || needs.changes.outputs.ci == 'true' || needs.changes.outputs.docs == 'true'
|
|
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
# 0 is required here for version.sh to work.
|
|
fetch-depth: 0
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go node pnpm protoc protoc-gen-go"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
with:
|
|
directory: offlinedocs
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:storj.io/drpc/cmd/protoc-gen-go-drpc go:github.com/coder/sqlc/cmd/sqlc
|
|
|
|
- name: Format
|
|
run: |
|
|
cd offlinedocs
|
|
pnpm format:check
|
|
|
|
- name: Lint
|
|
run: |
|
|
cd offlinedocs
|
|
pnpm lint
|
|
|
|
- name: Build
|
|
# no `-j` flag as `make` fails with:
|
|
# coderd/rbac/object_gen.go:1:1: syntax error: package statement must be first
|
|
run: |
|
|
make build/coder_docs_"$(./scripts/version.sh)".tgz
|
|
|
|
- name: Check for unstaged files
|
|
run: ./scripts/check_unstaged.sh
|
|
|
|
required:
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- changes
|
|
- fmt
|
|
- lint
|
|
- lint-docs
|
|
- lint-actions
|
|
- gen
|
|
- test-go-pg
|
|
- test-go-pg-17
|
|
- test-go-race-pg
|
|
- test-js
|
|
- test-e2e
|
|
- offlinedocs
|
|
- sqlc-vet
|
|
- check-build
|
|
# Allow this job to run even if the needed jobs fail, are skipped or
|
|
# cancelled.
|
|
if: always()
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Ensure required checks
|
|
run: | # zizmor: ignore[template-injection] We're just reading needs.x.result here, no risk of injection
|
|
echo "Checking required checks"
|
|
echo "- changes: ${{ needs.changes.result }}"
|
|
echo "- fmt: ${{ needs.fmt.result }}"
|
|
echo "- lint: ${{ needs.lint.result }}"
|
|
echo "- lint-docs: ${{ needs.lint-docs.result }}"
|
|
echo "- lint-actions: ${{ needs.lint-actions.result }}"
|
|
echo "- gen: ${{ needs.gen.result }}"
|
|
echo "- test-go-pg: ${{ needs.test-go-pg.result }}"
|
|
echo "- test-go-pg-17: ${{ needs.test-go-pg-17.result }}"
|
|
echo "- test-go-race-pg: ${{ needs.test-go-race-pg.result }}"
|
|
echo "- test-js: ${{ needs.test-js.result }}"
|
|
echo "- test-e2e: ${{ needs.test-e2e.result }}"
|
|
echo "- offlinedocs: ${{ needs.offlinedocs.result }}"
|
|
echo "- check-build: ${{ needs.check-build.result }}"
|
|
echo
|
|
|
|
# We allow skipped jobs to pass, but not failed or cancelled jobs.
|
|
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" || "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
|
|
echo "One of the required checks has failed or has been cancelled"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Required checks have passed"
|
|
|
|
check-build:
|
|
# This job runs make build to verify compilation on PRs.
|
|
# The build doesn't get signed, and is not suitable for usage, unlike the
|
|
# `build` job that runs on main.
|
|
needs: changes
|
|
if: needs.changes.outputs.go == 'true' && github.ref != 'refs/heads/main'
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
persist-credentials: false
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go node pnpm"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:github.com/tc-hib/go-winres go:github.com/goreleaser/nfpm/v2/cmd/nfpm
|
|
|
|
- name: Install zstd
|
|
run: sudo apt-get install -y zstd
|
|
|
|
- name: Build
|
|
run: |
|
|
set -euxo pipefail
|
|
./.github/scripts/retry.sh -- go mod download
|
|
make gen/mark-fresh
|
|
make build
|
|
|
|
build:
|
|
# This builds and publishes ghcr.io/coder/coder-preview:main for each commit
|
|
# to main branch.
|
|
needs:
|
|
- changes
|
|
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) && needs.changes.outputs.docs-only == 'false' && !github.event.pull_request.head.repo.fork
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-22.04' }}
|
|
permissions:
|
|
# Necessary to push docker images to ghcr.io.
|
|
packages: write
|
|
# Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage)
|
|
# Also necessary for keyless cosign (https://docs.sigstore.dev/cosign/signing/overview/)
|
|
# And for GitHub Actions attestation
|
|
id-token: write
|
|
# Required for GitHub Actions attestation
|
|
attestations: write
|
|
env:
|
|
DOCKER_CLI_EXPERIMENTAL: "enabled"
|
|
outputs:
|
|
IMAGE: ghcr.io/coder/coder-preview:${{ steps.build-docker.outputs.tag }}
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
persist-credentials: false
|
|
|
|
- name: GHCR Login
|
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go node pnpm cosign syft"
|
|
|
|
- name: Install pnpm dependencies
|
|
uses: ./.github/actions/pnpm-install
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:github.com/tc-hib/go-winres go:github.com/goreleaser/nfpm/v2/cmd/nfpm
|
|
|
|
- name: Install rcodesign
|
|
run: |
|
|
set -euo pipefail
|
|
wget -O /tmp/rcodesign.tar.gz https://github.com/indygreg/apple-platform-rs/releases/download/apple-codesign%2F0.22.0/apple-codesign-0.22.0-x86_64-unknown-linux-musl.tar.gz
|
|
sudo tar -xzf /tmp/rcodesign.tar.gz \
|
|
-C /usr/bin \
|
|
--strip-components=1 \
|
|
apple-codesign-0.22.0-x86_64-unknown-linux-musl/rcodesign
|
|
rm /tmp/rcodesign.tar.gz
|
|
|
|
- name: Setup Apple Developer certificate
|
|
run: |
|
|
set -euo pipefail
|
|
touch /tmp/{apple_cert.p12,apple_cert_password.txt}
|
|
chmod 600 /tmp/{apple_cert.p12,apple_cert_password.txt}
|
|
echo "$AC_CERTIFICATE_P12_BASE64" | base64 -d > /tmp/apple_cert.p12
|
|
echo "$AC_CERTIFICATE_PASSWORD" > /tmp/apple_cert_password.txt
|
|
env:
|
|
AC_CERTIFICATE_P12_BASE64: ${{ secrets.AC_CERTIFICATE_P12_BASE64 }}
|
|
AC_CERTIFICATE_PASSWORD: ${{ secrets.AC_CERTIFICATE_PASSWORD }}
|
|
|
|
# Necessary for signing Windows binaries.
|
|
- name: Setup Java
|
|
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
|
|
with:
|
|
distribution: "zulu"
|
|
java-version: "11.0"
|
|
|
|
- name: Install zstd
|
|
run: sudo apt-get install -y zstd
|
|
|
|
- name: Setup Windows EV Signing Certificate
|
|
run: |
|
|
set -euo pipefail
|
|
touch /tmp/ev_cert.pem
|
|
chmod 600 /tmp/ev_cert.pem
|
|
echo "$EV_SIGNING_CERT" > /tmp/ev_cert.pem
|
|
wget https://github.com/ebourg/jsign/releases/download/6.0/jsign-6.0.jar -O /tmp/jsign-6.0.jar
|
|
env:
|
|
EV_SIGNING_CERT: ${{ secrets.EV_SIGNING_CERT }}
|
|
|
|
# Setup GCloud for signing Windows binaries.
|
|
- name: Authenticate to Google Cloud
|
|
id: gcloud_auth
|
|
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
|
|
with:
|
|
workload_identity_provider: ${{ vars.GCP_CODE_SIGNING_WORKLOAD_ID_PROVIDER }}
|
|
service_account: ${{ vars.GCP_CODE_SIGNING_SERVICE_ACCOUNT }}
|
|
token_format: "access_token"
|
|
|
|
- name: Setup GCloud SDK
|
|
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1
|
|
|
|
- name: Build
|
|
run: |
|
|
set -euxo pipefail
|
|
./.github/scripts/retry.sh -- go mod download
|
|
|
|
version="$(./scripts/version.sh)"
|
|
tag="main-${version//+/-}"
|
|
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
|
|
|
make gen/mark-fresh
|
|
make -j \
|
|
build/coder_linux_{amd64,arm64,armv7} \
|
|
build/coder_"$version"_windows_amd64.zip \
|
|
build/coder_"$version"_linux_{amd64,arm64,armv7}.{tar.gz,deb}
|
|
env:
|
|
# The Windows and Darwin slim binaries must be signed for Coder
|
|
# Desktop to accept them.
|
|
CODER_SIGN_WINDOWS: "1"
|
|
CODER_WINDOWS_RESOURCES: "1"
|
|
CODER_SIGN_GPG: "1"
|
|
CODER_GPG_RELEASE_KEY_BASE64: ${{ secrets.GPG_RELEASE_KEY_BASE64 }}
|
|
CODER_SIGN_DARWIN: "1"
|
|
AC_CERTIFICATE_FILE: /tmp/apple_cert.p12
|
|
AC_CERTIFICATE_PASSWORD_FILE: /tmp/apple_cert_password.txt
|
|
EV_KEY: ${{ secrets.EV_KEY }}
|
|
EV_KEYSTORE: ${{ secrets.EV_KEYSTORE }}
|
|
EV_TSA_URL: ${{ secrets.EV_TSA_URL }}
|
|
EV_CERTIFICATE_PATH: /tmp/ev_cert.pem
|
|
GCLOUD_ACCESS_TOKEN: ${{ steps.gcloud_auth.outputs.access_token }}
|
|
JSIGN_PATH: /tmp/jsign-6.0.jar
|
|
# Enable React profiling build and discoverable source maps
|
|
# for the dogfood deployment (dev.coder.com). This also
|
|
# applies to release/* branch builds, but those still
|
|
# produce coder-preview images, not release images.
|
|
# Release images are built by release.yaml (no profiling).
|
|
CODER_REACT_PROFILING: "true"
|
|
|
|
# Free up disk space before building Docker images. The preceding
|
|
# Build step produces ~2 GB of binaries and packages, the Go build
|
|
# cache is ~1.3 GB, and node_modules is ~500 MB. Docker image
|
|
# builds, pushes, and SBOM generation need headroom that isn't
|
|
# available without reclaiming some of that space.
|
|
- name: Clean up build cache
|
|
run: |
|
|
set -euxo pipefail
|
|
# Go caches are no longer needed — binaries are already compiled.
|
|
go clean -cache -modcache
|
|
# Remove .apk and .rpm packages that are not uploaded as
|
|
# artifacts and were only built as make prerequisites.
|
|
rm -f ./build/*.apk ./build/*.rpm
|
|
|
|
- name: Build Linux Docker images
|
|
id: build-docker
|
|
env:
|
|
CODER_IMAGE_BASE: ghcr.io/coder/coder-preview
|
|
DOCKER_CLI_EXPERIMENTAL: "enabled"
|
|
# Skip building .deb/.rpm/.apk/.tar.gz as prerequisites for
|
|
# the Docker image targets — they were already built above.
|
|
DOCKER_IMAGE_NO_PREREQUISITES: "true"
|
|
run: |
|
|
set -euxo pipefail
|
|
|
|
# build Docker images for each architecture
|
|
version="$(./scripts/version.sh)"
|
|
tag="${version//+/-}"
|
|
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
|
|
|
# build images for each architecture
|
|
# note: omitting the -j argument to avoid race conditions when pushing
|
|
make build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
|
|
|
|
# only push if we are on main branch or release branch
|
|
if [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == refs/heads/release/* ]]; then
|
|
# build and push multi-arch manifest, this depends on the other images
|
|
# being pushed so will automatically push them
|
|
# note: omitting the -j argument to avoid race conditions when pushing
|
|
make push/build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
|
|
|
|
# Define specific tags
|
|
tags=("$tag")
|
|
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then
|
|
tags+=("main" "latest")
|
|
elif [[ "${GITHUB_REF}" == refs/heads/release/* ]]; then
|
|
tags+=("release-${GITHUB_REF#refs/heads/release/}")
|
|
fi
|
|
|
|
# Create and push a multi-arch manifest for each tag
|
|
# we are adding `latest` tag and keeping `main` for backward
|
|
# compatibality
|
|
for t in "${tags[@]}"; do
|
|
echo "Pushing multi-arch manifest for tag: $t"
|
|
# shellcheck disable=SC2046
|
|
./scripts/build_docker_multiarch.sh \
|
|
--push \
|
|
--target "ghcr.io/coder/coder-preview:$t" \
|
|
--version "$version" \
|
|
$(cat build/coder_"$version"_linux_{amd64,arm64,armv7}.tag)
|
|
done
|
|
fi
|
|
|
|
- name: SBOM Generation and Attestation
|
|
if: github.ref == 'refs/heads/main'
|
|
continue-on-error: true
|
|
env:
|
|
COSIGN_EXPERIMENTAL: 1
|
|
BUILD_TAG: ${{ steps.build-docker.outputs.tag }}
|
|
run: |
|
|
set -euxo pipefail
|
|
|
|
# Define image base and tags
|
|
IMAGE_BASE="ghcr.io/coder/coder-preview"
|
|
TAGS=("${BUILD_TAG}" "main" "latest")
|
|
|
|
# Generate and attest SBOM for each tag
|
|
for tag in "${TAGS[@]}"; do
|
|
IMAGE="${IMAGE_BASE}:${tag}"
|
|
SBOM_FILE="coder_sbom_${tag//[:\/]/_}.spdx.json"
|
|
|
|
echo "Generating SBOM for image: ${IMAGE}"
|
|
syft "${IMAGE}" -o spdx-json > "${SBOM_FILE}"
|
|
|
|
echo "Attesting SBOM to image: ${IMAGE}"
|
|
cosign clean --force=true "${IMAGE}"
|
|
cosign attest --type spdxjson \
|
|
--predicate "${SBOM_FILE}" \
|
|
--yes \
|
|
"${IMAGE}"
|
|
done
|
|
|
|
- name: Resolve Docker image digests for attestation
|
|
id: docker_digests
|
|
if: github.ref == 'refs/heads/main'
|
|
continue-on-error: true
|
|
env:
|
|
IMAGE_BASE: ghcr.io/coder/coder-preview
|
|
BUILD_TAG: ${{ steps.build-docker.outputs.tag }}
|
|
run: |
|
|
set -euxo pipefail
|
|
main_digest=$(docker buildx imagetools inspect --raw "${IMAGE_BASE}:main" | sha256sum | awk '{print "sha256:"$1}')
|
|
echo "main_digest=${main_digest}" >> "$GITHUB_OUTPUT"
|
|
latest_digest=$(docker buildx imagetools inspect --raw "${IMAGE_BASE}:latest" | sha256sum | awk '{print "sha256:"$1}')
|
|
echo "latest_digest=${latest_digest}" >> "$GITHUB_OUTPUT"
|
|
version_digest=$(docker buildx imagetools inspect --raw "${IMAGE_BASE}:${BUILD_TAG}" | sha256sum | awk '{print "sha256:"$1}')
|
|
echo "version_digest=${version_digest}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: GitHub Attestation for Docker image
|
|
id: attest_main
|
|
if: github.ref == 'refs/heads/main' && steps.docker_digests.outputs.main_digest != ''
|
|
continue-on-error: true
|
|
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
|
|
with:
|
|
subject-name: ghcr.io/coder/coder-preview
|
|
subject-digest: ${{ steps.docker_digests.outputs.main_digest }}
|
|
push-to-registry: true
|
|
|
|
- name: GitHub Attestation for Docker image (latest tag)
|
|
id: attest_latest
|
|
if: github.ref == 'refs/heads/main' && steps.docker_digests.outputs.latest_digest != ''
|
|
continue-on-error: true
|
|
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
|
|
with:
|
|
subject-name: ghcr.io/coder/coder-preview
|
|
subject-digest: ${{ steps.docker_digests.outputs.latest_digest }}
|
|
push-to-registry: true
|
|
|
|
- name: GitHub Attestation for version-specific Docker image
|
|
id: attest_version
|
|
if: github.ref == 'refs/heads/main' && steps.docker_digests.outputs.version_digest != ''
|
|
continue-on-error: true
|
|
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4.1.0
|
|
with:
|
|
subject-name: ghcr.io/coder/coder-preview
|
|
subject-digest: ${{ steps.docker_digests.outputs.version_digest }}
|
|
push-to-registry: true
|
|
|
|
# Report attestation failures but don't fail the workflow
|
|
- name: Check attestation status
|
|
if: github.ref == 'refs/heads/main'
|
|
run: | # zizmor: ignore[template-injection] We're just reading steps.attest_x.outcome here, no risk of injection
|
|
if [[ "${{ steps.attest_main.outcome }}" == "failure" ]]; then
|
|
echo "::warning::GitHub attestation for main tag failed"
|
|
fi
|
|
if [[ "${{ steps.attest_latest.outcome }}" == "failure" ]]; then
|
|
echo "::warning::GitHub attestation for latest tag failed"
|
|
fi
|
|
if [[ "${{ steps.attest_version.outcome }}" == "failure" ]]; then
|
|
echo "::warning::GitHub attestation for version-specific tag failed"
|
|
fi
|
|
|
|
- name: Prune old images
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: vlaurin/action-ghcr-prune@0cf7d39f88546edd31965acba78cdcb0be14d641 # v0.6.0
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
organization: coder
|
|
container: coder-preview
|
|
keep-younger-than: 7 # days
|
|
keep-tags: latest
|
|
keep-tags-regexes: ^pr
|
|
prune-tags-regexes: |
|
|
^main-
|
|
^v
|
|
prune-untagged: true
|
|
|
|
- name: Upload build artifact (coder-linux-amd64.tar.gz)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coder-linux-amd64.tar.gz
|
|
path: ./build/*_linux_amd64.tar.gz
|
|
retention-days: 7
|
|
|
|
- name: Upload build artifact (coder-linux-amd64.deb)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coder-linux-amd64.deb
|
|
path: ./build/*_linux_amd64.deb
|
|
retention-days: 7
|
|
|
|
- name: Upload build artifact (coder-linux-arm64.tar.gz)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coder-linux-arm64.tar.gz
|
|
path: ./build/*_linux_arm64.tar.gz
|
|
retention-days: 7
|
|
|
|
- name: Upload build artifact (coder-linux-arm64.deb)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coder-linux-arm64.deb
|
|
path: ./build/*_linux_arm64.deb
|
|
retention-days: 7
|
|
|
|
- name: Upload build artifact (coder-linux-armv7.tar.gz)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coder-linux-armv7.tar.gz
|
|
path: ./build/*_linux_armv7.tar.gz
|
|
retention-days: 7
|
|
|
|
- name: Upload build artifact (coder-linux-armv7.deb)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coder-linux-armv7.deb
|
|
path: ./build/*_linux_armv7.deb
|
|
retention-days: 7
|
|
|
|
- name: Upload build artifact (coder-windows-amd64.zip)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: coder-windows-amd64.zip
|
|
path: ./build/*_windows_amd64.zip
|
|
retention-days: 7
|
|
|
|
# Deploy is handled in deploy.yaml so we can apply concurrency limits.
|
|
deploy:
|
|
needs:
|
|
- changes
|
|
- build
|
|
if: |
|
|
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/'))
|
|
&& needs.changes.outputs.docs-only == 'false'
|
|
&& !github.event.pull_request.head.repo.fork
|
|
uses: ./.github/workflows/deploy.yaml
|
|
with:
|
|
image: ${{ needs.build.outputs.IMAGE }}
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
packages: write # to retag image as dogfood
|
|
|
|
# sqlc-vet runs a postgres docker container, runs Coder migrations, and then
|
|
# runs sqlc-vet to ensure all queries are valid. This catches any mistakes
|
|
# in migrations or sqlc queries that makes a query unable to be prepared.
|
|
sqlc-vet:
|
|
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
|
|
needs: changes
|
|
if: needs.changes.outputs.db == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 1
|
|
persist-credentials: false
|
|
- name: Set up mise tools
|
|
uses: ./.github/actions/setup-mise
|
|
with:
|
|
install-args: "go"
|
|
|
|
- name: Restore Go cache
|
|
uses: ./.github/actions/go-cache
|
|
|
|
- name: Install Go mise tools
|
|
run: ./.github/scripts/retry.sh -- mise install --locked go:github.com/coder/sqlc/cmd/sqlc
|
|
|
|
- name: Setup and run sqlc vet
|
|
run: |
|
|
make sqlc-vet
|
|
|
|
notify-slack-on-failure:
|
|
needs:
|
|
- required
|
|
runs-on: ubuntu-latest
|
|
if: failure() && github.ref == 'refs/heads/main'
|
|
|
|
steps:
|
|
- name: Send Slack notification
|
|
run: |
|
|
ESCAPED_PROMPT=$(printf "%s" "<@U09LQ75AHKR> $BLINK_CI_FAILURE_PROMPT" | jq -Rsa .)
|
|
curl -X POST -H 'Content-type: application/json' \
|
|
--data '{
|
|
"blocks": [
|
|
{
|
|
"type": "header",
|
|
"text": {
|
|
"type": "plain_text",
|
|
"text": "❌ CI Failure in main",
|
|
"emoji": true
|
|
}
|
|
},
|
|
{
|
|
"type": "section",
|
|
"text": {
|
|
"type": "mrkdwn",
|
|
"text": "*View failure:* <'"${RUN_URL}"'|Click here>"
|
|
}
|
|
},
|
|
{
|
|
"type": "section",
|
|
"text": {
|
|
"type": "mrkdwn",
|
|
"text": '"$ESCAPED_PROMPT"'
|
|
}
|
|
}
|
|
]
|
|
}' "${SLACK_WEBHOOK}"
|
|
env:
|
|
SLACK_WEBHOOK: ${{ secrets.CI_FAILURE_SLACK_WEBHOOK }}
|
|
RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
|
BLINK_CI_FAILURE_PROMPT: ${{ vars.BLINK_CI_FAILURE_PROMPT }}
|