Skip to content
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

feat: implement CMake dependency scanning #1

Open
wants to merge 97 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
d73081e
build: add devcontainer
rjaegers Jul 17, 2023
602e84c
refactor: remove trailing spaces
rjaegers Jul 17, 2023
5b13b05
refactor: couple main to detector and add tests
rjaegers Jul 18, 2023
be18181
ci: update actions
rjaegers Jul 18, 2023
54b7030
ci: update test.yml
rjaegers Jul 18, 2023
62141b0
build: update dist folder
rjaegers Jul 18, 2023
778774e
build: update dist folder
rjaegers Jul 18, 2023
904e0af
refactor: improved dection robustness
rjaegers Jul 18, 2023
100e0d3
chore: update dependencies
rjaegers Jul 18, 2023
f4773f4
chore: remove quotes from quoted arguments
rjaegers Jul 18, 2023
5b7afd4
chore: revert to es2019 for compatibility
rjaegers Jul 18, 2023
1724327
chore: fix build
rjaegers Jul 18, 2023
14c6dc3
feat: support multiple CMake files
rjaegers Jul 18, 2023
ac5524b
chore: fix glob path
rjaegers Jul 18, 2023
27dc41a
feat: add dependency submission
rjaegers Jul 18, 2023
47a58a8
build: enable dependency scanner
rjaegers Jul 18, 2023
6e5a1fe
build: fix build
rjaegers Jul 18, 2023
6713d67
chore: check with commit sha
rjaegers Jul 18, 2023
ebd5aa9
ci: add additional dependency
rjaegers Jul 18, 2023
388b300
chore: adhere to purl spec
rjaegers Jul 18, 2023
d8661bc
feat: determine correct purl type
rjaegers Jul 19, 2023
cfc915e
refactor: add file to BuildTarget
rjaegers Jul 19, 2023
a7eebeb
feat: couple correct file to BuildTargets
rjaegers Jul 19, 2023
169d0f6
chore: try out different types
rjaegers Jul 19, 2023
d2f1be6
build: fix build
rjaegers Jul 19, 2023
dd0378d
chore: try out different types
rjaegers Jul 19, 2023
b61825b
chore: try out different types
rjaegers Jul 19, 2023
73ab3fa
chore: restore type
rjaegers Jul 19, 2023
c547f0a
docs: update README.md
rjaegers Jul 19, 2023
d0ba98e
ci: try-out permission claim
rjaegers Jul 19, 2023
1c6fe9d
docs: update README.md
rjaegers Jul 19, 2023
1405388
ci: test sbom extraction
rjaegers Jul 19, 2023
6ee3c63
docs: contents write permission is required
rjaegers Jul 19, 2023
40b31e8
ci: supply GH_TOKEN to gh cli
rjaegers Jul 19, 2023
1178c33
fix: only add BuildTArget when dependencies are found
rjaegers Jul 19, 2023
de1b0d6
feat: add 'config' mode to determine files to scan
rjaegers Jul 19, 2023
dd3633e
build: fix example generation
rjaegers Jul 19, 2023
4cd2a62
build: add missing include
rjaegers Jul 19, 2023
ec6525f
fix: correct cmake query path
rjaegers Jul 19, 2023
c7975b6
fix: recursive mkdir
rjaegers Jul 19, 2023
69bd48d
fix: incorrect reply file
rjaegers Jul 19, 2023
49734b7
fix: make cmake file api paths absolute
rjaegers Jul 20, 2023
6d7fe06
refactor: improve input validation
rjaegers Jul 20, 2023
59b3392
docs: update README.md
rjaegers Jul 20, 2023
2312dbc
ci: add dependabot
rjaegers Jul 20, 2023
c80c56d
build(deps-dev): bump ts-jest from 29.0.3 to 29.1.1
dependabot[bot] Jul 20, 2023
f8f6417
Merge pull request #5 from philips-forks/dependabot/npm_and_yarn/ts-j…
rjaegers Jul 20, 2023
8e41c84
build(deps): bump @github/dependency-submission-toolkit from 1.2.7 to…
dependabot[bot] Jul 20, 2023
522a6df
build(deps-dev): bump @types/jest from 29.2.3 to 29.5.3 (#3)
dependabot[bot] Jul 20, 2023
076c3ac
build(deps-dev): bump typescript from 4.9.3 to 5.1.6 (#4)
dependabot[bot] Jul 20, 2023
8ec7c21
build(deps-dev): bump @vercel/ncc from 0.34.0 to 0.36.1 (#6)
dependabot[bot] Jul 20, 2023
bb5ef18
build: update packages after dependency updates
rjaegers Jul 20, 2023
087b97c
refactor: use path.join and don't use ';'
rjaegers Jul 24, 2023
f57e1d1
docs: minor updates to README.md
rjaegers Jul 24, 2023
8c56206
refactor: remove GitPair type
rjaegers Jul 24, 2023
b1e8c39
docs: update LICENSE
rjaegers Jul 24, 2023
f1603e3
feat: add annotations as dependency source
rjaegers Jul 24, 2023
7288058
docs: add link to purl spec
rjaegers Jul 25, 2023
3897361
build(deps): bump actions/checkout from 3.5.3 to 3.6.0 (#7)
dependabot[bot] Sep 6, 2023
4173220
build(deps-dev): bump typescript from 5.1.6 to 5.2.2 (#8)
dependabot[bot] Sep 6, 2023
19fba29
build(deps-dev): bump @types/jest from 29.5.3 to 29.5.4 (#9)
dependabot[bot] Sep 6, 2023
bd9d37e
build(deps): bump glob from 10.3.3 to 10.3.4 (#10)
dependabot[bot] Sep 6, 2023
30e200b
build(deps): bump actions/checkout from 3.6.0 to 4.0.0 (#12)
dependabot[bot] Sep 21, 2023
a18b415
build(deps-dev): bump @types/jest from 29.5.4 to 29.5.5 (#14)
dependabot[bot] Sep 21, 2023
e8bfcf5
build(deps): bump @actions/core from 1.10.0 to 1.10.1 (#13)
dependabot[bot] Sep 21, 2023
e70310d
build(deps-dev): bump @vercel/ncc from 0.36.1 to 0.38.0 (#11)
dependabot[bot] Sep 21, 2023
85b0a32
build(deps): bump glob from 10.3.4 to 10.3.10 (#17)
dependabot[bot] Oct 3, 2023
5213963
build(deps): bump actions/checkout from 4.0.0 to 4.1.0 (#16)
dependabot[bot] Oct 3, 2023
fa6f625
chore: update dist
rjaegers Oct 3, 2023
d941131
build(deps-dev): bump @types/jest from 29.5.5 to 29.5.8 (#25)
dependabot[bot] Nov 21, 2023
413ed5e
build(deps): bump actions/setup-node from 3 to 4 (#23)
dependabot[bot] Nov 21, 2023
9787eb3
build(deps): bump undici from 5.22.1 to 5.26.3 (#18)
dependabot[bot] Nov 21, 2023
ecfd5c9
build(deps-dev): bump @babel/traverse from 7.22.8 to 7.23.2 (#19)
dependabot[bot] Nov 21, 2023
1fcd1b1
build(deps): bump actions/checkout from 4.1.0 to 4.1.1 (#20)
dependabot[bot] Nov 21, 2023
dc4e0ae
build(deps-dev): bump @vercel/ncc from 0.38.0 to 0.38.1 (#22)
dependabot[bot] Nov 21, 2023
74043ac
build(deps-dev): bump typescript from 5.2.2 to 5.3.2 (#26)
dependabot[bot] Dec 3, 2023
bb5e24a
build(deps-dev): bump @types/jest from 29.5.8 to 29.5.10 (#27)
dependabot[bot] Dec 3, 2023
11dccb6
build(deps-dev): bump @types/jest from 29.5.10 to 29.5.11 (#28)
dependabot[bot] Feb 4, 2024
44b6c15
build(deps-dev): bump typescript from 5.3.2 to 5.3.3 (#29)
dependabot[bot] Feb 4, 2024
7486a76
build(deps-dev): bump ts-jest from 29.1.1 to 29.1.2 (#33)
dependabot[bot] Feb 4, 2024
617409f
build(deps-dev): bump @types/jest from 29.5.11 to 29.5.12 (#34)
dependabot[bot] Apr 25, 2024
ba9d88e
build(deps): bump glob from 10.3.10 to 10.3.12 (#40)
dependabot[bot] Apr 25, 2024
78ee9cd
build(deps): bump undici from 5.26.3 to 5.28.4 (#41)
dependabot[bot] Apr 25, 2024
9492013
build(deps-dev): bump typescript from 5.3.3 to 5.4.5 (#43)
dependabot[bot] Apr 25, 2024
f1a754b
build(deps): bump actions/checkout from 4.1.1 to 4.1.3 (#44)
dependabot[bot] Apr 25, 2024
609c578
chore: update action to node20
rjaegers Apr 25, 2024
8ea70d1
Merge branch 'main' of https://github.com/philips-forks/cmake-depende…
rjaegers Apr 25, 2024
d02af79
chore: update dist
rjaegers Apr 25, 2024
12f1412
chore: update dist
rjaegers Apr 25, 2024
3f1819a
chore: make sure ncc is installed globally
rjaegers Apr 25, 2024
21cb730
chore: update to depencency-submission-toolkit 2.0.4
rjaegers Apr 25, 2024
eec05c1
chore: update packageurl-js to 1.2.1
rjaegers Apr 25, 2024
0218480
build(deps): bump actions/checkout from 4.1.3 to 4.1.5 (#47)
dependabot[bot] May 14, 2024
7231790
build(deps): bump glob from 10.3.12 to 10.3.15 (#46)
dependabot[bot] May 14, 2024
0ec687d
build(deps): bump actions/checkout from 4.1.5 to 4.1.7 (#53)
dependabot[bot] Aug 21, 2024
3176452
build(deps): bump glob from 10.3.15 to 11.0.0 (#58)
dependabot[bot] Aug 21, 2024
7c311b1
build(deps-dev): bump braces from 3.0.2 to 3.0.3 (#60)
dependabot[bot] Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye",
"customizations": {
"vscode": {
"extensions": [
"Orta.vscode-jest"
]
}
},
"postCreateCommand": "npm install && npm i -g @vercel/ncc"
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
version: 2

updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
19 changes: 0 additions & 19 deletions .github/workflows/cmake-dependency-submission.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Dependency Submission

on:
push:
branches:
- main

jobs:
dependency-submission-glob:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: philips-forks/cmake-dependency-submission@main
- env:
GH_TOKEN: ${{ github.token }}
run: |
gh ext install advanced-security/gh-sbom
gh sbom | jq
dependency-submission-configure:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- run: cmake -S example -B build
- uses: philips-forks/cmake-dependency-submission@main
with:
scanMode: 'configure'
buildPath: 'build'
- env:
GH_TOKEN: ${{ github.token }}
run: |
gh ext install advanced-security/gh-sbom
gh sbom | jq
20 changes: 6 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Build & test
name: Build & Test

on:
pull_request:
branches:
branches:
- main
push:
branches:
Expand All @@ -11,20 +12,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Node
uses: actions/setup-node@v3
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-node@v4
with:
node-version: 16

- name: Install npm dependencies
run: npm ci --ignore-scripts

- name: Build and run tests
- name: Build and run tests
run: npm rebuild && npm run all

- name: Verify no uncommitted files
run: '[ -z "$(git status --porcelain=v1 2>/dev/null)" ]'
shell: bash
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MIT License

Copyright (c) 2023 Ron Jaegers
Copyright (c) 2022 Breno Cunha Queiroz

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
70 changes: 55 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,76 @@
CMake Dependency Submission
</h1>

Calculates dependencies for a cmake project and submits the list to the Dependency Submission API
This GitHub Action identifies dependencies for a CMake project that uses [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html), and submits the results to the [Dependency Submission API](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api). Dependencies then appear in your repository's [dependency graph](https://github.com/philips-forks/cmake-dependency-submission/network/dependencies) and can, for example, be exported to an SBOM file.

## Github dependency graph
![2022-12-01_09-57](https://user-images.githubusercontent.com/17342434/204997995-1955d053-87f4-464f-8e02-e36fa807d0b1.png)
## Usage

This Action can be used in two different modes, depending on how the list of CMake files to scan should be determined:

## Setup
- [Glob mode](#glob-mode) (*default*); CMakeLists.txt and *.cmake files will be found by recursively globbing from the optionally provided sourcePath.
- [Configure mode](#configure-mode); CMake files will be found by querying the [CMake File API](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#manual:cmake-file-api(7)). In configure mode it is mandatory to run the CMake configure step before this action is ran.

Glob mode is faster, but configure mode is more accurate. Configure mode will recursively detect FetchContent dependencies. Configure mode will not include CMake files that are part of the source tree, but not included in the configured build.

See [action.yml](action.yml) for all valid inputs.
See [dependency-submission.yml](.github/workflows/dependency-submission.yml) for an example scan on this repository.

> **&#9432;** please note that the Dependency Submission API requires `contents: write` persmissions.

### Glob mode

```yml
name: CMake Dependency Submission
on:

on:
push:
branches:
- main
- main

jobs:
dependency-submission:
runs-on: ubuntu-latest
permissions: # The Dependency Submission API requires write permission
contents: write
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- uses: actions/checkout@v3
- uses: philips-forks/cmake-dependency-submission@main
```

- name: Dependency Submission
uses: brenocq/cmake-dependency-submission@main
### Configure mode

```yml
name: CMake Dependency Submission

on:
push:
branches:
- main

jobs:
dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- run: cmake -S example -B build
- uses: philips-forks/cmake-dependency-submission@main
with:
testing-action: "Hello world!"
scanMode: 'configure'
buildPath: 'build'
```

## Non-FetchContent dependencies

When an external dependency is not FetchContent-compatible, or there is another reason to consume a dependency without using FetchContent, the dependency can still be detected by this Action using an annotation in a CMake file.

The annotation should be in the following format:

`# cmake-dependency-scan [package-url]`

Where `[package-url]` should be a valid [Package URL](https://github.com/package-url/purl-spec) like `pkg:github/google/[email protected]`

## License
This project is licensed under the MIT License - check [LICENSE](LICENSE) for details.

This project is licensed under the [MIT](https://choosealicense.com/licenses/mit/) license. See [LICENSE](LICENSE) for details.
23 changes: 15 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
name: 'Cmake Dependency Submission'
description: 'Calculates dependencies for a cmake project and submits the list to the Dependency Submission API'
name: 'CMake Dependency Submission'
description: 'Calculates dependencies for a CMake project and submits the list to the GitHub Dependency Submission API'
author: 'Breno Cunha Queiroz'
branding:
icon: 'check-circle'
icon: 'check-circle'
color: 'blue'
inputs:
token:
description: "GitHub Personal Access Token (PAT). Defaults to PAT provided by Action runner"
required: false
default: ${{ github.token }}
path:
required: false
description: 'Path to cmake project folder'
default: ''
sourcePath:
description: "Path to source tree containing CMakeLists.txt and *.cmake files"
default: "${{ github.workspace }}"
required: false
scanMode:
description: "How to find CMake files; supported values are 'glob' or 'configure'. See README.md for more information"
default: 'glob'
required: false
buildPath:
description: "Path to the pre-configured build tree; only used in 'configure' mode"
required: false
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
Loading