Skip to content

Commit 27f471d

Browse files
Merge master into add_output_name
2 parents e28e162 + f9c9b7a commit 27f471d

26 files changed

Lines changed: 1675 additions & 220 deletions

‎.github/dependabot.yml‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎.github/workflows/ci.yml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test:
16+
name: tests and coverage
17+
runs-on: cx-public-ubuntu-x64
18+
timeout-minutes: 10
19+
steps:
20+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
with:
22+
persist-credentials: false
23+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
24+
with:
25+
node-version: 22
26+
# Runner cannot reach registry.npmjs.org; install through the echohq registry, as in test_action.yaml
27+
- name: Install dependencies through echohq registry
28+
env:
29+
ECHO_LIBRARIES_ACCESS_KEY: ${{ secrets.ECHO_LIBRARIES_ACCESS_KEY }}
30+
run: |
31+
NPMRC="${RUNNER_TEMP}/npmrc"
32+
umask 077
33+
printf 'registry=https://npm.echohq.com/\n//npm.echohq.com/:_authToken=%s\n' "${ECHO_LIBRARIES_ACCESS_KEY}" > "${NPMRC}"
34+
npm ci --ignore-scripts --userconfig "${NPMRC}"
35+
rm -f "${NPMRC}"
36+
- name: Run tests with coverage
37+
run: npm run test:coverage
38+
39+
shellcheck:
40+
name: shellcheck entrypoint
41+
runs-on: cx-public-ubuntu-x64
42+
timeout-minutes: 5
43+
steps:
44+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
45+
with:
46+
persist-credentials: false
47+
# entrypoint.sh runs under busybox ash in the action image
48+
- name: Lint entrypoint.sh
49+
run: docker run --rm -v "${PWD}:/mnt:ro" koalaman/shellcheck@sha256:2097951f02e735b613f4a34de20c40f937a6c8f18ecb170612c88c34517221fb --shell=busybox --severity=error entrypoint.sh # v0.10.0
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: coverage-badge
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}
9+
cancel-in-progress: false
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
coverage:
16+
name: generate-coverage
17+
runs-on: cx-public-ubuntu-x64
18+
timeout-minutes: 10
19+
steps:
20+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
with:
22+
persist-credentials: false
23+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
24+
with:
25+
node-version: 22
26+
# Runner cannot reach registry.npmjs.org; install through the echohq registry, as in test_action.yaml
27+
- name: Install dependencies through echohq registry
28+
env:
29+
ECHO_LIBRARIES_ACCESS_KEY: ${{ secrets.ECHO_LIBRARIES_ACCESS_KEY }}
30+
run: |
31+
NPMRC="${RUNNER_TEMP}/npmrc"
32+
umask 077
33+
printf 'registry=https://npm.echohq.com/\n//npm.echohq.com/:_authToken=%s\n' "${ECHO_LIBRARIES_ACCESS_KEY}" > "${NPMRC}"
34+
npm ci --ignore-scripts --userconfig "${NPMRC}"
35+
rm -f "${NPMRC}"
36+
- name: Run tests with coverage
37+
run: npm run test:coverage
38+
- name: Generate badge
39+
run: node scripts/coverage-badge.js coverage/lcov.info coverage/badge.json
40+
- name: Upload coverage badge Artifact
41+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
42+
with:
43+
name: coverage-badge
44+
path: coverage/badge.json
45+
46+
publish:
47+
name: publish-coverage
48+
needs: coverage
49+
runs-on: cx-public-ubuntu-x64
50+
timeout-minutes: 5
51+
permissions:
52+
contents: write # for git push to the badges branch
53+
steps:
54+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
55+
with:
56+
ref: badges
57+
persist-credentials: true
58+
- name: Download Badge json
59+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
60+
with:
61+
name: coverage-badge
62+
path: latest-coverage
63+
- name: Push badge to the badges branch
64+
run: |
65+
git config user.name "github-actions[bot]"
66+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
67+
mv latest-coverage/badge.json coverage.json
68+
git add coverage.json
69+
if ! git status | grep "nothing to commit"; then
70+
git commit -m 'chore(tests): updating test coverage badge'
71+
git push origin badges
72+
fi

‎.github/workflows/publish.yml‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@ on:
66
tags:
77
- 'v*'
88

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: read
15+
916
jobs:
1017
publish:
11-
runs-on: ubuntu-latest
18+
name: publish kics github action
19+
runs-on: cx-public-ubuntu-x64
20+
timeout-minutes: 10
21+
permissions:
22+
contents: write # for haya14busa/action-update-semver to push tags and gh release create to publish the release
1223
steps:
1324
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
25+
with:
26+
persist-credentials: false
1427
- uses: haya14busa/action-update-semver@7d2c558640ea49e798d46539536190aff8c18715 #v1.5.1
1528
with:
1629
major_version_tag_only: true
1730
- name: Create a Release
18-
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e #v1.1.4
1931
env:
20-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
21-
with:
22-
tag_name: ${{ github.ref }}
23-
release_name: ${{ github.ref }}
32+
GH_TOKEN: ${{ github.token }}
33+
TAG_NAME: ${{ github.ref_name }}
34+
run: gh release create "$TAG_NAME" --repo "$GITHUB_REPOSITORY" --title "$TAG_NAME" --verify-tag --generate-notes

