diff --git a/.github/actions/aws-cli/DEPRECATED.md b/.github/actions/aws-cli/DEPRECATED.md new file mode 100644 index 0000000..36be8d2 --- /dev/null +++ b/.github/actions/aws-cli/DEPRECATED.md @@ -0,0 +1,42 @@ +# Deprecated + +This composite action is deprecated and will be removed after the RFC-001 §7 grace period. It remains functional in the interim and now emits a `::warning::` on every run. + +## Why + +The action's public contract is "run any AWS CLI command passed as a string". That shape is an arbitrary-command runner dressed up as a helper: historically it also interpolated the input directly into the `run:` body at YAML-expansion time, which allowed callers who passed untrusted strings through `command` to break out of the intended AWS invocation and execute arbitrary shell in a job that had already assumed AWS credentials. The YAML-paste injection has been closed (inputs now travel via `env:`), but the underlying "run whatever the caller passes" shape remains unsafe by design. The right answer is to not have the composite at all. + +## Known regression during the grace period + +Closing the YAML-paste hole means the action now word-splits `command` through POSIX shell rules only. **Quoted arguments no longer work:** passing `command: '--bucket "my bucket" --key foo'` sends `--bucket`, `"my`, `bucket"`, `--key`, `foo` to the CLI. In the legacy implementation YAML + shell double-interpretation happened to parse the quotes correctly. Callers that rely on quoted arguments should migrate to the recommended replacement **now** rather than wait for the 180-day removal; the replacement (writing your own `run:` step) preserves the usual shell quoting rules. + +## Replacement + +Assume credentials with [`aws-auth`](../aws-auth) and then write your own explicit `run:` step. Arguments stay as literal shell tokens — no composite wrapping, no indirection, no interpolation surface. + +```yaml +- uses: dvsa/.github/.github/actions/aws-auth@v7 + with: + aws_role: ${{ vars.AWS_DEPLOY_ROLE }} + aws_account_id: ${{ vars.AWS_ACCOUNT_ID }} + aws_region: ${{ vars.AWS_REGION }} + +- name: List S3 buckets + shell: bash + run: aws s3 ls +``` + +For the narrow cases where the composite was genuinely useful (parameterising a single command across many jobs), either call a purpose-specific reusable workflow in `dvsa/.github/.github/workflows/` (e.g. `update-lambda-function.yaml`) or write a thin service-specific composite that takes structured inputs, not a shell string. + +## Timeline + +| When | What | +| --------------------------------- | ------------------------------------------------------------------------ | +| This change merges | Every run of `aws-cli` emits a deprecation `::warning::`. | +| T+180 days (per RFC-001 §7) | Follow-up PR removes the action. | + +If you maintain a caller still pinned to this action, open an issue on `dvsa/.github` with the label `migration` so we can help you move. + +## Related + +- `dvsa/appdev-github-actions/.github/actions/assume-and-run-aws` — bundled role-assumption + CLI runner, also deprecated (`DEPRECATED.md` in that repo). Previously named as the replacement pair alongside this action; the actual replacement for both is `aws-auth` + your own `run:`. diff --git a/.github/actions/aws-cli/README.md b/.github/actions/aws-cli/README.md index c8dcabb..cbcbcc4 100644 --- a/.github/actions/aws-cli/README.md +++ b/.github/actions/aws-cli/README.md @@ -1,22 +1,49 @@ -# AWS CLI -Action to provide ability to run AWS CLI command +# aws-cli (deprecated) -#### Prerequisites -Authenticated with AWS Account +**This action is deprecated — see [DEPRECATED.md](DEPRECATED.md).** Prefer writing a plain `run: aws …` step after the [`aws-auth`](../aws-auth) composite. The action remains available during the RFC-001 §7 grace period and emits a `::warning::` on every run. -#### Context -This action allows the workflow to interact with AWS the CLI. +## What it does (for existing callers) -#### Inputs -command (required): Command to be invoked by AWS CLI. +Runs `aws` with the supplied argument string on a runner that already has AWS credentials established (typically by a prior `aws-auth` step). -#### Outputs -N/A +#### Prerequisites + +Caller has already configured AWS credentials — this action does **not** assume a role. + +#### Inputs + +| Input | Required | Description | +| --------- | -------- | --------------------------------------------------------------------------- | +| `command` | yes | Argument string passed to the `aws` CLI. MUST come from a trusted source. | + +#### Outputs + +None. + +#### Legacy usage -#### Usage ```yaml -- name: List S3 Buckets - uses: dvsa/.github/.github/actions/aws-cli@v7 +- uses: dvsa/.github/.github/actions/aws-auth@v7 + with: + aws_role: ${{ vars.AWS_DEPLOY_ROLE }} + aws_account_id: ${{ vars.AWS_ACCOUNT_ID }} + aws_region: ${{ vars.AWS_REGION }} + +- uses: dvsa/.github/.github/actions/aws-cli@v7 with: command: "s3 ls" ``` + +#### Recommended replacement + +```yaml +- uses: dvsa/.github/.github/actions/aws-auth@v7 + with: + aws_role: ${{ vars.AWS_DEPLOY_ROLE }} + aws_account_id: ${{ vars.AWS_ACCOUNT_ID }} + aws_region: ${{ vars.AWS_REGION }} + +- name: List S3 buckets + shell: bash + run: aws s3 ls +``` diff --git a/.github/actions/aws-cli/action.yml b/.github/actions/aws-cli/action.yml index b99ca23..e19b70d 100644 --- a/.github/actions/aws-cli/action.yml +++ b/.github/actions/aws-cli/action.yml @@ -1,17 +1,48 @@ name: aws-cli +# DEPRECATED. See DEPRECATED.md in this directory. The replacement is to write +# your own `run: aws …` step after assuming credentials with the `aws-auth` +# composite. This action will be removed after the RFC-001 §7 grace period. +# +# Security notes for the remaining grace-period callers: +# - Inputs are passed via `env:`, not YAML-interpolated into the `run:` +# body, so a value containing shell metacharacters can no longer escape +# out of the step at YAML-expansion time. The step is still an arbitrary +# AWS CLI runner by design; callers MUST NOT pass untrusted strings +# (PR titles, issue bodies, workflow_dispatch inputs sourced from +# untrusted actors, etc.) through `command`. +# - The action no longer runs `actions/checkout`. Callers that need the +# working tree must check out the repo themselves in a prior step. +# - Quoted arguments regress during the grace period: `--bucket "my bucket"` +# word-splits into literal quotes. See DEPRECATED.md. Callers relying on +# quoted args should migrate to the plain `run: aws …` replacement now. + inputs: command: type: string - description: Command to be invoked by AWS CLI + description: Arguments to pass to `aws` (deprecated — write your own `run: aws …` step after aws-auth instead). required: true runs: using: 'composite' steps: - - name: Checkout code - uses: actions/checkout@v7 + - name: Deprecation warning + shell: bash + run: | + echo "::warning title=Deprecated action::" \ + "dvsa/.github/.github/actions/aws-cli is deprecated. Replace it with a " \ + "'run: aws …' step after dvsa/.github/.github/actions/aws-auth. " \ + "See .github/actions/aws-cli/DEPRECATED.md." - name: Invoke AWS CLI command - run: aws ${{ inputs.command }} shell: bash + env: + AWS_CLI_ARGS: ${{ inputs.command }} + run: | + set -euo pipefail + # Intentional unquoted expansion: callers pass a single string of + # space-separated args, and the historical API relies on shell + # word-splitting to break them apart. This kills the YAML-paste + # injection class (shellcheck SC2086 is expected). + # shellcheck disable=SC2086 + aws $AWS_CLI_ARGS diff --git a/.github/actions/check-s3/README.md b/.github/actions/check-s3/README.md new file mode 100644 index 0000000..0f08019 --- /dev/null +++ b/.github/actions/check-s3/README.md @@ -0,0 +1,44 @@ +# check-s3 + +Check whether an object (or any object of a given type) exists in an S3 bucket. Emits two outputs: `s3_existence` for a basic `aws s3 ls s3://bucket/path` listing, and `file_existence` for the most recent object whose key **contains** `path` **and ends with** `file_type`. The latest matching object's URL is appended to `GITHUB_STEP_SUMMARY`. + +Migrated from `dvsa/appdev-github-actions` (the `check_s3` composite) in Nov 2026; renamed to kebab-case to match sibling composites in this repo. + +Requires AWS credentials to be configured on the runner first — use `dvsa/.github/.github/actions/aws-auth@v7` beforehand. + +> **Filter semantics.** `s3_existence` is a prefix check (that's how `aws s3 ls` matches). `file_existence` uses JMESPath `contains(Key, …)`, which matches `path` anywhere in the key — not only as a prefix. If two environments share a key segment (e.g. `releases/` and `historic/releases/`) you'll get hits from both. Pass a sufficiently unique `path` or add your own uniqueness suffix. + +## Inputs + +| Input | Required | Description | +| ----------- | -------- | ------------------------------------------------------------------------- | +| `bucket` | yes | S3 bucket name. | +| `path` | yes | Substring that must appear in the object key (not strictly a prefix). | +| `file_type` | yes | Suffix the object key must end with (e.g. `.zip`). | + +## Outputs + +| Output | Description | +| ----------------- | ---------------------------------------------------------------- | +| `s3_existence` | `YES` if the prefix returns any listing, `NO` otherwise. | +| `file_existence` | `YES` if the latest matching file was found, `NO` otherwise. | + +## Example + +```yaml +- uses: dvsa/.github/.github/actions/aws-auth@v7 + with: + aws_role: github-actions-read + aws_account_id: ${{ vars.AWS_ACCOUNT_ID }} + aws_region: eu-west-1 + +- id: check + uses: dvsa/.github/.github/actions/check-s3@v7 + with: + bucket: my-bucket + path: releases/v1.2.3/ + file_type: .zip + +- if: steps.check.outputs.file_existence == 'YES' + run: echo "Found the release artifact." +``` diff --git a/.github/actions/check-s3/action.yml b/.github/actions/check-s3/action.yml new file mode 100644 index 0000000..e7fab27 --- /dev/null +++ b/.github/actions/check-s3/action.yml @@ -0,0 +1,64 @@ +name: 'Check S3 for Artefacts' +description: 'Check whether a prefix (and optionally a matching object) exists in an S3 bucket.' + +inputs: + bucket: + required: true + description: 'The S3 Bucket to check' + path: + required: true + description: 'The path prefix to check in the bucket' + file_type: + required: true + description: 'The file extension/suffix the object must end with (e.g. ".zip")' + +outputs: + s3_existence: + description: 'YES if the prefix returns any listing, NO otherwise.' + value: ${{ steps.s3_path.outputs.existence }} + file_existence: + description: 'YES if a matching object was found, NO otherwise.' + value: ${{ steps.s3_file.outputs.existence }} + +runs: + using: 'composite' + steps: + - name: Check S3 path exists + id: s3_path + shell: bash + env: + BUCKET: ${{ inputs.bucket }} + PATH_PREFIX: ${{ inputs.path }} + run: | + set -euo pipefail + if aws s3 ls "s3://${BUCKET}/${PATH_PREFIX}" >/dev/null 2>&1; then + echo "existence=YES" >> "$GITHUB_OUTPUT" + else + echo "existence=NO" >> "$GITHUB_OUTPUT" + fi + + - name: Check S3 file exists + id: s3_file + shell: bash + env: + BUCKET: ${{ inputs.bucket }} + PATH_PREFIX: ${{ inputs.path }} + FILE_TYPE: ${{ inputs.file_type }} + run: | + set -euo pipefail + # Build the JMESPath filter via jq --arg + tojson so the user-supplied + # strings land inside the query as JSON-quoted literals (backticks in + # JMESPath require JSON values, not raw strings — raw text fails to + # parse). This also neutralises injection into the --query expression. + query=$(jq -nr --arg p "$PATH_PREFIX" --arg t "$FILE_TYPE" \ + '"Contents[?contains(Key, `\($p | tojson)`) && ends_with(Key, `\($t | tojson)`)].{Key:Key,LastModified:LastModified}"') + object=$(aws s3api list-objects-v2 \ + --bucket "$BUCKET" \ + --query "$query" \ + --output json | jq -r 'sort_by(.LastModified) | last | .Key // "null"') + if [ "$object" != "null" ] && [ -n "$object" ]; then + echo "existence=YES" >> "$GITHUB_OUTPUT" + echo "Object Found: https://${BUCKET}.s3.eu-west-1.amazonaws.com/${object}" >> "$GITHUB_STEP_SUMMARY" + else + echo "existence=NO" >> "$GITHUB_OUTPUT" + fi diff --git a/.github/actions/notify-teams/README.md b/.github/actions/notify-teams/README.md new file mode 100644 index 0000000..17c812e --- /dev/null +++ b/.github/actions/notify-teams/README.md @@ -0,0 +1,15 @@ +# notify-teams + +Send an Adaptive Card notification to a Microsoft Teams Incoming Webhook. + +Migrated from `dvsa/appdev-github-actions` (`notify-teams` composite) in Nov 2026 to consolidate DVSA central actions. + +## Example + +```yaml +- uses: dvsa/.github/.github/actions/notify-teams@v7 + with: + webhook_url: ${{ secrets.TEAMS_WEBHOOK_URL }} + title: 'Deploy to prod' + status: 'success' +``` diff --git a/.github/actions/notify-teams/action.yml b/.github/actions/notify-teams/action.yml new file mode 100644 index 0000000..3fa0a45 --- /dev/null +++ b/.github/actions/notify-teams/action.yml @@ -0,0 +1,108 @@ +name: Send Teams Notification +description: 'Send an Adaptive Card notification to a Microsoft Teams channel via an Incoming Webhook.' + +inputs: + webhook_url: + description: 'The Teams Incoming Webhook URL. Must be a repository/environment secret.' + required: true + information: + description: 'Extended information rendered in the card (plain text).' + required: false + default: '' + ipa-link: + description: 'Optional URL to the built .ipa file to link from the card.' + required: false + default: '' + qr-link: + description: 'Optional URL to a QR code image for the .ipa download.' + required: false + default: '' + +runs: + using: 'composite' + steps: + - name: Microsoft Teams Notification + shell: bash + env: + WEBHOOK_URL: ${{ inputs.webhook_url }} + INFORMATION: ${{ inputs.information }} + IPA_LINK: ${{ inputs.ipa-link }} + QR_LINK: ${{ inputs.qr-link }} + JOB_STATUS: ${{ job.status }} + run: | + set -euo pipefail + + case "$JOB_STATUS" in + failure) COLOR=attention ;; + cancelled) COLOR=warning ;; + *) COLOR=good ;; + esac + + # Build the Adaptive Card payload with jq --arg so every value is + # JSON-escaped at the string boundary — no interpolation into the + # literal template, no injection via newlines/quotes in inputs. + PAYLOAD=$(jq -n \ + --arg status "$JOB_STATUS" \ + --arg color "$COLOR" \ + --arg information "$INFORMATION" \ + --arg repository "$GITHUB_REPOSITORY" \ + --arg workflow "$GITHUB_WORKFLOW" \ + --arg branch "$GITHUB_REF_NAME" \ + --arg actor "$GITHUB_ACTOR" \ + --arg run_url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ + --arg ipa_link "$IPA_LINK" \ + --arg qr_link "$QR_LINK" ' + def text($t): { type: "TextBlock", text: $t }; + def bold($t): { type: "TextBlock", size: "Large", weight: "Bolder", text: $t }; + + def openUrl($title; $url): + { type: "ActionSet", + actions: [ { type: "Action.OpenUrl", title: $title, url: $url } ] }; + + { + type: "message", + attachments: [{ + contentType: "application/vnd.microsoft.card.adaptive", + content: { + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + version: "1.4", + type: "AdaptiveCard", + body: [ + { type: "ColumnSet", + columns: [ + { width: "100px", + items: [ { type: "Image", + url: ("https://raw.githubusercontent.com/Skitionek/notify-microsoft-teams/master/icons/" + $status + ".png"), + size: "stretch" } ] }, + { width: "stretch", + verticalContentAlignment: "center", + items: ( + [ bold($workflow) ] + + ( if $information != "" then [ bold("Env & Version: " + $information) ] else [] end ) + + [ text("**Repository:** " + $repository), + text("**Branch:** " + $branch), + text("**Who:** " + $actor), + (text("**Status:** " + $status) + { color: $color }) ] + ) } + ] }, + { type: "ColumnSet", + columns: [ + ( if $qr_link != "" then + { width: "100px", + items: [ { type: "Image", url: $qr_link, size: "stretch" } ] } + else empty end ), + { width: "stretch", + items: ( + [ openUrl("View Workflow"; $run_url) ] + + ( if $ipa_link != "" then [ openUrl("Get .ipa file"; $ipa_link) ] else [] end ) + ) } + ] } + ] + } + }] + }') + + curl --fail --silent --show-error \ + -H "Content-Type: application/json" \ + --data-binary "$PAYLOAD" \ + "$WEBHOOK_URL" diff --git a/.github/workflows/ci-backend.yaml b/.github/workflows/ci-backend.yaml new file mode 100644 index 0000000..59f5be5 --- /dev/null +++ b/.github/workflows/ci-backend.yaml @@ -0,0 +1,142 @@ +name: Backend CI + +# Reusable workflow for DVSA Node/TypeScript backend services. +# Runs type-check, build, lint, and tests with coverage, then uploads the +# `artifacts/` directory for downstream consumers (e.g. deploy jobs). +# +# Invoke from a repo via: +# jobs: +# ci: +# uses: dvsa/.github/.github/workflows/ci-backend.yaml@v7 +# secrets: inherit + +on: + workflow_call: + inputs: + dynamodb: + description: Require an install of Serverless DynamoDB. + type: boolean + required: false + default: false + node-version: + description: Node version override. Empty uses the project's .nvmrc. + type: string + required: false + default: '' + coverage-summary-path: + description: Path to Jest coverage summary JSON for the job summary. + type: string + required: false + default: 'coverage/coverage-summary.json' + artifact-name: + description: >- + Name under which to upload the build artifact. Leave at the default + to get a per-run name, or pass a stable value (e.g. 'service-artifact') + so a downstream deploy workflow can download it by a known name. + type: string + required: false + default: '' + outputs: + artifact-name: + description: The actual name used when uploading the build artifact. + value: ${{ jobs.run-ci.outputs.artifact-name }} + secrets: + ACCESS_TOKEN: + description: GitHub token for private npm registry (GitHub Packages). + required: false + +permissions: + contents: read + +jobs: + run-ci: + name: Lint, test, build + runs-on: ubuntu-latest + timeout-minutes: 15 + outputs: + artifact-name: ${{ steps.artifact-name.outputs.name }} + + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Resolve artifact name + id: artifact-name + env: + OVERRIDE: ${{ inputs.artifact-name }} + REPO_NAME: ${{ github.event.repository.name }} + PR_OR_RUN: ${{ github.event.pull_request.number || github.run_id }} + run: | + if [ -n "$OVERRIDE" ]; then + printf 'name=%s\n' "$OVERRIDE" >> "$GITHUB_OUTPUT" + else + printf 'name=%s-artifacts-%s\n' "$REPO_NAME" "$PR_OR_RUN" >> "$GITHUB_OUTPUT" + fi + + - name: Install dependencies + uses: dvsa/.github/.github/actions/install-deps@v7 + with: + node-version: ${{ inputs.node-version }} + + - name: Configure npm authentication + if: ${{ env.ACCESS_TOKEN != '' }} + env: + ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + run: echo "//npm.pkg.github.com/:_authToken=$ACCESS_TOKEN" >> ~/.npmrc + + - name: Install Serverless DynamoDB + if: ${{ inputs.dynamodb }} + run: npx --yes serverless dynamodb install + + - name: TypeScript compile check + run: npx tsc --noEmit + + - name: Build and package + run: npm run package + + - name: Lint + run: | + if npm run | grep -qE '^ *lint$'; then + # Biome 2.x supports --reporter=github for inline PR annotations; + # fall back silently if the local script already sets a reporter. + npm run lint -- --reporter=github || npm run lint + else + echo "::warning::No lint script defined; skipping." + fi + + - name: Test with coverage + run: npm run test:coverage + + - name: Coverage summary + if: ${{ always() }} + env: + SUMMARY_PATH: ${{ inputs.coverage-summary-path }} + run: | + if [ ! -f "$SUMMARY_PATH" ]; then + echo "::warning::Coverage summary not found at $SUMMARY_PATH" + exit 0 + fi + read -r L F S B < <(node -e ' + const s=require(process.env.SUMMARY_PATH).total; + process.stdout.write([s.lines.pct, s.functions.pct, s.statements.pct, s.branches.pct].join(" ")); + ') + { + echo "## Test coverage" + echo + echo "| Metric | Covered |" + echo "| --- | ---: |" + echo "| Lines | ${L}% |" + echo "| Functions | ${F}% |" + echo "| Statements | ${S}% |" + echo "| Branches | ${B}% |" + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload artifacts + if: ${{ always() && hashFiles('artifacts/*') != '' }} + uses: actions/upload-artifact@v7 + with: + name: ${{ steps.artifact-name.outputs.name }} + retention-days: 5 + overwrite: true + path: | + artifacts/* diff --git a/.github/workflows/conventional-commits.yaml b/.github/workflows/conventional-commits.yaml index b2ef114..bb31688 100644 --- a/.github/workflows/conventional-commits.yaml +++ b/.github/workflows/conventional-commits.yaml @@ -19,6 +19,7 @@ jobs: check-pr-title: name: Check PR title runs-on: ubuntu-latest + timeout-minutes: 5 env: INPUT: ${{ inputs.title || github.event.pull_request.title }} steps: diff --git a/.github/workflows/deploy-docs.yaml b/.github/workflows/deploy-docs.yaml new file mode 100644 index 0000000..663b7f6 --- /dev/null +++ b/.github/workflows/deploy-docs.yaml @@ -0,0 +1,95 @@ +name: Deploy documentation + +# Reusable workflow for Docusaurus-style documentation hosted at /website +# with sources in /docs. Builds on every call; deploys to GitHub Pages when +# `deploy: true`. +# +# Invoke from a repo via: +# jobs: +# docs: +# uses: dvsa/.github/.github/workflows/deploy-docs.yaml@v7 +# with: +# deploy: ${{ github.ref == 'refs/heads/main' }} + +on: + workflow_call: + inputs: + deploy: + description: Whether to deploy to GitHub Pages. + required: true + type: boolean + default: false + working-directory: + description: Directory containing the Docusaurus site (package.json). + required: false + type: string + default: 'website' + sources: + description: Newline-separated sparse-checkout paths. + required: false + type: string + default: | + website + docs + build-command: + required: false + type: string + default: 'npm run build' + build-output: + description: Path to the built site, relative to working-directory. + required: false + type: string + default: 'build' + +permissions: + contents: read + +jobs: + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 10 + defaults: + run: + working-directory: ${{ inputs.working-directory }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + sparse-checkout: ${{ inputs.sources }} + + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: 'lts/*' + cache: npm + cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Build + run: ${{ inputs.build-command }} + + - name: Upload pages artefact + if: ${{ inputs.deploy }} + uses: actions/upload-pages-artifact@v3 + with: + path: ${{ inputs.working-directory }}/${{ inputs.build-output }} + + deploy: + name: Deploy + if: ${{ inputs.deploy }} + needs: [build] + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/deploy-serverless.yaml b/.github/workflows/deploy-serverless.yaml new file mode 100644 index 0000000..68c302b --- /dev/null +++ b/.github/workflows/deploy-serverless.yaml @@ -0,0 +1,163 @@ +name: Deploy Serverless Service + +# Reusable workflow for deploying a Serverless Framework (or CDK / direct +# AWS CLI) service across DVSA's standard 4-environment × 2-account layout: +# +# AWS account Environment +# ------------ ------------------ +# nonprod dev, int, prep +# prod prod +# +# Each environment is a GitHub Environment on the caller repo carrying three +# `vars`: AWS_ACCOUNT_ID, AWS_DEPLOY_ROLE, AWS_REGION +# plus any env-scoped secrets the deploy command needs. `prod` MUST have +# required reviewers (TSS) configured in the Environment protection rules. +# +# Invoke from a repo via: +# jobs: +# deploy-dev: +# uses: dvsa/.github/.github/workflows/deploy-serverless.yaml@v7 +# with: { environment: dev, artifact-name: service-artifact } +# secrets: inherit +# deploy-int: +# needs: deploy-dev +# uses: dvsa/.github/.github/workflows/deploy-serverless.yaml@v7 +# with: { environment: int, artifact-name: service-artifact } +# secrets: inherit +# deploy-prep: +# needs: deploy-int +# uses: dvsa/.github/.github/workflows/deploy-serverless.yaml@v7 +# with: { environment: prep, artifact-name: service-artifact } +# secrets: inherit +# deploy-prod: +# needs: deploy-prep +# uses: dvsa/.github/.github/workflows/deploy-serverless.yaml@v7 +# with: { environment: prod, artifact-name: service-artifact } +# secrets: inherit + +on: + workflow_call: + inputs: + environment: + description: GitHub Environment name — dev, int, prep, or prod. + required: true + type: string + artifact-name: + description: Build artifact uploaded by CI. Empty = build in place. + required: false + type: string + default: '' + artifact-path: + description: Directory to unpack the artifact into. + required: false + type: string + default: 'artifacts' + artifact-run-id: + description: >- + Run ID that produced the artifact. Set to + `${{ github.event.workflow_run.id }}` when CD is `workflow_run` + triggered by a separate CI workflow — the default behaviour of + `actions/download-artifact` looks only at the current run. + required: false + type: string + default: '' + deploy-command: + description: Shell command executed to perform the deploy. + required: false + type: string + default: 'npx serverless deploy --stage ${{ inputs.environment }} --conceal' + node-version: + description: Node version override. Empty uses the project's .nvmrc. + required: false + type: string + default: '' + install-deps: + description: Whether to run npm ci before deploying. + required: false + type: boolean + default: true + secrets: + ACCESS_TOKEN: + description: GitHub token for private npm registry (GitHub Packages). + required: false + +permissions: + contents: read + id-token: write # OIDC assume-role + actions: read # needed when downloading an artifact from a different run + +jobs: + deploy: + name: Deploy to ${{ inputs.environment }} + runs-on: ubuntu-latest + timeout-minutes: 20 + environment: ${{ inputs.environment }} + + steps: + - name: Validate environment input + env: + ENV: ${{ inputs.environment }} + run: | + case "$ENV" in + dev|int|prep|prod) ;; + *) echo "::error::environment must be one of dev|int|prep|prod (got '$ENV')"; exit 1 ;; + esac + + - name: Checkout + uses: actions/checkout@v7 + + - name: Install dependencies + if: ${{ inputs.install-deps }} + uses: dvsa/.github/.github/actions/install-deps@v7 + with: + node-version: ${{ inputs.node-version }} + + - name: Configure npm authentication + if: ${{ inputs.install-deps && secrets.ACCESS_TOKEN != '' }} + env: + ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + run: echo "//npm.pkg.github.com/:_authToken=$ACCESS_TOKEN" >> ~/.npmrc + + - name: Download build artifact + if: ${{ inputs.artifact-name != '' }} + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.artifact-name }} + path: ${{ inputs.artifact-path }} + # Set run-id + github-token only when a caller is pulling from a + # different run (e.g. CD triggered by workflow_run on a prior CI + # run). Empty strings fall back to the current run's artifacts. + run-id: ${{ inputs.artifact-run-id }} + github-token: ${{ inputs.artifact-run-id != '' && secrets.GITHUB_TOKEN || '' }} + + - name: Assume AWS role (OIDC) + uses: dvsa/.github/.github/actions/aws-auth@v7 + with: + aws_role: ${{ vars.AWS_DEPLOY_ROLE }} + aws_account_id: ${{ vars.AWS_ACCOUNT_ID }} + aws_region: ${{ vars.AWS_REGION }} + + - name: Deploy + env: + ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + run: ${{ inputs.deploy-command }} + + - name: Deploy summary + if: ${{ always() }} + env: + ENV: ${{ inputs.environment }} + STATUS: ${{ job.status }} + ACCOUNT: ${{ vars.AWS_ACCOUNT_ID }} + REGION: ${{ vars.AWS_REGION }} + SHA: ${{ github.sha }} + run: | + { + echo "## Deploy to \`$ENV\` — $STATUS" + echo + echo "| Field | Value |" + echo "| --- | --- |" + echo "| AWS account | \`$ACCOUNT\` |" + echo "| Region | \`$REGION\` |" + echo "| Commit | \`$SHA\` |" + echo "| Actor | @${{ github.actor }} |" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/nodejs-security.yaml b/.github/workflows/nodejs-security.yaml index f4e3e93..eb4632e 100644 --- a/.github/workflows/nodejs-security.yaml +++ b/.github/workflows/nodejs-security.yaml @@ -1,4 +1,4 @@ -name: Synk Security run +name: Snyk Security run on: workflow_call: inputs: @@ -16,10 +16,14 @@ on: jobs: security: runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@v7 - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/node@master + # Pinned to v1 (the only semver-tagged release of snyk/actions); + # Snyk historically only publishes @master, but v1 is a stable + # synonym and matches RFC-001 §3.6 (no floating default-branch refs). + uses: snyk/actions/node@v1 continue-on-error: ${{ inputs.continue-on-error }} env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} diff --git a/.github/workflows/release-please-call.yaml b/.github/workflows/release-please-call.yaml new file mode 100644 index 0000000..0e6ada4 --- /dev/null +++ b/.github/workflows/release-please-call.yaml @@ -0,0 +1,73 @@ +name: Release Please (callable) + +# Reusable `workflow_call` variant of release-please for repos that want to +# orchestrate release-please from their own ci.yml / cd.yml rather than let +# this repo's own `release-please.yaml` run on `push: main`. Both coexist. +# +# Invoke from a repo via: +# jobs: +# release: +# uses: dvsa/.github/.github/workflows/release-please-call.yaml@v7 +# with: +# target-branch: ${{ github.ref_name }} +# permissions: +# contents: write +# pull-requests: write + +on: + workflow_call: + inputs: + target-branch: + description: Branch to release from. + required: true + type: string + default: 'main' + release-type: + description: release-please release-type. + required: false + type: string + default: 'node' + config-file: + description: Optional release-please config file path. + required: false + type: string + default: '' + manifest-file: + description: Optional release-please manifest file path. + required: false + type: string + default: '' + outputs: + release_created: + value: ${{ jobs.release-please.outputs.release_created }} + tag_name: + value: ${{ jobs.release-please.outputs.tag_name }} + +jobs: + release-please: + name: Release + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write + pull-requests: write + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} + steps: + - uses: actions/checkout@v7 + + - name: Ensure labels exist + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh label create "autorelease: tagged" --color ededed --force + gh label create "autorelease: pending" --color ededed --force + + - uses: googleapis/release-please-action@v5 + id: release + with: + release-type: ${{ inputs.release-type }} + target-branch: ${{ inputs.target-branch }} + config-file: ${{ inputs.config-file }} + manifest-file: ${{ inputs.manifest-file }}