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 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions bin/composer_paths.sh
Original file line number Diff line number Diff line change
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 "command=${composer_path}" >> "${GITHUB_OUTPUT}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shellcheck doesn't like this output being called command...

In bin/composer_paths.sh line 56:
echo "command=${composer_path}" >> "${GITHUB_OUTPUT}"
^-- SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects.

For more information:
  https://www.shellcheck.net/wiki/SC2129 -- Consider using { cmd1; cmd2; } >>...

Copy link
Contributor Author

@desrosj desrosj Oct 14, 2022

Choose a reason for hiding this comment

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

I've changed the variable name to composer_command.

It doesn't seem like this will have any backwards compatibility concerns since it's only used within the repo. But not sure if I'm missing something.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd need to check, but this output may also be available to steps in external workflows being run after the step using this action runner.
If that's the case and while it would be rare for a workflow to use the command output, it would still need a changelog entry. Though as I said, this would need to be checked and confirmed first.

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
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}"
17 changes: 16 additions & 1 deletion tests/expect/cache_key_01.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

set gitHubEnvFile cache_key_01.txt
set ::env(GITHUB_ENV) $gitHubEnvFile
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

set fp [open $gitHubEnvFile r]
Expand All @@ -27,5 +29,18 @@ if { $expectedValue != $fileData } {
exit 1
}

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
16 changes: 15 additions & 1 deletion tests/expect/cache_key_02.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

set gitHubEnvFile cache_key_02.txt
set ::env(GITHUB_ENV) $gitHubEnvFile
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

set fp [open $gitHubEnvFile r]
Expand All @@ -27,5 +28,18 @@ if { $expectedValue != $fileData } {
exit 1
}

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
16 changes: 15 additions & 1 deletion tests/expect/cache_key_03.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

set gitHubEnvFile cache_key_03.txt
set ::env(GITHUB_ENV) $gitHubEnvFile
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

set fp [open $gitHubEnvFile r]
Expand All @@ -27,5 +28,18 @@ if { $expectedValue != $fileData } {
exit 1
}

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
16 changes: 15 additions & 1 deletion tests/expect/cache_key_04.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

set gitHubEnvFile cache_key_04.txt
set ::env(GITHUB_ENV) $gitHubEnvFile
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

set fp [open $gitHubEnvFile r]
Expand All @@ -27,5 +28,18 @@ if { $expectedValue != $fileData } {
exit 1
}

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
16 changes: 15 additions & 1 deletion tests/expect/cache_key_05.exp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env -S expect -f

set gitHubEnvFile cache_key_05.txt
set gitHubOutputFile cache_key_output_05.txt
set ::env(GITHUB_ENV) $gitHubEnvFile
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

set fp [open $gitHubEnvFile r]
Expand All @@ -27,5 +28,18 @@ if { $expectedValue != $fileData } {
exit 1
}

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
16 changes: 15 additions & 1 deletion tests/expect/cache_key_06.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

set gitHubEnvFile cache_key_06.txt
set ::env(GITHUB_ENV) $gitHubEnvFile
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

set fp [open $gitHubEnvFile r]
Expand All @@ -27,5 +28,18 @@ if { $expectedValue != $fileData } {
exit 1
}

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
16 changes: 15 additions & 1 deletion tests/expect/cache_key_07.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

set gitHubEnvFile cache_key_07.txt
set ::env(GITHUB_ENV) $gitHubEnvFile
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

set fp [open $gitHubEnvFile r]
Expand All @@ -27,5 +28,18 @@ if { $expectedValue != $fileData } {
exit 1
}

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
2 changes: 1 addition & 1 deletion tests/expect/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 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,24 @@ 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

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

set expectedValue "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
26 changes: 22 additions & 4 deletions tests/expect/composer_paths_05.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_05.txt
set ::env(GITHUB_OUTPUT) $gitHubOutputFile

set timeout 3
spawn ../../bin/composer_paths.sh "" "../fixtures/no-lock-file"
match_max 100000
Expand All @@ -10,9 +13,24 @@ expect "::debug::Unable to find composer.lock at '../fixtures/no-lock-file/compo
::debug::Composer cache directory found at '*'\r
::debug::File composer.json found at '../fixtures/no-lock-file/composer.json'\r
::debug::File composer.lock path computed as ''\r
::set-output name=command::*\r
::set-output name=cache-dir::*\r
::set-output name=json::../fixtures/no-lock-file/composer.json\r
::set-output name=lock::\r
"
expect eof

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

set expectedValue "command=*\r
cache-dir=*\r
json=../fixtures/no-lock-file/composer.json\r
lock=\r
"

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.

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

# Clean up
file delete $gitHubOutputFile
Loading