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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ updates:
directory: "/"
schedule:
interval: "weekly"

# Workflow actions are pinned to commit SHAs; this keeps the pins current
# with one grouped PR a week.
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
actions:
patterns: ["*"]
2 changes: 1 addition & 1 deletion .github/workflows/dev_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Shell files are LF
run: |
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ concurrency:
group: api-docs
cancel-in-progress: false

# Least privilege for the workflow token. A job that needs more asks for it
# in its own permissions block.
permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24.x
- run: npm ci
- run: npm run docs

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./docs
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
node-version: [24.x]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand Down
38 changes: 38 additions & 0 deletions src/__tests__/workflows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {describe, it, expect} from 'vitest';
import {readdirSync, readFileSync} from 'node:fs';
import {fileURLToPath} from 'node:url';
import {dirname, resolve} from 'node:path';

/**
* The shape of the GitHub workflows.
*
* Actions are pinned to a commit SHA with the tag in a trailing comment: a tag
* can be moved to different code, a SHA cannot. Dependabot's github-actions
* entry moves SHA and comment together in one grouped PR a week.
*/
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
const DIR = resolve(ROOT, '.github/workflows');
const files = readdirSync(DIR).filter((f) => /\.ya?ml$/.test(f));
const read = (f: string) => readFileSync(resolve(DIR, f), 'utf8');

const usesLines = (src: string) =>
src.split('\n').filter((l) => /^\s*(- )?uses:/.test(l) && !/uses:\s*(\.\/|docker:\/\/)/.test(l));
const PINNED = /uses: [\w.-]+\/[\w./-]+@[0-9a-f]{40} # \S+$/;

describe('workflows', () => {
it.each(files)('%s pins every action to a commit SHA, with the ref in a comment', (f) => {
const uses = usesLines(read(f));
expect(uses.length).toBeGreaterThan(0);
for (const l of uses) expect(l, l).toMatch(PINNED);
});

it.each(files)('%s gives the workflow token read access only', (f) => {
expect(read(f)).toMatch(/^permissions:\n {2}contents: read\n/m);
expect(read(f)).not.toMatch(/:\s*write\b/);
});

it('Dependabot keeps the pinned actions current', () => {
const cfg = readFileSync(resolve(ROOT, '.github/dependabot.yml'), 'utf8');
expect(cfg).toMatch(/package-ecosystem: "github-actions"\n\s+directory: "\/"\n\s+schedule:\n\s+interval: "weekly"/);
});
});
Loading