‎.github/workflows/test_action.yaml‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,38 @@ on:
44
workflow_dispatch:
55
pull_request:
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions:
12+
contents: read
13+
714
jobs:
815
test:
9-
runs-on: ubuntu-latest
16+
name: test kics github action
17+
runs-on: cx-public-ubuntu-x64
18+
timeout-minutes: 10
19+
permissions:
20+
contents: read
21+
pull-requests: write # for enable_comments to post scan results on the PR
1022
steps:
1123
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
24+
with:
25+
persist-credentials: false
1226
- run: mkdir -p myoutput
27+
# The runner cannot reach registry.npmjs.org, and the docker build done by `uses: ./` cannot receive secrets.
28+
# Pre-build the npm layers through the echohq registry so that build reuses them from the local docker cache.
29+
- name: Pre-build npm layers through echohq registry
30+
env:
31+
ECHO_LIBRARIES_ACCESS_KEY: ${{ secrets.ECHO_LIBRARIES_ACCESS_KEY }}
32+
DOCKER_BUILDKIT: "1"
33+
run: |
34+
NPMRC="${RUNNER_TEMP}/npmrc"
35+
umask 077
36+
printf 'registry=https://npm.echohq.com/\n//npm.echohq.com/:_authToken=%s\n' "${ECHO_LIBRARIES_ACCESS_KEY}" > "${NPMRC}"
37+
docker build --target builder --secret "id=npmrc,src=${NPMRC}" .
38+
rm -f "${NPMRC}"
1339
- name: Test KICS action
1440
uses: ./
1541
with:

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
.vscode
2+
.vscode
3+
coverage

‎Dockerfile‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
FROM checkmarx/kics:v2.1.20 as kics-env
2-
3-
FROM cgr.dev/chainguard/wolfi-base:latest
4-
1+
FROM node:20-alpine@sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293 AS builder
2+
3+
WORKDIR /build
4+
5+
COPY package.json package-lock.json ./
6+
# Optional npmrc secret, only used on runners that cannot reach registry.npmjs.org directly
7+
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false npm ci
8+
9+
COPY src ./src
10+
RUN npm run build
11+
12+
FROM docker.io/checkmarx/kics:v2.1.20@sha256:3e5a268eb8adda2e5a483c9359ddfc4cd520ab856a7076dc0b1d8784a37e2602 AS kics-env
13+
14+
FROM cgr.dev/chainguard/node:latest@sha256:f6aa5d5b1fa68ab77a3512b606534e22a8afc3a04fb22db95430bb850e433664
15+
16+
USER root
17+
518
COPY --from=kics-env /app /app
6-
19+
COPY --from=builder /build/dist /app/dist
20+
721
COPY ./entrypoint.sh /entrypoint.sh
8-
22+
923
RUN chmod +x /entrypoint.sh
10-
11-
COPY ./ /app
12-
24+
1325
ENTRYPOINT ["/entrypoint.sh"]

‎README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![License: GPL-3.0](https://img.shields.io/badge/License-GPL3.0-yellow.svg)](https://www.gnu.org/licenses)
44
[![Latest Release](https://img.shields.io/github/v/release/checkmarx/kics-github-action)](https://github.com/checkmarx/kics-github-action/releases)
55
[![Open Issues](https://img.shields.io/github/issues-raw/checkmarx/kics-github-action)](https://github.com/checkmarx/kics-github-action/issues)
6+
[![Coverage](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FCheckmarx%2Fkics-github-action%2Fbadges%2Fcoverage.json)](https://github.com/Checkmarx/kics-github-action/actions/workflows/coverage-badge.yml)
67

78
- [KICS GitHub Action](#kics-github-action)
89
- [Integrate KICS into your GitHub workflows](#integrate-kics-into-your-github-workflows)
@@ -20,6 +21,7 @@
2021
- [Uploading SARIF report](#uploading-sarif-report)
2122
- [Using configuration file](#using-configuration-file)
2223
- [How To Contribute](#how-to-contribute)
24+
- [Running the tests](#running-the-tests)
2325
- [License](#license)
2426

2527
## Integrate KICS into your GitHub workflows
@@ -422,6 +424,7 @@ jobs:
422424
{
423425
"exclude-categories": "Encryption",
424426
"exclude-paths": "terraform/gcp/big_data.tf,terraform/gcp/gcs.tf",
427+
"ignore-on-exit": "results",
425428
"log-file": true,
426429
"minimal-ui": false,
427430
"no-color": false,
@@ -448,6 +451,25 @@ jobs:
448451

449452
We welcome [issues](https://github.com/checkmarx/kics-github-action/issues) to and [pull requests](https://github.com/checkmarx/kics-github-action/pulls) against this repository!
450453

454+
### Running the tests
455+
456+
Requires Node.js 22 or newer.
457+
458+
```sh
459+
npm ci
460+
npm test # unit and end-to-end tests
461+
npm run test:coverage # same, plus a coverage report and the coverage gate used by CI
462+
```
463+
464+
Tests live under `test/`:
465+
466+
- `test/unit` - the PR comment and job summary logic against a fake GitHub API
467+
- `test/e2e` - the action run as a workflow would run it: `src/main.js` as a process, `entrypoint.sh` against a fake `kics`, and the `action.yml` contract
468+
- `test/helpers` and `test/fixtures` - the fake GitHub API, KICS report builders and process runners
469+
470+
Tests marked with `knownBug` document known bugs: they are reported as `todo` and are expected to fail until the bug is fixed.
471+
They are skipped in the coverage run, so coverage only counts verified behaviour.
472+
451473
# License
452474

453475
KICS Github Action

0 commit comments

Comments
 (0)