Skip to content

Commit

Permalink
fix: default to "locked" if "highest" or "lowest" not passed
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Dec 24, 2021
1 parent f22409e commit 966a519
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
8 changes: 8 additions & 0 deletions bin/cache_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ function join_by {
fi
}

# Ensure "highest", "lowest", and "locked" are the only values
# allowed for dependency_versions.
case "${dependency_versions}" in
highest) ;;
lowest) ;;
*) dependency_versions="locked" ;;
esac

if [ -n "${custom_cache_key}" ]; then
key+=("${custom_cache_key}")
else
Expand Down
4 changes: 2 additions & 2 deletions bin/composer_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ composer_options=(
)

case "${dependency_versions}" in
locked) composer_command="install" ;;
lowest) composer_options+=("--prefer-lowest" "--prefer-stable") ;;
highest) ;;
lowest) composer_options+=("--prefer-lowest" "--prefer-stable") ;;
*) composer_command="install" ;;
esac

IFS=' '
Expand Down
29 changes: 29 additions & 0 deletions tests/expect/cache_key_07.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env -S expect -f

set gitHubEnvFile cache_key_07.txt
file delete $gitHubEnvFile
set ::env(GITHUB_ENV) $gitHubEnvFile

set timeout 3
spawn ../../bin/cache_key.sh "Windows" "8.0.2" "foobar" "" "some-other-hash"
match_max 100000

expect -exact "::notice title=Primary Cache Key::Cache primary key is 'Windows-php-8.0.2-composer-locked-some-other-hash'"
expect -exact "::notice title=Restore Cache Keys::Cache restore keys are 'Windows-php-8.0.2-composer-locked-'"
expect -exact "::set-output name=key::Windows-php-8.0.2-composer-locked-some-other-hash"
expect eof

set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp

set expectedValue "CACHE_RESTORE_KEY<<EOF
Windows-php-8.0.2-composer-locked-
EOF
"

if { $expectedValue != $fileData } {
puts "\nExpected environment variable does not match. Received:\n"
puts $fileData
exit 1
}
10 changes: 10 additions & 0 deletions tests/expect/composer_install_17.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "foobar"
match_max 100000

expect -exact "::notice title=Composer::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi '"
expect "Installing dependencies from lock file (including require-dev)"
expect "Generating autoload files"
expect eof

0 comments on commit 966a519

Please sign in to comment.