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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at removing set-output #235

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions bin/composer_paths.sh
Expand Up @@ -53,7 +53,7 @@ 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}" >> "${GITHUB_OUTPUT}"
echo "cache-dir=${cache_dir}" >> "${GITHUB_OUTPUT}"
echo "json=${composer_json}" >> "${GITHUB_OUTPUT}"
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
}

# Confirm environment variables.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Confirm environment variables.
# Confirm output variables.

(here and in the other test files)

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
}

# Confirm environment variables.
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
}

# Confirm environment variables.
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
}

# Confirm environment variables.
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
}

# Confirm environment variables.
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
}

# Confirm environment variables.
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
}

# Confirm environment variables.
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
27 changes: 23 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,25 @@ 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

# Confirm environment variables.
set fp [open $gitHubOutputFile r]
set fileData [read $fp]
close $fp

set expectedValue "composer_command=*\r
cache-dir=*\r
json=./composer.json\r
lock=./composer.lock\n
"

if { $expectedValue != $fileData } {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails as it needs to do a regex compare, not a direct comparison.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bash scripting is admittedly poor. Do you have an example I could use as a guide?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bash scripting skills are even worse, then again, my Google skills are reasonable ;-)

puts "\nExpected output variable does not match. Received:\n"
puts $fileData
exit 1
}

# Clean up
file delete $gitHubOutputFile