-
Notifications
You must be signed in to change notification settings - Fork 0
Fix call from other repos #108
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
305e39b
410a307
35c7666
e6d8014
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,4 @@ | ||
| ignore-scripts=true | ||
| save-exact=true | ||
| audit=true | ||
| fund=false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Changelog for run-semgrep Composite Action | ||
|
|
||
| All notable changes to the run-semgrep composite GitHub Action will be documented in this file. | ||
|
|
||
| ## 1.0.0 - Initial Release | ||
|
|
||
| ### Added | ||
|
|
||
| - Initial release of the reusable composite action for running Semgrep scans | ||
| - Inputs are passed via environment variables | ||
| - Support running on both push and pull_request events | ||
| - Standardizes baseline resolution for diff scans | ||
| - Outputs include scan summary, config summary, scan status, and finding counts | ||
| - Designed to integrate with reviewdog for annotations |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # Run Semgrep Action | ||
|
|
||
| ## 🧭 Summary | ||
|
|
||
| Runs a Semgrep scan normalizing the baseline for diff scans depending on push vs PR context. Outputs scan results and summaries for downstream steps. | ||
|
|
||
| ## Scope/Limitations | ||
|
|
||
| - Supports both push and pull request events. | ||
| - Requires Semgrep to be installed and available in the runner environment. | ||
| - Expects environment variables for configuration (see below). | ||
|
|
||
| ## 🔒 Permissions | ||
|
|
||
| The following GHA permissions are required to use this step: | ||
|
|
||
| ```yaml | ||
| permissions: | ||
| contents: read | ||
| ``` | ||
|
|
||
| ## Dependencies | ||
|
|
||
| - `semgrep` — must be installed in the runner environment. | ||
| - `node-fetch` — required Node.js dependency (see package.json). | ||
| - `reviewdog` — for annotation output (optional, for downstream steps). | ||
|
|
||
| ## ⚙️ Inputs | ||
|
|
||
| This action is environment-driven. The following environment variables are required: | ||
|
|
||
| | Name | Required | Description | | ||
| | ------------------- | -------- | ------------------------------------------------------------------------------------------- | | ||
| | `HAS_PR` | ✅ | Whether the current context has an associated PR (true/false) | | ||
| | `PR_NUMBER` | ❌ | PR number if applicable | | ||
| | `PR_URL` | ❌ | PR URL if applicable | | ||
| | `INPUT_BASELINE` | ✅ | Baseline ref to use for diffing (e.g., origin/main) | | ||
| | `GITHUB_EVENT_NAME` | ✅ | GitHub provided environment variable for event name (e.g., push, pull_request) | | ||
| | `GITHUB_REF_NAME` | ✅ | GitHub provided environment variable for the branch or tag name that triggered the workflow | | ||
| | `GITHUB_BASE_REF` | ❌ | GitHub provided environment variable for the base ref of a PR (if applicable) | | ||
| | `GITHUB_REPOSITORY` | ✅ | GitHub provided environment variable for the repository (e.g., owner/repo) | | ||
| | `GITHUB_TOKEN` | ✅ | GitHub token for API access | | ||
| | `SCAN_MODE` | ✅ | 'diff' or 'full' scan mode | | ||
| | `SEMGREP_CONFIG` | ✅ | Semgrep ruleset(s) to use | | ||
| | `SEMGREP_TARGETS` | ✅ | Targets to scan (default: current directory) | | ||
| | `FAIL_LEVEL` | ✅ | Severity level to fail on (e.g., ERROR, WARNING) | | ||
| | `EXTRA_ARGS` | ❌ | Additional arguments to pass to Semgrep | | ||
|
|
||
| ## 📤 Outputs | ||
|
|
||
| Along with writing files for reviewdog annotations and inputs, this action provides the following outputs: | ||
|
|
||
| | Name | Description | | ||
| | -------------------- | --------------------------------------------------- | | ||
| | `normalizedBaseline` | The resolved baseline ref | | ||
| | `scanSummary` | Summary of findings in markdown format | | ||
| | `configSummary` | Summary of scan config in markdown format | | ||
| | `scanStatus` | 'success' or 'failure' based on findings/fail level | | ||
| | `totalFindings` | Total number of findings | | ||
| | `numErrors` | Number of ERROR severity findings | | ||
| | `numWarnings` | Number of WARNING severity findings | | ||
| | `numInfo` | Number of INFO severity findings | | ||
|
|
||
| ## 🚀 Usage | ||
|
|
||
| Basic usage example: | ||
|
|
||
| ```yaml | ||
| - name: Run Semgrep | ||
| id: semgrep | ||
| uses: OpenSesame/core-github-actions/.github/actions/run-semgrep@actions/run-semgrep/1.0.0 | ||
| env: | ||
| HAS_PR: ${{ env.HAS_PR }} | ||
| INPUT_BASELINE: ${{ env.INPUT_BASELINE }} | ||
| GITHUB_EVENT_NAME: ${{ github.event_name }} | ||
| GITHUB_REF_NAME: ${{ github.ref_name }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
| SEMGREP_CONFIG: 'p/default' | ||
| SEMGREP_TARGETS: '.' | ||
| SCAN_MODE: 'full' | ||
| FAIL_LEVEL: 'error' | ||
| EXTRA_ARGS: '' | ||
| ``` | ||
|
|
||
| Example outputs: | ||
|
|
||
| ```yaml | ||
| steps.semgrep.outputs.scanStatus | ||
| steps.semgrep.outputs.totalFindings | ||
| ``` | ||
|
|
||
| Example usage of outputs in later steps: | ||
|
|
||
| ```yaml | ||
| if: steps.semgrep.outputs.scanStatus == 'failure' | ||
| run: echo "Semgrep scan failed at or above threshold." | ||
| ``` | ||
|
|
||
| ## 🧠 Notes | ||
|
|
||
| - This action writes a file for reviewdog annotations (`reviewdog_input.txt`). | ||
| - Unit tests for the script are included in `run-semgrep.unit.test.js` (not used by the action, but kept for maintainability). | ||
|
|
||
| ## Versioning | ||
|
|
||
| This action uses namespaced tags for versioning and is tracked in the CHANGELOG. | ||
|
|
||
| ```text | ||
| actions/run-semgrep/vX.Y.Z | ||
| ``` | ||
|
|
||
| See the repository's versioning documentation for details on how tags are validated and created. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| name: 'Run Semgrep' | ||
| description: 'Run a Semgrep scan and output results for reviewdog and future steps' | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install action dependencies | ||
| shell: bash | ||
| working-directory: ${{ github.action_path }} | ||
| run: npm ci | ||
|
|
||
| - name: Run Semgrep Scan | ||
| shell: bash | ||
| run: node ${{ github.action_path }}/run-semgrep.js |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "@opensesame/run-semgrep-action", | ||
| "version": "1.0.0", | ||
| "main": "run-semgrep.js", | ||
| "private": true, | ||
| "description": "Composite action to run Semgrep scan for GitHub Actions.", | ||
| "dependencies": { | ||
| "node-fetch": "^2.6.7" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| const { validateEnvVar } = require('./env-helpers'); | ||
|
|
||
| describe('validateEnvVar', () => { | ||
|
Comment on lines
+1
to
+3
|
||
| const ORIGINAL_EXIT = process.exit; | ||
| const ORIGINAL_CONSOLE_ERROR = console.error; | ||
|
|
||
| beforeEach(() => { | ||
| process.exit = jest.fn(); | ||
| console.error = jest.fn(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.exit = ORIGINAL_EXIT; | ||
| console.error = ORIGINAL_CONSOLE_ERROR; | ||
| }); | ||
|
|
||
| it('does not exit when env var is set', () => { | ||
| process.env.TEST_VAR = 'value'; | ||
| validateEnvVar('TEST_VAR'); | ||
| expect(process.exit).not.toHaveBeenCalled(); | ||
| expect(console.error).not.toHaveBeenCalled(); | ||
| delete process.env.TEST_VAR; | ||
| }); | ||
|
|
||
| it('exits with error when env var is not set', () => { | ||
| delete process.env.TEST_VAR; | ||
| validateEnvVar('TEST_VAR'); | ||
| expect(console.error).toHaveBeenCalledWith( | ||
| '::error::Environment variable TEST_VAR is required' | ||
| ); | ||
| expect(process.exit).toHaveBeenCalledWith(1); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,12 @@ | |||||
|
|
||||||
| All notable changes to the **run_semgrep_scan** callable workflow are documented in this file. | ||||||
|
|
||||||
| ## 1.0.1 | ||||||
|
|
||||||
| ### Changed | ||||||
|
|
||||||
| - Updated workflow to support cross-repository usage by checking out the core-github-actions repository into a subdirectory and referencing all internal actions and scripts from that subdirectory. This ensures that required actions and scripts are always available, regardless of which repository invokes the workflow. | ||||||
|
||||||
| - Updated workflow to support cross-repository usage by checking out the core-github-actions repository into a subdirectory and referencing all internal actions and scripts from that subdirectory. This ensures that required actions and scripts are always available, regardless of which repository invokes the workflow. | |
| - Updated workflow to support cross-repository usage by referencing internal actions and scripts via fully-qualified paths to the `OpenSesame/core-github-actions` repository (for example, `OpenSesame/core-github-actions/.github/actions/...@...`). This ensures that required actions and scripts are always available, regardless of which repository invokes the workflow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test file imports
validateEnvVarfrom./env-helpers, but based on the diff inrun-semgrep.js(line 4), this module should exist. However, theenv-helpers.jsfile is not present in the provided diffs. If this file was not moved or created as part of this PR, the tests and the main script will fail at runtime.