Skip to content
Closed
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
27 changes: 27 additions & 0 deletions .github/workflows/api-spec-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: API spec validation
on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- "api/source/specification/**"
- ".github/workflows/api-spec-validation.yml"
push:
branches:
- main
paths:
- "api/source/specification/**"
- ".github/workflows/api-spec-validation.yml"

jobs:
validate_asyncapi:
name: Validate AsyncAPI specs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Validate log-socket.yaml
run: npx --yes @asyncapi/cli@2 validate api/source/specification/log-socket.yaml
Comment on lines +19 to +27

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 2 months ago

In general, the fix is to add an explicit permissions block limiting the GITHUB_TOKEN to the least privileges needed. This workflow only checks out contents and runs a validation command; it does not write to the repo, issues, or pull requests. Therefore, contents: read (and nothing else) is sufficient.

The best minimal change without altering existing behavior is to add a permissions section at the workflow root (top level, alongside name and on). This will apply to all jobs, including validate_asyncapi, and avoids repeating the block per job. Concretely, in .github/workflows/api-spec-validation.yml, insert:

permissions:
  contents: read

between the existing on: block (ending at current line 15) and the jobs: key (current line 17). No additional imports or methods are needed; this is pure YAML configuration for GitHub Actions.

Suggested changeset 1
.github/workflows/api-spec-validation.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/api-spec-validation.yml b/.github/workflows/api-spec-validation.yml
--- a/.github/workflows/api-spec-validation.yml
+++ b/.github/workflows/api-spec-validation.yml
@@ -14,6 +14,9 @@
       - "api/source/specification/**"
       - ".github/workflows/api-spec-validation.yml"
 
+permissions:
+  contents: read
+
 jobs:
   validate_asyncapi:
     name: Validate AsyncAPI specs
EOF
@@ -14,6 +14,9 @@
- "api/source/specification/**"
- ".github/workflows/api-spec-validation.yml"

permissions:
contents: read

jobs:
validate_asyncapi:
name: Validate AsyncAPI specs
Copilot is powered by AI and may make mistakes. Always verify output.
36 changes: 36 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Unit tests
on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- "api/source/**"
- "test/unit/**"
- ".github/workflows/unit-tests.yml"
push:
branches:
- main
paths:
- "api/source/**"
- "test/unit/**"
- ".github/workflows/unit-tests.yml"

jobs:
unit-tests:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install API dependencies
run: npm ci
working-directory: ./api/source/
- name: Install test dependencies
run: npm ci
working-directory: ./test/unit/
- name: Run unit tests
working-directory: ./test/unit/
run: npm test
Comment on lines +21 to +36

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 2 months ago

In general, the fix is to explicitly declare a permissions block that restricts the GITHUB_TOKEN to the least privilege required. For this unit test workflow, all steps only read repository contents and do not perform any write operations to GitHub resources, so contents: read at the workflow level is sufficient.

The best way to fix this without changing functionality is to add a root-level permissions section just under the name: line (before on:). This will apply to all jobs in the workflow, including unit-tests, unless overridden by a job-specific permissions block. No changes to the steps are required. The new block should be:

permissions:
  contents: read

This is sufficient because actions/checkout, actions/setup-node, and npm commands used locally do not require write access to the GitHub API. No imports or additional definitions are needed; only this YAML change in .github/workflows/unit-tests.yml.

Suggested changeset 1
.github/workflows/unit-tests.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -1,4 +1,6 @@
 name: Unit tests
+permissions:
+  contents: read
 on:
   workflow_dispatch:
   pull_request:
EOF
@@ -1,4 +1,6 @@
name: Unit tests
permissions:
contents: read
on:
workflow_dispatch:
pull_request:
Copilot is powered by AI and may make mistakes. Always verify output.
Loading
Loading