mirror of
https://github.com/actions-rust-lang/audit.git
synced 2025-12-27 01:43:48 -05:00
Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
579aeab71c | ||
|
|
0a7806b229 | ||
|
|
4fb4af0611 | ||
|
|
1aae8517bc | ||
|
|
202eeee8b4 | ||
|
|
34bae80559 | ||
|
|
23dacfdca9 | ||
|
|
dafa32a4e4 | ||
|
|
06105d122a | ||
|
|
af2ca4abcf | ||
|
|
de806b6f80 | ||
|
|
e12665dbfb | ||
|
|
fdc8c6b8ea | ||
|
|
42ea4d34ab | ||
|
|
b4380b6dac | ||
|
|
96e0e19d75 | ||
|
|
d57b2706e6 | ||
|
|
6028f82778 | ||
|
|
5bcf9487c7 | ||
|
|
165f86c1a6 | ||
|
|
5c5da92c03 | ||
|
|
17d62dc82d | ||
|
|
733aff2088 | ||
|
|
95e05e5d8e | ||
|
|
969643f199 | ||
|
|
7614934373 | ||
|
|
946808f018 | ||
|
|
1fcfd212ac | ||
|
|
d26dd44917 | ||
|
|
645e2942e8 | ||
|
|
965b6233a3 | ||
|
|
9fe902be91 | ||
|
|
94cd57b0d8 | ||
|
|
5330a4041e | ||
|
|
531fba54da | ||
|
|
31383575a9 | ||
|
|
e2ad894c8f | ||
|
|
e4b4ec6817 | ||
|
|
b0169fdb1a | ||
|
|
de48309832 | ||
|
|
f007442857 | ||
|
|
8a4f84d32b | ||
|
|
4a6925b10a | ||
|
|
fae1c3e0b7 | ||
|
|
7fe0328ae6 | ||
|
|
e3466a0192 | ||
|
|
1bedf5d769 | ||
|
|
4ef6a36667 | ||
|
|
9a5a196eb1 | ||
|
|
74871ea769 | ||
|
|
62b30a4d5b | ||
|
|
fa1f058f19 | ||
|
|
1e389b4122 | ||
|
|
a6eeed1940 | ||
|
|
1ca8cd30ac | ||
|
|
0ddaadad09 | ||
|
|
160ac8b6ed | ||
|
|
b8800a8c21 | ||
|
|
1010e1e336 | ||
|
|
72f0fdca3b | ||
|
|
cbff13557b | ||
|
|
08bf11f3ea | ||
|
|
7049db077c | ||
|
|
e8ea165957 | ||
|
|
1926841165 | ||
|
|
08a60eccbb | ||
|
|
16af786dc7 | ||
|
|
ddc21578b3 | ||
|
|
c37ceabcab | ||
|
|
342fdff255 | ||
|
|
b719ea468c | ||
|
|
25528f1e0b | ||
|
|
f4430692fd | ||
|
|
0f2a92891d | ||
|
|
c248204ea6 | ||
|
|
e7db852e4a | ||
|
|
494d723603 |
@@ -1,10 +1,10 @@
|
||||
repos:
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 24.1.1
|
||||
rev: 25.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.5.0
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: check-ast
|
||||
- id: check-case-conflict
|
||||
@@ -14,24 +14,24 @@ repos:
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 5.13.2
|
||||
rev: 6.0.1
|
||||
# https://github.com/psf/black/blob/main/docs/guides/using_black_with_other_tools.md
|
||||
hooks:
|
||||
- id: isort
|
||||
args: ["--profile=black"]
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.15.0
|
||||
rev: v3.19.1
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: ["--py37-plus"]
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v1.8.0
|
||||
rev: v1.15.0
|
||||
hooks:
|
||||
- id: mypy
|
||||
additional_dependencies:
|
||||
- types-requests
|
||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
||||
rev: 0.28.0
|
||||
rev: 0.31.2
|
||||
hooks:
|
||||
- id: check-dependabot
|
||||
- id: check-github-actions
|
||||
|
||||
23
CHANGELOG.md
23
CHANGELOG.md
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.2.4] - 2025-03-03
|
||||
|
||||
* Update `cargo-audit` to 0.21.2
|
||||
|
||||
## [1.2.3] - 2024-12-17
|
||||
|
||||
* Show a better error message when running "cargo audit" fails #98
|
||||
|
||||
## [1.2.2] - 2024-11-06
|
||||
|
||||
* Update `cargo-audit` to 0.21.0
|
||||
|
||||
## [1.2.1] - 2024-07-31
|
||||
|
||||
* Temporarily remove `--locked` from the install instructions again, since cargo-audit relies on an old version of `time` that is incompatible with Rust 1.80.
|
||||
|
||||
## [1.2.0] - 2024-03-05
|
||||
|
||||
* feat: add --locked to cargo install cargo-audit by @lwshang in #72
|
||||
* Add working directory input to configure where cargo audit executes by @jonasbb in #78
|
||||
|
||||
## [1.1.14] - 2024-02-18
|
||||
|
||||
* Update `cargo-audit` to 0.20.0
|
||||
@@ -22,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [1.1.11] - 2024-01-18
|
||||
|
||||
* Allow specifying the path to the `Cargo.lock` file, in case it is not in the root of the repository (#55)
|
||||
* Update the example in the readme, to have the correct permissions for private repositories.
|
||||
* Update the example in the README, to have the correct permissions for private repositories.
|
||||
|
||||
## [1.1.10] - 2023-11-02
|
||||
|
||||
|
||||
31
README.md
31
README.md
@@ -1,6 +1,6 @@
|
||||
# Audit Rust dependencies using the RustSec Advisory DB
|
||||
|
||||
Audit your Rust dependencies using [cargo audit] and the [RustSec Advisory DB]. The action creates a summary with all vulnerabilieties. It can create issues for each of the found vulnerabilities.
|
||||
Audit your Rust dependencies using [cargo audit] and the [RustSec Advisory DB]. The action creates a summary with all vulnerabilities. It can create issues for each of the found vulnerabilities.
|
||||
|
||||
Execution Summary:
|
||||
|
||||
@@ -44,18 +44,31 @@ jobs:
|
||||
## Inputs
|
||||
|
||||
All inputs are optional.
|
||||
Consider adding a [`audit.toml` configuration file] to your repository for further configurations.
|
||||
Consider adding an [`audit.toml` configuration file] to your repository for further configurations.
|
||||
cargo audit supports multiple warning types, such as unsound code or yanked crates.
|
||||
Configuration is only possible via the `informational_warnings` parameter in the configuration file ([#318](https://github.com/rustsec/rustsec/issues/318)).
|
||||
Setting `denyWarnings` to true will also enable these warnings, but each warning is upgraded to an error.
|
||||
|
||||
| Name | Description | Default |
|
||||
| -------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
|
||||
| `TOKEN` | The GitHub access token to allow us to retrieve, create and update issues (automatically set). | `github.token` |
|
||||
| `denyWarnings` | Any warnings generated will be treated as an error and fail the action. | false |
|
||||
| `file` | The path to the Cargo.lock file. | |
|
||||
| `ignore` | A comma separated list of Rustsec IDs to ignore. | |
|
||||
| `createIssues` | Create/Update issues for each found vulnerability. By default only on `main` or `master` branch. | `github.ref == 'refs/heads/master' \|\| github.ref == 'refs/heads/main'` |
|
||||
| Name | Description | Default |
|
||||
| ------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
|
||||
| `TOKEN` | The GitHub access token to allow us to retrieve, create and update issues (automatically set). | `github.token` |
|
||||
| `denyWarnings` | Any warnings generated will be treated as an error and fail the action. | false |
|
||||
| `file` | The path to the Cargo.lock file to inspect file. | |
|
||||
| `ignore` | A comma separated list of Rustsec IDs to ignore. | |
|
||||
| `createIssues` | Create/Update issues for each found vulnerability. By default only on `main` or `master` branch. | `github.ref == 'refs/heads/master' \|\| github.ref == 'refs/heads/main'` |
|
||||
| `workingDirectory` | Run `cargo audit` from the given working directory | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
The action works best on the GitHub-hosted runners, but can work on self-hosted ones too, provided the necessary dependencies are available.
|
||||
PRs to add support for more environments are welcome.
|
||||
|
||||
* bash
|
||||
* Python 3.9+
|
||||
* requests
|
||||
* Rust stable
|
||||
* cargo
|
||||
* use node actions
|
||||
|
||||
## License
|
||||
|
||||
|
||||
11
action.yml
11
action.yml
@@ -15,7 +15,7 @@ inputs:
|
||||
required: false
|
||||
default: "false"
|
||||
file:
|
||||
description: "Cargo lockfile to inspect"
|
||||
description: "The path to the Cargo.lock file to inspect"
|
||||
required: false
|
||||
default: ""
|
||||
ignore:
|
||||
@@ -26,6 +26,10 @@ inputs:
|
||||
description: Create/Update issues for each found vulnerability.
|
||||
required: false
|
||||
default: "${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}"
|
||||
workingDirectory:
|
||||
description: "Run `cargo audit` from the given working directory"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
@@ -41,12 +45,12 @@ runs:
|
||||
${{ steps.cargo-home.outputs.cargohome }}/bin/cargo-audit*
|
||||
${{ steps.cargo-home.outputs.cargohome }}/.crates.toml
|
||||
${{ steps.cargo-home.outputs.cargohome }}/.crates2.json
|
||||
key: cargo-audit-v0.20.0
|
||||
key: cargo-audit-v0.21.2
|
||||
|
||||
- name: Install cargo-audit
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
# Update both this version number and the cache key
|
||||
run: cargo install cargo-audit --vers 0.20.0 --no-default-features
|
||||
run: cargo install cargo-audit --vers 0.21.2 --no-default-features
|
||||
shell: bash
|
||||
|
||||
- run: |
|
||||
@@ -59,5 +63,6 @@ runs:
|
||||
INPUT_FILE: ${{ inputs.file }}
|
||||
INPUT_IGNORE: ${{ inputs.ignore }}
|
||||
INPUT_TOKEN: ${{ inputs.TOKEN }}
|
||||
INPUT_WORKING_DIRECTORY: ${{ inputs.workingDirectory }}
|
||||
PYTHONPATH: ${{ github.action_path }}
|
||||
REPO: ${{ github.repository }}
|
||||
|
||||
40
audit.py
40
audit.py
@@ -7,18 +7,32 @@ from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
import requests
|
||||
|
||||
# GitHub API CLient copied and adapted from
|
||||
# GitHub API Client copied and adapted from
|
||||
# https://github.com/alstr/todo-to-issue-action/blob/25c80e9c4999d107bec208af49974d329da26370/main.py
|
||||
# Originally licensed under MIT license
|
||||
|
||||
# Timeout in seconds for requests methods
|
||||
TIMEOUT = 30
|
||||
"""Timeout in seconds for requests methods"""
|
||||
|
||||
NEWLINE = "\n"
|
||||
"""Definition of newline"""
|
||||
|
||||
|
||||
def debug(message: str) -> None:
|
||||
"""Print a debug message to the GitHub Action log"""
|
||||
newline = "\n"
|
||||
print(f"""::debug::{message.replace(newline, " ")}""")
|
||||
print(f"""::debug::{message.replace(NEWLINE, " ")}""")
|
||||
|
||||
|
||||
def error(message: str) -> None:
|
||||
"""Print an error message to the GitHub Action log"""
|
||||
print(f"""::error::{message.replace(NEWLINE, " ")}""")
|
||||
|
||||
|
||||
def group(title: str, message: str) -> None:
|
||||
"""Print an expandable group message to the GitHub Action log"""
|
||||
print(f"::group::{title}")
|
||||
print(message)
|
||||
print("::endgroup::")
|
||||
|
||||
|
||||
class Issue:
|
||||
@@ -404,10 +418,15 @@ def run() -> None:
|
||||
extra_args.append("--file")
|
||||
extra_args.append(os.environ["INPUT_FILE"])
|
||||
|
||||
working_directory = None
|
||||
if os.environ["INPUT_WORKING_DIRECTORY"] != "":
|
||||
working_directory = os.environ["INPUT_WORKING_DIRECTORY"]
|
||||
|
||||
audit_cmd = ["cargo", "audit", "--json"] + extra_args + ignore_args
|
||||
debug(f"Running command: {audit_cmd}")
|
||||
completed = subprocess.run(
|
||||
audit_cmd,
|
||||
cwd=working_directory,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
@@ -415,7 +434,18 @@ def run() -> None:
|
||||
debug(f"Command return code: {completed.returncode}")
|
||||
debug(f"Command output: {completed.stdout}")
|
||||
debug(f"Command error: {completed.stderr}")
|
||||
data = json.loads(completed.stdout)
|
||||
try:
|
||||
data = json.loads(completed.stdout)
|
||||
except json.decoder.JSONDecodeError as _:
|
||||
error(
|
||||
f"cargo audit did not produce any JSON output. Exit code: {completed.returncode}"
|
||||
)
|
||||
group(
|
||||
"cargo audit output",
|
||||
f"""stdout:\n{completed.stdout}\n\n\nstderr:\n{completed.stderr}""",
|
||||
)
|
||||
|
||||
sys.exit(2)
|
||||
|
||||
summary = create_summary(data)
|
||||
entries = create_entries(data)
|
||||
|
||||
Reference in New Issue
Block a user