Skip to content

Commit 73fdd9b

Browse files
committed
feat(ci,test): add Ruff linter to CI pipeline and update tests
- Added Ruff linter to GitHub Actions matrix in `.github/workflows/test.yaml`. - Updated README.md with instructions for Ruff. - Created `ruff` feature with `devcontainer-feature.json` and `install.sh`. - Added Ruff linter version check to `all-tools.sh`. - Created Ruff-specific version test script and scenario. - Updated `scenarios.json` to include Ruff-specific test scenarios.
1 parent 8020331 commit 73fdd9b

8 files changed

Lines changed: 196 additions & 26 deletions

File tree

.github/workflows/test.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ jobs:
1313
strategy:
1414
matrix:
1515
features:
16-
- flux
17-
- notation
16+
- copa
1817
- crane
19-
- skopeo
20-
- kyverno
2118
- cyclonedx
22-
- copa
19+
- flux
2320
- gic
24-
- uv
2521
- gitleaks
2622
- jnv
23+
- kyverno
24+
- notation
25+
- ruff
26+
- skopeo
27+
- uv
2728
baseImage:
2829
- debian:latest
2930
- ubuntu:latest

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ This repository contains a _collection_ of Features.
1616
| cyclonedx | https://cyclonedx.org/ | cyclonedx is a command-line tool for working with Software Bill of Materials (SBOM). |
1717
| Copacelic | https://project-copacetic.github.io/copacetic/website/ | Project Copacetic: Directly patch container image vulnerabilities. Copa is a CLI tool written in Go and based on buildkit that can be used to directly patch container images given the vulnerability scanning results from popular tools like Trivy. |
1818
| Gic | https://github.com/jsburckhardt/gic | Reducing cognitive load by automating commit message generation, allowing developers to focus on coding instead of crafting messages. |
19-
| UV/UVX | https://docs.astral.sh/uv/ | An extremely fast Python package and project manager, written in Rust. A single tool to replace pip, pip-tools, pipx, poetry, pyenv, virtualenv, and more. |
2019
| Gitleaks | https://gitleaks.io/ | Gitleaks is a SAST tool for detecting and preventing hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks is an easy-to-use, all-in-one solution for detecting secrets, past or present, in your code. |
2120
| Zarf | https://zarf.dev/ | Zarf eliminates the complexity of air gap software delivery for Kubernetes clusters and cloud-native workloads using a declarative packaging strategy to support DevSecOps in offline and semi-connected environments. |
2221
| jnv | https://github.com/ynqa/jnv | jnv is designed for navigating JSON, offering an interactive JSON viewer and jq filter editor. |
22+
| UV/UVX | https://docs.astral.sh/uv/ | An extremely fast Python package and project manager, written in Rust. A single tool to replace pip, pip-tools, pipx, poetry, pyenv, virtualenv, and more. |
23+
| Ruff | https://docs.astral.sh/ruff/ | An extremely fast Python linter and code formatter, written in Rust. |
2324

2425

2526

@@ -37,7 +38,7 @@ Running `flux` inside the built container will print the help menu of flux.
3738
```
3839

3940
```bash
40-
$ flux
41+
flux
4142
```
4243

4344
### `notation`
@@ -54,7 +55,7 @@ Running `notation` inside the built container will print the help menu of notati
5455
```
5556

5657
```bash
57-
$ notation
58+
notation
5859
```
5960

6061
### `crane`
@@ -71,7 +72,7 @@ Running `crane` inside the built container will print the help menu of crane.
7172
```
7273

7374
```bash
74-
$ crane
75+
crane
7576
```
7677

7778
### `skopeo`
@@ -88,7 +89,7 @@ Running `skopeo` inside the built container will print the help menu of skopeo.
8889
```
8990

9091
```bash
91-
$ skopeo
92+
skopeo
9293
```
9394

