Skip to content

Commit 1fab03c

Browse files
authored
Merge pull request #126 from scaryrawr/pn-shim-support
Add pn artifact helper shim
2 parents 1b21aac + 7400deb commit 1fab03c

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎src/artifacts-helper/devcontainer-feature.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Azure Artifacts Credential Helper",
33
"id": "artifacts-helper",
4-
"version": "3.1.1",
4+
"version": "3.1.2",
55
"description": "Configures Codespace to authenticate with Azure Artifact feeds",
66
"options": {
77
"nugetURIPrefixes": {

‎src/artifacts-helper/install.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ if [ "${ALIAS_RUSH}" = "true" ]; then
3838
ALIASES_ARR+=('rush-pnpm')
3939
fi
4040
if [ "${ALIAS_PNPM}" = "true" ]; then
41+
ALIASES_ARR+=('pn')
4142
ALIASES_ARR+=('pnpm')
4243
ALIASES_ARR+=('pnpx')
4344
fi

‎src/artifacts-helper/scripts/pn‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# If ACTIONS_ID_TOKEN_REQUEST_URL is set, we're in GitHub Actions - skip Azure DevOps setup
4+
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then
5+
source "$(dirname $0)"/resolve-shim.sh
6+
PN_EXE="$(resolve_shim)"
7+
"${PN_EXE}" "$@"
8+
exit $?
9+
fi
10+
11+
source "$(dirname $0)"/auth-ado.sh
12+
source "$(dirname $0)"/resolve-shim.sh
13+
14+
PN_EXE="$(resolve_shim)"
15+
ARTIFACTS_ACCESSTOKEN="${ARTIFACTS_ACCESSTOKEN:-}" ${PN_EXE} "$@"

‎test/artifacts-helper/test_shim_integration.sh‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,39 @@ check "dotnet shim handles missing auth helper" bash -c '
2020
# Test that the shim scripts properly source auth-ado.sh
2121
check "dotnet shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/dotnet
2222
check "npm shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/npm
23+
check "pn shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/pn
2324
check "corepack shim sources auth-ado.sh" grep -q "source.*auth-ado.sh" /usr/local/share/codespace-shims/corepack
2425

2526
# Verify the shim directory is in PATH
2627
check "shim directory in PATH" bash -c '[[ ":$PATH:" == *":/usr/local/share/codespace-shims:"* ]]'
2728

2829
# Verify that shell function shims are written to rc files (not just shim scripts)
2930
check "npm shell function written to bash.bashrc" grep -q "npm()" /etc/bash.bashrc
31+
check "pn shell function written to bash.bashrc" grep -q "pn()" /etc/bash.bashrc
3032
check "corepack shell function written to bash.bashrc" grep -q "corepack()" /etc/bash.bashrc
3133
check "dotnet shell function written to bash.bashrc" grep -q "dotnet()" /etc/bash.bashrc
3234
check "npm shell function on its own line in bash.bashrc" grep -q "^npm()" /etc/bash.bashrc
3335

3436
# Verify aliases include proper quoting and argument passing ($@)
3537
check "dotnet alias has quoted path and passes args" grep -q 'dotnet() { ".*/dotnet" "\$@"; }' /etc/bash.bashrc
3638
check "npm alias has quoted path and passes args" grep -q 'npm() { ".*/npm" "\$@"; }' /etc/bash.bashrc
39+
check "pn alias has quoted path and passes args" grep -q 'pn() { ".*/pn" "\$@"; }' /etc/bash.bashrc
3740
check "corepack alias has quoted path and passes args" grep -q 'corepack() { ".*/corepack" "\$@"; }' /etc/bash.bashrc
3841

42+
check "pn shim delegates to the underlying pn command" bash -c '
43+
TEST_DIR=$(mktemp -d)
44+
trap "rm -rf \"$TEST_DIR\"" EXIT
45+
mkdir -p "$TEST_DIR/bin"
46+
printf "#!/bin/bash\nprintf \"%%s\\n\" \"\$@\" > \"%s/args\"\n" "$TEST_DIR" > "$TEST_DIR/bin/pn"
47+
chmod +x "$TEST_DIR/bin/pn"
48+
49+
PATH="/usr/local/share/codespace-shims:$TEST_DIR/bin:/usr/bin:/bin" \
50+
ACTIONS_ID_TOKEN_REQUEST_URL=test \
51+
/usr/local/share/codespace-shims/pn install --frozen-lockfile
52+
53+
diff -u <(printf "install\n--frozen-lockfile\n") "$TEST_DIR/args"
54+
'
55+
3956
# Verify Corepack lifecycle commands target the real binary directory rather than the shim directory.
4057
check "corepack enable targets the real binary directory" bash -c '
4158
TEST_DIR=$(mktemp -d)

0 commit comments

Comments
 (0)