Skip to content

Commit 84c50bd

Browse files
authored
Merge branch 'main' into fix/biome
2 parents b6861d2 + 68b7378 commit 84c50bd

File tree

6 files changed

+230
-0
lines changed

6 files changed

+230
-0
lines changed

actions/uv/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# uv
2+
3+
## Recommended Usage
4+
5+
The recommended way to run [uv](https://docs.astral.sh/uv/) using Trunk is to use the SYSTEM
6+
environment, rather than a hermetic setup. This is because uv provides its own environment
7+
management that will often collide with Trunk's hermetic setup. Nevertheless, leveraging uv and
8+
Trunk in parallel can be powerful.
9+
10+
Trunk provides several different Actions for running your uv validation and dependency management.
11+
12+
| action | description |
13+
| ---------- | ------------------------------------------------------------------------------ |
14+
| `uv-check` | Validate `pyproject.toml` when running `git commit` |
15+
| `uv-lock` | Create or update `uv.lock` when running `git commit` |
16+
| `uv-sync` | Install dependencies from `uv.lock` when running `git checkout` or `git merge` |
17+
18+
You can enable any subset of these Actions using `trunk actions enable`.
19+
20+
As written, all of these actions require that you have `uv` in your `PATH` in order to run.
21+
22+
## Hermetic Installation
23+
24+
Trunk provides some mechanisms for a hermetic installation and execution of `uv`. You can use the uv
25+
[Tool](https://docs.trunk.io/check/advanced-setup/tools) to run `uv` manually, and you can override
26+
each of the action definitions to include the `packages_file` and `runtime`, like so:
27+
28+
```yaml
29+
version: 0.1
30+
actions:
31+
definitions:
32+
- id: uv-check
33+
runtime: python
34+
packages_file: ${cwd}/requirements.txt
35+
```
36+
37+
These overrides will tell Trunk to use the hermetic install of `uv` and use a sandboxed execution
38+
for the Action. Note that this approach has some limitations, namely when creating uv virtual
39+
environments. Currently full functionality is blocked by the inability to unset runtime-inherited
40+
environments. Note that the `uv` Tool suffers from the same problem.
41+
42+
When using the hermetic installation, you will want to ensure that your `python` runtime is enabled
43+
at the same version required by your uv configuration. See our
44+
[docs](https://docs.trunk.io/check/advanced-setup/runtimes) for more information about specifying
45+
runtime versions.
46+
47+
## Notes
48+
49+
uv requires Python 3.8 or higher to run.

actions/uv/plugin.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: 0.1
2+
# NOTE: See README.md for usage guidelines.
3+
actions:
4+
definitions:
5+
- id: uv-check
6+
display_name: uv check
7+
description: Run 'uv check' to validate the project configuration.
8+
run: uv check
9+
triggers:
10+
- git_hooks: [pre-commit]
11+
environment:
12+
- name: VIRTUAL_ENV
13+
value: ${env.VIRTUAL_ENV}
14+
optional: true
15+
16+
- id: uv-lock
17+
display_name: uv lock
18+
description: Run 'uv lock' to create or update the lock file.
19+
run: uv lock
20+
triggers:
21+
- git_hooks: [pre-commit]
22+
environment:
23+
- name: VIRTUAL_ENV
24+
value: ${env.VIRTUAL_ENV}
25+
optional: true
26+
27+
- id: uv-sync
28+
display_name: uv sync
29+
description: Run 'uv sync' to install dependencies from the lock file.
30+
run: uv sync
31+
triggers:
32+
- git_hooks: [post-checkout, post-merge]
33+
environment:
34+
- name: VIRTUAL_ENV
35+
value: ${env.VIRTUAL_ENV}
36+
optional: true
37+
38+
tools:
39+
definitions:
40+
- name: uv
41+
runtime: python
42+
package: uv
43+
known_good_version: 0.7.8
44+
health_checks:
45+
- command: uv --version
46+
parse_regex: ${semver}
47+
shims: [uv]

actions/uv/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uv==0.7.8

actions/uv/uv.test.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
import { actionRunTest, toolInstallTest } from "tests";
4+
import { TrunkActionDriver } from "tests/driver";
5+
6+
toolInstallTest({
7+
toolName: "uv",
8+
toolVersion: "0.3",
9+
});
10+
11+
const preCheck = (driver: TrunkActionDriver) => {
12+
const trunkYamlPath = ".trunk/trunk.yaml";
13+
const currentContents = driver.readFile(trunkYamlPath);
14+
const newContents = currentContents.concat(`
15+
definitions:
16+
- id: uv-check
17+
runtime: python
18+
- id: uv-lock
19+
runtime: python
20+
- id: uv-sync
21+
runtime: python`);
22+
driver.writeFile(trunkYamlPath, newContents);
23+
24+
driver.writeFile(
25+
"pyproject.toml",
26+
`[project]
27+
name = "uv-test"
28+
version = "0.1.0"
29+
description = ""
30+
31+
[project.dependencies]
32+
python = "^3.12"
33+
pendulum = "^3.0.0"
34+
`,
35+
);
36+
};
37+
38+
const checkTestCallback = async (driver: TrunkActionDriver) => {
39+
try {
40+
await driver.gitDriver?.commit(
41+
"Test commit",
42+
[],
43+
{ "--allow-empty": null },
44+
(error, result) => {
45+
// uv check should pass for a valid pyproject.toml
46+
expect(error).toBeFalsy();
47+
expect(result).toBeTruthy();
48+
},
49+
);
50+
} catch {
51+
// Intentionally empty
52+
}
53+
};
54+
55+
const fileExistsCallback = (filename: string) => async (driver: TrunkActionDriver) => {
56+
try {
57+
await driver.gitDriver?.commit(
58+
"Test commit",
59+
[],
60+
{ "--allow-empty": null },
61+
(_error, result) => {
62+
expect(_error).toBeFalsy();
63+
expect(result).toBeTruthy();
64+
},
65+
);
66+
67+
expect(fs.existsSync(path.resolve(driver.getSandbox(), filename))).toBeTruthy();
68+
} catch {
69+
// Intentionally empty
70+
}
71+
};
72+
73+
actionRunTest({
74+
actionName: "uv-check",
75+
syncGitHooks: true,
76+
testCallback: checkTestCallback,
77+
preCheck: preCheck,
78+
});
79+
80+
actionRunTest({
81+
actionName: "uv-lock",
82+
syncGitHooks: true,
83+
testCallback: fileExistsCallback("uv.lock"),
84+
preCheck: preCheck,
85+
});
86+
87+
actionRunTest({
88+
actionName: "uv-sync",
89+
syncGitHooks: true,
90+
testCallback: fileExistsCallback(".venv"), // Assuming uv creates a .venv by default
91+
preCheck: preCheck,
92+
});

tools/flyway/flyway.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { makeToolTestConfig, toolTest } from "tests";
2+
3+
toolTest({
4+
toolName: "flyway",
5+
toolVersion: "11.9.2",
6+
testConfigs: [
7+
makeToolTestConfig({
8+
command: ["flyway", "--version"],
9+
expectedOut: "Flyway OSS Edition 11.9.2 by Redgate",
10+
}),
11+
],
12+
});

tools/flyway/plugin.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: 0.1
2+
downloads:
3+
- name: flyway
4+
args:
5+
semver: ${version}=>flyway-(?P<semver>.*)
6+
downloads:
7+
- os:
8+
linux: linux
9+
macos: macosx
10+
cpu:
11+
x86_64: x64
12+
arm_64: arm64
13+
url: https://github.com/flyway/flyway/releases/download/flyway-${semver}/flyway-commandline-${semver}-${os}-${cpu}.tar.gz
14+
strip_components: 1
15+
- os:
16+
windows: Windows
17+
cpu:
18+
x86_64: amd64
19+
arm_64: arm64
20+
url: https://github.com/flyway/flyway/releases/download/flyway-${semver}/flyway-commandline-${semver}-windows-x64.zip
21+
strip_components: 1
22+
tools:
23+
definitions:
24+
- name: flyway
25+
download: flyway
26+
known_good_version: 11.9.2
27+
shims:
28+
- name: flyway
29+
target: flyway

0 commit comments

Comments
 (0)