Skip to content

Commit

Permalink
Fix use of deprecated set-output command (#238)
Browse files Browse the repository at this point in the history
* First pass at removing `set-output`.

`set-output` has been deprecated. See https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/.

* Revert unintentional lock file change.

* Change `command` to `composer_command`.

Bash gets confused with the variable being named `command`.

* Undo `composer.lock` file changes within test fixtures.

* Add some inline documentation to tests.

* Change missed `command` instance to `composer_command`.

* `composer_paths.sh`: fix issue flagged by shellcheck

* Tests: fix inline comments

... and make them slightly more descriptive.

* Tests/composer_paths_09.exp: fix expectation

Follow up to 237 which updated the `composer.phar` file, but missed the update needed to the test expectations.

* Tests: fix test which need a pattern match

Note: there may well be a way to not have the regex inline, which would make the code more readable, but I'm not familiar enough with Tcl and to be honest, I'm already darn glad that I managed to get it working ;-)

Refs:
* https://www.tcl.tk/man/tcl8.5/TclCmd/regexp.html
* https://www.tcl.tk/man/tcl8.5/TclCmd/re_syntax.html

Co-authored-by: Jon Desrosiers <[email protected]>
Co-authored-by: jrfnl <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2022
1 parent 4617231 commit 7f9021e
Show file tree
Hide file tree
Showing 26 changed files with 420 additions and 47 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ runs:
"${{ inputs.composer-options }}" \
"${{ inputs.working-directory }}" \
"${{ steps.php.outputs.path }}" \
"${{ steps.composer.outputs.command }}" \
"${{ steps.composer.outputs.composer_command }}" \
"${{ steps.composer.outputs.lock }}"
2 changes: 1 addition & 1 deletion bin/cache_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cache_key="$(make_key "${key[@]}")"
echo "::debug::Cache primary key is '${cache_key}'"
echo "::debug::Cache restore keys are '$(join_by ", " "${uniq_restore_key[@]}")'"

echo "::set-output name=key::${cache_key}"
echo "key=${cache_key}" >> "${GITHUB_OUTPUT}"

# Use an environment variable to capture the multiline restore key.
# See: https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#multiline-strings
Expand Down
10 changes: 6 additions & 4 deletions bin/composer_paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ echo "::debug::${composer_version}"
echo "::debug::Composer cache directory found at '${cache_dir}'"
echo "::debug::File composer.json found at '${composer_json}'"
echo "::debug::File composer.lock path computed as '${composer_lock}'"
echo "::set-output name=command::${composer_path}"
echo "::set-output name=cache-dir::${cache_dir}"
echo "::set-output name=json::${composer_json}"
echo "::set-output name=lock::${composer_lock}"
{
echo "composer_command=${composer_path}"
echo "cache-dir=${cache_dir}"
echo "json=${composer_json}"
echo "lock=${composer_lock}"
} >> "${GITHUB_OUTPUT}"
4 changes: 2 additions & 2 deletions bin/php_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ php_version=$($php_path -r 'echo phpversion();')

echo "::debug::PHP path is '${php_path}'"
echo "::debug::PHP version is '${php_version}'"
echo "::set-output name=path::${php_path}"
echo "::set-output name=version::${php_version}"
echo "path=${php_path}" >> "${GITHUB_OUTPUT}"
echo "version=${php_version}" >> "${GITHUB_OUTPUT}"
2 changes: 1 addition & 1 deletion bin/should_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ if [ $should_cache -eq 0 ]; then
fi

echo "::debug::We ${will_cache} the dependencies because ignore-cache is set to '${ignore_cache}'"
echo "::set-output name=do-cache::${should_cache}"
echo "do-cache=${should_cache}" >> "${GITHUB_OUTPUT}"
22 changes: 21 additions & 1 deletion tests/expect/cache_key_01.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#!/usr/bin/env -S expect -f

# For testing environment variables written to GITHUB_ENV
set gitHubEnvFile cache_key_01.txt
set ::env(GITHUB_ENV) $gitHubEnvFile

