Skip to content

Conversation

@kilifu
Copy link
Contributor

@kilifu kilifu commented Jan 30, 2026

fixes #202

Comment on lines 13 to 119
runs-on: ubuntu-latest
name: Test OpenAPI Overlays Action
steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Create test OpenAPI file
run: |
mkdir -p test-data
cat > test-data/openapi.yaml << 'EOF'
openapi: 3.1.0
info:
title: Test API
version: 1.0.0
description: Original Description
paths:
/test:
get:
summary: Test endpoint
responses:
'200':
description: OK
EOF

- name: Create test overlay file
run: |
cat > test-data/overlay.yaml << 'EOF'
overlay: 1.0.0
info:
title: Test Overlay
version: 1.0.0
actions:
- target: $.info.description
description: Update description
update:
description: Modified Description
EOF

- name: Test Action - Apply
uses: ./
with:
input: 'test-data/openapi.yaml'
overlays: 'test-data/overlay.yaml'
output: 'test-data/output-apply.yaml'
command: 'apply'

- name: Verify output file exists
run: |
if [ ! -f "test-data/output-apply.yaml" ]; then
echo "Error: Output file was not created"
exit 1
fi
echo "? Output file created successfully"

- name: Verify overlay was applied
run: |
if ! grep -q "Modified Description" "test-data/output-apply.yaml"; then
echo "Error: Overlay was not applied correctly"
cat test-data/output-apply.yaml
exit 1
fi
echo "? Overlay applied correctly"

- name: Create multiple overlay files
run: |
cat > test-data/overlay2.yaml << 'EOF'
overlay: 1.0.0
info:
title: Second Overlay
version: 1.0.0
actions:
- target: $.info
description: Add contact info
update:
contact:
name: API Support
email: [email protected]
EOF

- name: Test Action - Multiple Overlays
uses: ./
with:
input: 'test-data/openapi.yaml'
overlays: |
test-data/overlay.yaml
test-data/overlay2.yaml
output: 'test-data/output-multiple.yaml'
command: 'apply-and-normalize'

- name: Verify multiple overlays applied
run: |
if ! grep -q "Modified Description" "test-data/output-multiple.yaml"; then
echo "Error: First overlay was not applied"
exit 1
fi
if ! grep -q "[email protected]" "test-data/output-multiple.yaml"; then
echo "Error: Second overlay was not applied"
exit 1
fi
echo "? Multiple overlays applied correctly"

- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v6
with:
name: test-results
path: test-data/

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium test

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 4 days ago

To fix the problem, we should explicitly declare a permissions block that grants only the minimal scopes needed by this workflow. The job only needs to read repository contents (for actions/checkout) and upload artifacts; neither of these requires write access to repository contents, issues, or pull requests. Therefore, a root-level permissions: contents: read is sufficient and is the recommended minimal starting point.

The best fix without changing existing functionality is:

  • Add a permissions block at the top (root) level of .github/workflows/test-action.yml, so it applies to all jobs that don’t override it.
  • Set contents: read as the only permission, which is enough for actions/checkout@v6 to fetch the repository. Artifact upload uses the actions scope, which is not controlled by this permissions map, so it will continue to work.
  • No other steps (like running the local action or shell commands) require extra GitHub API permissions.

Concretely:

  • In .github/workflows/test-action.yml, insert a permissions: section between the name: Test GitHub Action line and the on: block.

  • The block should look like:

    permissions:
      contents: read

No additional imports, methods, or definitions are required, since this is purely a YAML configuration change.

Suggested changeset 1
.github/workflows/test-action.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/test-action.yml b/.github/workflows/test-action.yml
--- a/.github/workflows/test-action.yml
+++ b/.github/workflows/test-action.yml
@@ -1,5 +1,8 @@
 name: Test GitHub Action
 
+permissions:
+  contents: read
+
 on:
   workflow_dispatch:
   pull_request:
EOF
@@ -1,5 +1,8 @@
name: Test GitHub Action

permissions:
contents: read

on:
workflow_dispatch:
pull_request:
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add support for using the tool as a github action

2 participants