Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of deprecated set-output command #238

Merged
merged 10 commits into from Nov 3, 2022
2 changes: 1 addition & 1 deletion action.yml
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
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
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
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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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