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
3 changes: 1 addition & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
environment: PUBLISH
permissions:
contents: read
id-token: write

steps:
- name: Checkout
Expand Down Expand Up @@ -52,5 +53,3 @@ jobs:

- name: Publish package
run: bun run release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 5 additions & 2 deletions tests/workflow-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const pullRequestTriggerPattern = /^\s*pull_request:\s*$/m
const readOnlyPermissionsPattern = /^permissions:\n\s+contents: read$/m
const persistedCredentialsPattern = /persist-credentials: false/g
const publishEnvironmentPattern = /^\s+environment: PUBLISH$/m
const publishPermissionsPattern = /^\s+permissions:\n\s+contents: read$/m
const publishPermissionsPattern = /^\s+permissions:\n\s+contents: read\n\s+id-token: write$/m
const releasePermissionsPattern = /^permissions:\n\s+contents: write\n\s+pull-requests: write$/m

function readWorkflow(name: (typeof workflowNames)[number]): Promise<string> {
Expand Down Expand Up @@ -39,7 +39,7 @@ describe("GitHub Actions security", () => {
expect(workflow.match(persistedCredentialsPattern)).toHaveLength(2)
})

test("limits publishing to the merged canonical release PR", async () => {
test("limits trusted publishing to the merged canonical release PR", async () => {
const workflow = await readWorkflow("publish.yml")

expect(workflow).toContain("github.repository == 'hack-dance/schema-stream'")
Expand All @@ -51,6 +51,9 @@ describe("GitHub Actions security", () => {
expect(workflow).toMatch(publishPermissionsPattern)
expect(workflow).toContain("persist-credentials: false")
expect(workflow).not.toContain("contents: write")
expect(workflow).not.toContain("NODE_AUTH_TOKEN")
expect(workflow).not.toContain("NPM_TOKEN")
expect(workflow).not.toContain("secrets.")
})

test("scopes release automation to the canonical repository", async () => {
Expand Down