Skip to content

Commit 4ec3704

Browse files
authored
Merge pull request #4 from secondlife/signal/composer
Add --composer for PHP
2 parents a89efe2 + c5c5241 commit 4ec3704

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

test/test.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,26 @@ create_osrelease() {
273273
assert_success
274274
assert_equal "$(<$TMPDIR/etc/pip.conf)" "old"
275275
}
276+
277+
@test "composer auth.json is set up" {
278+
export CLOUDSMITH_API_KEY="test-api-key"
279+
run with-cloudsmith --composer --keep
280+
assert_success
281+
[ -f $TMPDIR$HOME/.config/composer/auth.json ]
282+
}
283+
284+
@test "composer auth.json is cleaned up" {
285+
export CLOUDSMITH_API_KEY="test-api-key"
286+
run with-cloudsmith --composer
287+
assert_success
288+
[ ! -f $TMPDIR$HOME/.config/composer/auth.json ]
289+
}
290+
291+
@test "existing composer auth.json is restored" {
292+
export CLOUDSMITH_API_KEY="test-api-key"
293+
mkdir -p "$TMPDIR$HOME/.config/composer"
294+
echo "old" > $TMPDIR$HOME/.config/composer/auth.json
295+
run with-cloudsmith --composer
296+
assert_success
297+
assert_equal "$(<$TMPDIR$HOME/.config/composer/auth.json)" "old"
298+
}

with-cloudsmith

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Options:
2828
-v, --verbose Enable verbose output
2929
-vv Enable debug output
3030
-s, --silent Silence output
31+
--composer Enable Composer registry
3132
--pip Enable PIP registry
3233
--deb Enable Debian registry
3334
-k, --keep Keep temporary files
@@ -60,6 +61,10 @@ while [[ $# -gt 0 ]]; do
6061
LOGLEVEL=$LOGLEVEL_WARN
6162
shift
6263
;;
64+
--composer)
65+
REGISTRIES+=("composer")
66+
shift
67+
;;
6368
--pip)
6469
REGISTRIES+=("pip")
6570
shift
@@ -362,6 +367,38 @@ function teardown_deb {
362367
rm -rf "$ROOT/etc/apt/sources.list.d/$CLOUDSMITH_ORG-$CLOUDSMITH_REPO.list"
363368
}
364369

370+
################################
371+
# PHP Composer
372+
################################
373+
374+
function setup_composer {
375+
local auth_file="$ROOT$HOME/.config/composer/auth.json"
376+
if [ -f "$auth_file" ]; then
377+
mv "$auth_file" "$auth_file.bak"
378+
fi
379+
380+
mkdir -p "$(dirname "$auth_file")"
381+
382+
cat > "$auth_file" << EOF
383+
{
384+
"http-basic": {
385+
"dl.cloudsmith.io": {
386+
"username": "$CLOUDSMITH_USER",
387+
"password": "$CLOUDSMITH_PASSWORD"
388+
}
389+
}
390+
}
391+
EOF
392+
}
393+
394+
function teardown_composer {
395+
local auth_file="$ROOT$HOME/.config/composer/auth.json"
396+
rm -rf "$auth_file"
397+
if [ -f "$auth_file.bak" ]; then
398+
mv "$auth_file.bak" "$auth_file"
399+
fi
400+
}
401+
365402
################################
366403
# Python PIP
367404
################################
@@ -394,6 +431,7 @@ function teardown_pip {
394431
function setup {
395432
load_creds
396433
if have_creds; then
434+
if registry_enabled composer; then setup_composer; fi
397435
if registry_enabled deb; then setup_deb; fi
398436
if registry_enabled pip; then setup_pip; fi
399437
else
@@ -402,6 +440,7 @@ function setup {
402440
}
403441

404442
function cleanup {
443+
if registry_enabled composer; then teardown_composer; fi
405444
if registry_enabled pip; then teardown_pip; fi
406445
if registry_enabled deb; then teardown_deb; fi
407446
}

0 commit comments

Comments
 (0)