-
Notifications
You must be signed in to change notification settings - Fork 5
Add GitHub Action for pull request sanity tests #36
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,113 @@ | |||||||||||||||||||||||
| name: Pull Request Sanity Tests | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| on: | |||||||||||||||||||||||
| # Run on pull requests | |||||||||||||||||||||||
| pull_request: | |||||||||||||||||||||||
| types: [opened, synchronize, reopened] | |||||||||||||||||||||||
| branches: | |||||||||||||||||||||||
| - main | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # Allow manual trigger from any branch | |||||||||||||||||||||||
| workflow_dispatch: | |||||||||||||||||||||||
| inputs: | |||||||||||||||||||||||
| log_level: | |||||||||||||||||||||||
| description: 'Log level for test output' | |||||||||||||||||||||||
| required: false | |||||||||||||||||||||||
| default: 'info' | |||||||||||||||||||||||
| type: choice | |||||||||||||||||||||||
| options: | |||||||||||||||||||||||
| - debug | |||||||||||||||||||||||
| - info | |||||||||||||||||||||||
| - warning | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| jobs: | |||||||||||||||||||||||
| sanity-tests: | |||||||||||||||||||||||
| name: Run Sanity Tests | |||||||||||||||||||||||
| runs-on: ubuntu-latest | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| steps: | |||||||||||||||||||||||
| - name: Checkout code | |||||||||||||||||||||||
| uses: actions/checkout@v4 | |||||||||||||||||||||||
| with: | |||||||||||||||||||||||
| fetch-depth: 0 | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| - name: Set up environment | |||||||||||||||||||||||
| run: | | |||||||||||||||||||||||
| echo "Running sanity tests on branch: ${{ github.ref_name }}" | |||||||||||||||||||||||
| echo "Triggered by: ${{ github.event_name }}" | |||||||||||||||||||||||
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |||||||||||||||||||||||
| echo "Manual trigger - Log level: ${{ inputs.log_level }}" | |||||||||||||||||||||||
| fi | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # Add your test setup here | |||||||||||||||||||||||
| # Example: Set up Python, Go, Node.js, etc. | |||||||||||||||||||||||
| # - name: Set up Python | |||||||||||||||||||||||
| # uses: actions/setup-python@v5 | |||||||||||||||||||||||
| # with: | |||||||||||||||||||||||
| # python-version: '3.11' | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # - name: Install dependencies | |||||||||||||||||||||||
| # run: | | |||||||||||||||||||||||
| # pip install -r requirements.txt | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| - name: Run sanity tests | |||||||||||||||||||||||
| run: | | |||||||||||||||||||||||
| echo "===================================" | |||||||||||||||||||||||
| echo "Running Sanity Tests" | |||||||||||||||||||||||
| echo "===================================" | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # TODO: Add your sanity test commands here | |||||||||||||||||||||||
| # Examples: | |||||||||||||||||||||||
| # - Basic syntax/lint checks | |||||||||||||||||||||||
| # - Quick unit tests | |||||||||||||||||||||||
| # - Container build validation | |||||||||||||||||||||||
| # - Configuration validation | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # Placeholder for actual tests | |||||||||||||||||||||||
| echo "✓ Placeholder: Add your sanity tests here" | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # Example test structure: | |||||||||||||||||||||||
| # make sanity-test | |||||||||||||||||||||||
| # or | |||||||||||||||||||||||
| # ./scripts/run-sanity-tests.sh | |||||||||||||||||||||||
| # or | |||||||||||||||||||||||
| # pytest tests/sanity/ | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| - name: Test summary | |||||||||||||||||||||||
| if: always() | |||||||||||||||||||||||
| run: | | |||||||||||||||||||||||
| echo "===================================" | |||||||||||||||||||||||
| echo "Sanity Tests Complete" | |||||||||||||||||||||||
| echo "===================================" | |||||||||||||||||||||||
| if [ $? -eq 0 ]; then | |||||||||||||||||||||||
| echo "✓ All sanity tests passed" | |||||||||||||||||||||||
| else | |||||||||||||||||||||||
| echo "✗ Some sanity tests failed" | |||||||||||||||||||||||
| exit 1 | |||||||||||||||||||||||
| fi | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # Optional: Upload test results | |||||||||||||||||||||||
| # - name: Upload test results | |||||||||||||||||||||||
| # if: always() | |||||||||||||||||||||||
| # uses: actions/upload-artifact@v4 | |||||||||||||||||||||||
| # with: | |||||||||||||||||||||||
| # name: sanity-test-results | |||||||||||||||||||||||
| # path: test-results/ | |||||||||||||||||||||||
| # retention-days: 30 | |||||||||||||||||||||||
|
|
|||||||||||||||||||||||
| # Optional: Add a check status that can be used as a required check | |||||||||||||||||||||||
| sanity-tests-status: | |||||||||||||||||||||||
| name: Sanity Tests Status | |||||||||||||||||||||||
| runs-on: ubuntu-latest | |||||||||||||||||||||||
| needs: sanity-tests | |||||||||||||||||||||||
| if: always() | |||||||||||||||||||||||
| steps: | |||||||||||||||||||||||
| - name: Check test results | |||||||||||||||||||||||
| run: | | |||||||||||||||||||||||
| if [ "${{ needs.sanity-tests.result }}" == "success" ]; then | |||||||||||||||||||||||
| echo "✓ Sanity tests passed" | |||||||||||||||||||||||
| exit 0 | |||||||||||||||||||||||
| else | |||||||||||||||||||||||
| echo "✗ Sanity tests failed" | |||||||||||||||||||||||
| exit 1 | |||||||||||||||||||||||
| fi | |||||||||||||||||||||||
|
Comment on lines
+100
to
+113
Check warningCode 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: {}
Copilot AutofixAI 3 months ago To fix the problem, we should add a Given that neither job in this workflow appears to require any special repository or API access via the GITHUB_TOKEN, we can set permissions:
contents: readThis line should be added immediately after the workflow
Suggested changeset
1
.github/workflows/pr-sanity-tests.yml
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 3 months ago
The best way to fix the problem is to explicitly set the minimum permissions required for the job or the whole workflow. In this workflow, the steps do not need any write access to the repository or other resources. Therefore, you should add a
permissionsblock set tocontents: readat either the root level (applies to all jobs unless individually overridden) or on the specific jobs if desired. The most consistent and thorough approach is to add it at the top, just undername: ..., so it applies to all jobs, unless a job truly needs elevated permissions (not the case here).Specifically, insert the following lines after line 1:
No imports or additional changes are needed, since this is a YAML workflow file, not code.