Skip to content

Commit

Permalink
feat: force use of "update" if there is no lock file
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Dec 31, 2021
1 parent fcd69c7 commit 9389fa5
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 37 deletions.
5 changes: 2 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ runs:
if: steps.should-cache.outputs.do-cache == 1
shell: "bash"
run: |
composer_json="${{ steps.composer.outputs.json }}"
composer_lock="${{ steps.composer.outputs.lock }}"
${GITHUB_ACTION_PATH}/bin/cache_key.sh \
"${{ runner.os }}" \
"${{ steps.php.outputs.version }}" \
Expand All @@ -87,4 +85,5 @@ runs:
"${{ inputs.composer-options }}" \
"${{ inputs.working-directory }}" \
"${{ steps.php.outputs.path }}" \
"${{ steps.composer.outputs.command }}"
"${{ steps.composer.outputs.command }}" \
"${{ steps.composer.outputs.lock }}"
6 changes: 6 additions & 0 deletions bin/composer_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ additional_composer_options="${2}"
working_directory="${3}"
php_path="${4:-$(which php)}"
composer_path="${5:-$(which composer)}"
composer_lock="${6}"

composer_command="update"
composer_options=("--no-interaction" "--no-progress" "--ansi")
Expand All @@ -15,6 +16,11 @@ case "${dependency_versions}" in
*) composer_command="install" ;;
esac

# If there is no composer.lock file, then use the `update` command.
if [ -z "${composer_lock}" ]; then
composer_command="update"
fi

read -r -a additional_options <<<"${additional_composer_options}"
composer_options+=("${additional_options[@]}")

Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_01.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

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

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi'"
expect "Installing dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_02.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "lowest"
spawn ../../bin/composer_install.sh "lowest" "" "" "" "" "composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable'"
expect "Updating dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_03.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "highest"
spawn ../../bin/composer_install.sh "highest" "" "" "" "" "composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi'"
expect "Updating dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_04.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "locked"
spawn ../../bin/composer_install.sh "locked" "" "" "" "" "composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi'"
expect "Installing dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_05.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "" "--ignore-platform-reqs --optimize-autoloader"
spawn ../../bin/composer_install.sh "" "--ignore-platform-reqs --optimize-autoloader" "" "" "" "composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'"
expect "Installing dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_06.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "lowest" "--ignore-platform-reqs --optimize-autoloader"
spawn ../../bin/composer_install.sh "lowest" "--ignore-platform-reqs --optimize-autoloader" "" "" "" "composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable --ignore-platform-reqs --optimize-autoloader'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable --ignore-platform-reqs --optimize-autoloader'"
expect "Updating dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_07.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "highest" "--ignore-platform-reqs --optimize-autoloader"
spawn ../../bin/composer_install.sh "highest" "--ignore-platform-reqs --optimize-autoloader" "" "" "" "composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'"
expect "Updating dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_08.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "locked" "--ignore-platform-reqs --optimize-autoloader"
spawn ../../bin/composer_install.sh "locked" "--ignore-platform-reqs --optimize-autoloader" "" "" "" "composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader'"
expect "Installing dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_09.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "" "" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "" "" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi --working-dir ../fixtures/with-lock-file'"
expect "Installing dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_10.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "lowest" "" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "lowest" "" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable --working-dir ../fixtures/with-lock-file'"
expect "Updating dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_11.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "highest" "" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "highest" "" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi --working-dir ../fixtures/with-lock-file'"
expect "Updating dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_12.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "locked" "" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "locked" "" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi --working-dir ../fixtures/with-lock-file'"
expect "Installing dependencies"
expect "Generating autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_13.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "Installing dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_14.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "lowest" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "lowest" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi --prefer-lowest --prefer-stable --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "Updating dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_15.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "highest" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "highest" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer update --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer update --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "Updating dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_16.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

set timeout 3
spawn ../../bin/composer_install.sh "locked" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file"
spawn ../../bin/composer_install.sh "locked" "--ignore-platform-reqs --optimize-autoloader" "../fixtures/with-lock-file" "" "" "../fixtures/with-lock-file/composer.lock"
match_max 100000

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi --ignore-platform-reqs --optimize-autoloader --working-dir ../fixtures/with-lock-file'"
expect "Installing dependencies"
expect "Generating optimized autoload files"
expect eof
Expand Down
4 changes: 2 additions & 2 deletions tests/expect/composer_install_17.exp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env -S expect -f

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

expect -exact "::debug::Using the following Composer command: 'composer install --no-interaction --no-progress --ansi'"
expect "::debug::Using the following Composer command: '*/composer install --no-interaction --no-progress --ansi'"
expect "Installing dependencies"
expect "Generating autoload files"
expect eof
Expand Down

0 comments on commit 9389fa5

Please sign in to comment.