9495
### `kyverno`
@@ -105,7 +106,7 @@ Running `kyverno` inside the built container will print the help menu of kyverno
105106
```
106107

107108
```bash
108-
$ kyverno
109+
kyverno
109110
```
110111

111112
### `cyclonedx cli`
@@ -122,7 +123,7 @@ Running `cyclonedx` inside the built container will print the help menu of cyclo
122123
```
123124

124125
```bash
125-
$ cyclonedx --version
126+
cyclonedx --version
126127
```
127128

128129
### `Copacetic cli`
@@ -139,7 +140,7 @@ Running `copa` inside the built container will print the help menu of copa.
139140
```
140141

141142
```bash
142-
$ copa
143+
copa
143144
```
144145

145146
### `Gic`
@@ -156,7 +157,7 @@ Running `Gic` inside the built container will print the help menu of gic.
156157
```
157158

158159
```bash
159-
$ gic --version
160+
gic --version
160161
```
161162

162163
### `Gitleaks`
@@ -173,7 +174,7 @@ Running `gitleaks` inside the built container will print the help menu of gitlea
173174
```
174175

175176
```bash
176-
$ gitleaks
177+
gitleaks
177178
```
178179

179180
### `Zarf`
@@ -190,7 +191,7 @@ Running `zarf` inside the built container will print the help menu of zarf.
190191
```
191192

192193
```bash
193-
$ zarf
194+
zarf
194195
```
195196

