-
Notifications
You must be signed in to change notification settings - Fork 2
create github action for docker #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| 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
Show autofix suggestion
Hide autofix suggestion
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
permissionsblock at the top (root) level of.github/workflows/test-action.yml, so it applies to all jobs that don’t override it. - Set
contents: readas the only permission, which is enough foractions/checkout@v6to fetch the repository. Artifact upload uses theactionsscope, which is not controlled by thispermissionsmap, 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 apermissions:section between thename: Test GitHub Actionline and theon: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.
-
Copy modified lines R3-R5
| @@ -1,5 +1,8 @@ | ||
| name: Test GitHub Action | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: |
fixes #202