# For testing outputs variables written to GITHUB_OUTPUT
set gitHubOutputFile cache_key_output_01.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/cache_key.sh
match_max 100000

expect -exact "::debug::Cache primary key is 'php-composer-locked'"
expect -exact "::debug::Cache restore keys are 'php-composer-locked-'"
expect -exact "::set-output name=key::php-composer-locked"

expect eof

# Confirm environment variables.
set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp
Expand All @@ -27,5 +33,19 @@ if { $expectedValue != $fileData } {
exit 1
}

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "key=php-composer-locked\n"

if { $expectedValue != $fileData } {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubEnvFile
file delete $gitHubOutputFile
21 changes: 20 additions & 1 deletion tests/expect/cache_key_02.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/usr/bin/env -S expect -f

# For testing environment variables written to GITHUB_ENV
set gitHubEnvFile cache_key_02.txt
set ::env(GITHUB_ENV) $gitHubEnvFile

# For testing outputs variables written to GITHUB_OUTPUT
set gitHubOutputFile cache_key_output_02.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "" "" "long-files-hash"
match_max 100000

expect -exact "::debug::Cache primary key is 'Linux-php-8.1.1-composer-locked-long-files-hash'"
expect -exact "::debug::Cache restore keys are 'Linux-php-8.1.1-composer-locked-'"
expect -exact "::set-output name=key::Linux-php-8.1.1-composer-locked-long-files-hash"
expect eof

# Confirm environment variables.
set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp
Expand All @@ -27,5 +32,19 @@ if { $expectedValue != $fileData } {
exit 1
}

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "key=Linux-php-8.1.1-composer-locked-long-files-hash\n"

if { $expectedValue != $fileData } {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubEnvFile
file delete $gitHubOutputFile
21 changes: 20 additions & 1 deletion tests/expect/cache_key_03.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/usr/bin/env -S expect -f

# For testing environment variables written to GITHUB_ENV
set gitHubEnvFile cache_key_03.txt
set ::env(GITHUB_ENV) $gitHubEnvFile

# For testing outputs variables written to GITHUB_OUTPUT
set gitHubOutputFile cache_key_output_03.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "locked" "" "long-files-hash"
match_max 100000

expect -exact "::debug::Cache primary key is 'Linux-php-8.1.1-composer-locked-long-files-hash'"
expect -exact "::debug::Cache restore keys are 'Linux-php-8.1.1-composer-locked-'"
expect -exact "::set-output name=key::Linux-php-8.1.1-composer-locked-long-files-hash"
expect eof

# Confirm environment variables.
set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp
Expand All @@ -27,5 +32,19 @@ if { $expectedValue != $fileData } {
exit 1
}

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "key=Linux-php-8.1.1-composer-locked-long-files-hash\n"

if { $expectedValue != $fileData } {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubEnvFile
file delete $gitHubOutputFile
21 changes: 20 additions & 1 deletion tests/expect/cache_key_04.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/usr/bin/env -S expect -f

# For testing environment variables written to GITHUB_ENV
set gitHubEnvFile cache_key_04.txt
set ::env(GITHUB_ENV) $gitHubEnvFile

# For testing outputs variables written to GITHUB_OUTPUT
set gitHubOutputFile cache_key_output_04.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "lowest" "--ignore-platform-reqs --optimize-autoloader" "long-files-hash"
match_max 100000

expect -exact "::debug::Cache primary key is 'Linux-php-8.1.1-composer---ignore-platform-reqs---optimize-autoloader-lowest-long-files-hash'"
expect -exact "::debug::Cache restore keys are 'Linux-php-8.1.1-composer---ignore-platform-reqs---optimize-autoloader-lowest-'"
expect -exact "::set-output name=key::Linux-php-8.1.1-composer---ignore-platform-reqs---optimize-autoloader-lowest-long-files-hash"
expect eof

# Confirm environment variables.
set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp
Expand All @@ -27,5 +32,19 @@ if { $expectedValue != $fileData } {
exit 1
}

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "key=Linux-php-8.1.1-composer---ignore-platform-reqs---optimize-autoloader-lowest-long-files-hash\n"

if { $expectedValue != $fileData } {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubEnvFile
file delete $gitHubOutputFile
21 changes: 20 additions & 1 deletion tests/expect/cache_key_05.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/usr/bin/env -S expect -f

# For testing environment variables written to GITHUB_ENV
set gitHubEnvFile cache_key_05.txt
set ::env(GITHUB_ENV) $gitHubEnvFile

# For testing outputs variables written to GITHUB_OUTPUT
set gitHubOutputFile cache_key_output_05.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "locked" "" "long-files-hash" "my-custom-key"
match_max 100000

expect -exact "::debug::Cache primary key is 'my-custom-key'"
expect -exact "::debug::Cache restore keys are ''"
expect -exact "::set-output name=key::my-custom-key"
expect eof

# Confirm environment variables.
set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp
Expand All @@ -27,5 +32,19 @@ if { $expectedValue != $fileData } {
exit 1
}

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "key=my-custom-key\n"

if { $expectedValue != $fileData } {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubEnvFile
file delete $gitHubOutputFile
21 changes: 20 additions & 1 deletion tests/expect/cache_key_06.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/usr/bin/env -S expect -f

# For testing environment variables written to GITHUB_ENV
set gitHubEnvFile cache_key_06.txt
set ::env(GITHUB_ENV) $gitHubEnvFile

# For testing outputs variables written to GITHUB_OUTPUT
set gitHubOutputFile cache_key_output_06.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "" "" "long-files-hash" "" "path/to/working/dir"
match_max 100000

expect -exact "::debug::Cache primary key is 'Linux-php-8.1.1-composer-locked-path/to/working/dir-long-files-hash'"
expect -exact "::debug::Cache restore keys are 'Linux-php-8.1.1-composer-locked-path/to/working/dir-'"
expect -exact "::set-output name=key::Linux-php-8.1.1-composer-locked-path/to/working/dir-long-files-hash"
expect eof

# Confirm environment variables.
set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp
Expand All @@ -27,5 +32,19 @@ if { $expectedValue != $fileData } {
exit 1
}

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "key=Linux-php-8.1.1-composer-locked-path/to/working/dir-long-files-hash\n"

if { $expectedValue != $fileData } {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubEnvFile
file delete $gitHubOutputFile
21 changes: 20 additions & 1 deletion tests/expect/cache_key_07.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#!/usr/bin/env -S expect -f

# For testing environment variables written to GITHUB_ENV
set gitHubEnvFile cache_key_07.txt
set ::env(GITHUB_ENV) $gitHubEnvFile

# For testing outputs variables written to GITHUB_OUTPUT
set gitHubOutputFile cache_key_output_07.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

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

expect -exact "::debug::Cache primary key is 'Windows-php-8.0.2-composer-locked-some-other-hash'"
expect -exact "::debug::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

# Confirm environment variables.
set fp [open $gitHubEnvFile r]
set fileData [read $fp]
close $fp
Expand All @@ -27,5 +32,19 @@ if { $expectedValue != $fileData } {
exit 1
}

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "key=Windows-php-8.0.2-composer-locked-some-other-hash\n"

if { $expectedValue != $fileData } {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubEnvFile
file delete $gitHubOutputFile
21 changes: 17 additions & 4 deletions tests/expect/composer_paths_01.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env -S expect -f

set gitHubOutputFile composer_paths_01.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/composer_paths.sh
match_max 100000
Expand All @@ -9,9 +12,19 @@ expect "::debug::Composer path is '*'\r
::debug::Composer cache directory found at '*'\r
::debug::File composer.json found at './composer.json'\r
::debug::File composer.lock path computed as './composer.lock'\r
::set-output name=command::*\r
::set-output name=cache-dir::*\r
::set-output name=json::./composer.json\r
::set-output name=lock::./composer.lock\r
"
expect eof

# Verify output variables have been set correctly.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

if {[regexp {^composer_command=\S*\s*cache-dir=\S*\s*json=\./composer\.json\s*lock=./composer.lock\s*$} $fileData] == 0} {
puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubOutputFile
Loading

0 comments on commit 7f9021e

Please sign in to comment.