196197
### `jnv`
@@ -207,12 +208,12 @@ Running `jnv -h` inside the built container will print the help menu of jnv.
207208
```
208209

209210
```bash
210-
$ jnv -h
211+
jnv -h
211212
```
212213

213214
### `UV/UVX`
214215

215-
Running `uv` or `uvx` inside the built container will print the help menu of gic.
216+
Running `uv` or `uvx` inside the built container will print the help menu of uv/uvx.
216217

217218
```jsonc
218219
{
@@ -224,5 +225,22 @@ Running `uv` or `uvx` inside the built container will print the help menu of gic
224225
```
225226

226227
```bash
227-
$ uv --version
228+
uv --version
229+
```
230+
231+
### `Ruff`
232+
233+
Running `ruff` inside the built container will print the help menu of ruff.
234+
235+
```jsonc
236+
{
237+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
238+
"features": {
239+
"ghcr.io/jsburckhardt/devcontainer-features/ruff:1": {}
240+
}
241+
}
242+
```
243+
244+
```bash
245+
ruff --version
228246
```

src/ruff/devcontainer-feature.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "ruff",
3+
"version": "1.0.0",
4+
"name": "ruff",
5+
"description": "Ruff is a fast Python linter, written in Rust.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"description": "Version of ruff to install. Accepts versions with 'v' prefix.",
10+
"default": "latest"
11+
}
12+
}
13+
}

src/ruff/install.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
# Variables
4+
REPO_OWNER="astral-sh"
5+
REPO_NAME="ruff"
6+
BINARY_NAME="ruff"
7+
8+
set -e
9+
10+
if [ "$(id -u)" -ne 0 ]; then
11+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
12+
exit 1
13+
fi
14+
15+
# Clean up
16+
rm -rf /var/lib/apt/lists/*
17+
18+
check_packages() {
19+
if ! dpkg -s "$@" >/dev/null 2>&1; then
20+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
21+
echo "Running apt-get update..."
22+
apt-get update -y
23+
fi
24+
apt-get -y install --no-install-recommends "$@"
25+
fi
26+
}
27+
28+
# make sure we have packages
29+
check_packages curl tar jq ca-certificates
30+
31+
# Function to get the latest version from GitHub API
32+
get_latest_version() {
33+
LATEST_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest"
34+
curl -s "$LATEST_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
35+
}
36+
37+
# Check if a version is passed as an argument
38+
if [ -z "$VERSION" ] || [ "$VERSION" == "latest" ]; then
39+
# No version provided, get the latest version
40+
VERSION=$(get_latest_version)
41+
echo "No version provided or 'latest' specified, installing the latest version: $VERSION"
42+
else
43+
VERSION=${VERSION#"v"}
44+
echo "Installing version from environment variable: $VERSION"
45+
fi
46+
47+
# Determine the OS and architecture following the naming template
48+
OS=$(uname | tr '[:upper:]' '[:lower:]')
49+
ARCH=$(uname -m)
50+
51+
case "$ARCH" in
52+
x86_64)
53+
ARCH="x86_64"
54+
;;
55+
i686)
56+
ARCH="i686"
57+
;;
58+
armv7l)
59+
ARCH="armv7"
60+
;;
61+
aarch64)
62+
ARCH="aarch64"
63+
;;
64+
powerpc64)
65+
ARCH="powerpc64"
66+
;;
67+
powerpc64le)
68+
ARCH="powerpc64le"
69+
;;
70+
s390x)
71+
ARCH="s390x"
72+
;;
73+
*)
74+
echo "Unsupported architecture: $ARCH"
75+
exit 1
76+
;;
77+
esac
78+
79+
# Construct the download URL to match the naming template
80+
if [[ "$OS" == "darwin" ]]; then
81+
OS="apple-darwin"
82+
elif [[ "$OS" == "linux" ]]; then
83+
OS="unknown-linux-gnu"
84+
else
85+
echo "Unsupported OS: $OS"
86+
exit 1
87+
fi
88+
89+
DOWNLOAD_URL="https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/$VERSION/${REPO_NAME}-${ARCH}-${OS}.tar.gz"
90+
91+
# Create a temporary directory for the download
92+
TMP_DIR=$(mktemp -d)
93+
cd "$TMP_DIR" || exit
94+
95+
# Download the binary tarball
96+
echo "Downloading $BINARY_NAME from $DOWNLOAD_URL"
97+
curl -LO "$DOWNLOAD_URL"
98+
99+
# Extract the tarball
100+
echo "Extracting the tarball"
101+
tar -xzf "${REPO_NAME}-${ARCH}-${OS}.tar.gz"
102+
103+
# Move the binary to /usr/local/bin
104+
echo "Installing $BINARY_NAME"
105+
mv ${REPO_NAME}-${ARCH}-${OS}/* /usr/local/bin/
106+
107+
108+
# Cleanup
109+
cd - || exit
110+
rm -rf "$TMP_DIR"
111+
112+
# Verify installation
113+
echo "Verifying installation"
114+
$BINARY_NAME --version

test/_global/all-tools.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ check "cyclonedx" cyclonedx --version
1111
check "gitleaks" gitleaks version
1212
check "gic" gic --version
1313
check "uv" uv --version
14+
check "ruff" ruff --version
1415
check "jnv" jnv -V
1516
check "zarf" zarf version
1617

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
source dev-container-features-test-lib
5+
check "ruff with specific version" /bin/bash -c "ruff --version | grep '0.7.0'"
6+
7+
reportResults

test/_global/scenarios.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
"all-tools": {
33
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
44
"features": {
5-
"flux": {},
6-
"notation": {},
5+
"copa": {},
76
"crane": {},
8-
"skopeo": {},
9-
"kyverno": {},
107
"cyclonedx": {},
11-
"copa": {},
8+
"flux": {},
129
"gic": {},
13-
"uv": {},
1410
"gitleaks": {},
1511
"jnv": {},
12+
"kyverno": {},
13+
"notation": {},
14+
"ruff": {},
15+
"skopeo": {},
16+
"uv": {},
1617
"zarf": {}
1718
}
1819
},
@@ -72,6 +73,14 @@
7273
}
7374
}
7475
},
76+
"ruff-specific-version": {
77+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
78+
"features": {
79+
"ruff": {
80+
"version": "v0.7.0"
81+
}
82+
}
83+
},
7584
"gitleaks-specific-version": {
7685
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
7786
"features": {

test/ruff/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
check "ruff" ruff -h
7+
reportResults

0 commit comments

Comments
 (0)