Skip to content

Commit ce9faee

Browse files
authored
Merge pull request #6 from buildkite-plugins/codex/export-mise-env-hook
fix: export mise env from hooks
2 parents 550f2a6 + 61ecfdb commit ce9faee

5 files changed

Lines changed: 55 additions & 9 deletions

File tree

.buildkite/pipeline.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
steps:
22
- label: ":sparkles: Tests"
33
plugins:
4-
- plugin-tester#v1.3.0:
5-
pull: true
4+
- plugin-tester#v1.3.0: ~
65

76
- label: ":lint-roller: Lint"
87
plugins:
98
- plugin-linter#v3.0.0:
10-
id: buildkite-plugins/mise
9+
id: buildkite/mise
10+
11+
- label: ":mise: Smoke test"
12+
command:
13+
- "command -v mise"
14+
- "mise --version"
15+
- "command -v shellcheck"
16+
- "shellcheck --version"
17+
- "shellcheck hooks/pre-command tests/pre-command.bats"
18+
plugins:
19+
- ./: ~
1120

1221
- label: ":shell: Shellcheck"
1322
command: shellcheck hooks/*
23+
plugins:
24+
- ./: ~

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shellcheck 0.11.0

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This plugin is intentionally small:
66

77
- `mise` is installed if missing or at the wrong version
88
- `mise install` always runs
9-
- `mise env --shell bash` is always appended to `$BUILDKITE_ENV_FILE`
9+
- `mise env --shell bash` is sourced in the hook and appended to `$BUILDKITE_ENV_FILE`
1010
- tool versions come from the repository, not plugin config
1111

1212
## Example
@@ -15,7 +15,7 @@ This plugin is intentionally small:
1515
steps:
1616
- label: ":wrench: Test"
1717
plugins:
18-
- buildkite-plugins/mise#v1.0.0:
18+
- buildkite/mise#v1.1.0:
1919
version: 2026.2.11
2020
command: go test ./...
2121
```
@@ -26,7 +26,7 @@ steps:
2626
steps:
2727
- label: ":wrench: Test backend"
2828
plugins:
29-
- buildkite-plugins/mise#v1.0.0:
29+
- buildkite/mise#v1.1.0:
3030
dir: backend
3131
command: go test ./...
3232
```
@@ -39,7 +39,7 @@ cache: ".buildkite/cache-volume"
3939
steps:
4040
- label: ":wrench: Test"
4141
plugins:
42-
- buildkite-plugins/mise#v1.0.0: ~
42+
- buildkite/mise#v1.1.0: ~
4343
command: go test ./...
4444
```
4545
@@ -66,7 +66,8 @@ The target directory must contain one of:
6666
Run plugin checks locally:
6767

6868
```bash
69-
docker run --rm -v "$PWD:/plugin" -w /plugin buildkite/plugin-linter --id buildkite-plugins/mise --path /plugin
69+
mise install
70+
docker run --rm -v "$PWD:/plugin" -w /plugin buildkite/plugin-linter --id buildkite/mise --path /plugin
7071
docker run --rm -v "$PWD:/plugin" -w /plugin buildkite/plugin-tester
7172
"$(mise where shellcheck@0.11.0)/shellcheck-v0.11.0/shellcheck" hooks/pre-command tests/pre-command.bats
7273
```

hooks/pre-command

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ append_export() {
4242
append_to_buildkite_env "$(printf 'export %s=%q' "$name" "$value")"
4343
}
4444

45+
apply_mise_env() {
46+
local mise_env_file
47+
48+
mise_env_file="$(mktemp)"
49+
run_mise env --shell bash | tee -a "$BUILDKITE_ENV_FILE" > "$mise_env_file"
50+
51+
# Source the generated exports so later host-side hooks inherit the tool env.
52+
# shellcheck disable=SC1090
53+
. "$mise_env_file"
54+
rm -f "$mise_env_file"
55+
}
56+
4557
cleanup_install_mise() {
4658
rm -f "$1"
4759
rm -rf "$2"
@@ -260,7 +272,11 @@ main() {
260272
append_export MISE_DATA_DIR "$MISE_DIR"
261273
append_export MISE_TRUSTED_CONFIG_PATHS "$WORKING_DIRECTORY"
262274
append_export MISE_YES "1"
263-
run_mise env --shell bash >> "$BUILDKITE_ENV_FILE"
275+
276+
export MISE_DATA_DIR="$MISE_DIR"
277+
export MISE_TRUSTED_CONFIG_PATHS="$WORKING_DIRECTORY"
278+
export MISE_YES="1"
279+
apply_mise_env
264280

265281
echo "~~~ :white_check_mark: mise setup complete"
266282
}

tests/pre-command.bats

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ MOCK
131131
grep -F "export PATH=\"${MISE_DATA_DIR}/installs/go/1.0.0/bin:\$PATH\"" "${BUILDKITE_ENV_FILE}"
132132
}
133133

134+
@test "exports mise environment in the hook shell" {
135+
printf 'go 1.0.0\n' > "${BUILDKITE_BUILD_CHECKOUT_PATH}/.tool-versions"
136+
137+
run bash -c "
138+
. hooks/pre-command >/dev/null
139+
env | grep -Fx 'TEST_ENV=ok'
140+
env | grep -Fx 'MISE_TRUSTED_CONFIG_PATHS=${BUILDKITE_BUILD_CHECKOUT_PATH}'
141+
env | grep -Fx 'MISE_YES=1'
142+
case \":\$PATH:\" in
143+
*\":${MISE_DATA_DIR}/installs/go/1.0.0/bin:\"*) ;;
144+
*) exit 1 ;;
145+
esac
146+
"
147+
148+
[ "${status}" -eq 0 ]
149+
}
150+
134151
@test "uses dir config for monorepos" {
135152
subdir="${BUILDKITE_BUILD_CHECKOUT_PATH}/backend"
136153
mkdir -p "${subdir}"

0 commit comments

Comments
 (0)