Skip to content

Commit 7f9021e

Browse files
jrfnldesrosj
andauthored
Fix use of deprecated set-output command (#238)
* 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 <desrosj@users.noreply.github.com> Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
1 parent 4617231 commit 7f9021e

26 files changed

+420
-47
lines changed

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ runs:
8585
"${{ inputs.composer-options }}" \
8686
"${{ inputs.working-directory }}" \
8787
"${{ steps.php.outputs.path }}" \
88-
"${{ steps.composer.outputs.command }}" \
88+
"${{ steps.composer.outputs.composer_command }}" \
8989
"${{ steps.composer.outputs.lock }}"

bin/cache_key.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cache_key="$(make_key "${key[@]}")"
5757
echo "::debug::Cache primary key is '${cache_key}'"
5858
echo "::debug::Cache restore keys are '$(join_by ", " "${uniq_restore_key[@]}")'"
5959

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

6262
# Use an environment variable to capture the multiline restore key.
6363
# See: https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#multiline-strings

bin/composer_paths.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ echo "::debug::${composer_version}"
5353
echo "::debug::Composer cache directory found at '${cache_dir}'"
5454
echo "::debug::File composer.json found at '${composer_json}'"
5555
echo "::debug::File composer.lock path computed as '${composer_lock}'"
56-
echo "::set-output name=command::${composer_path}"
57-
echo "::set-output name=cache-dir::${cache_dir}"
58-
echo "::set-output name=json::${composer_json}"
59-
echo "::set-output name=lock::${composer_lock}"
56+
{
57+
echo "composer_command=${composer_path}"
58+
echo "cache-dir=${cache_dir}"
59+
echo "json=${composer_json}"
60+
echo "lock=${composer_lock}"
61+
} >> "${GITHUB_OUTPUT}"

bin/php_version.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ php_version=$($php_path -r 'echo phpversion();')
1616

1717
echo "::debug::PHP path is '${php_path}'"
1818
echo "::debug::PHP version is '${php_version}'"
19-
echo "::set-output name=path::${php_path}"
20-
echo "::set-output name=version::${php_version}"
19+
echo "path=${php_path}" >> "${GITHUB_OUTPUT}"
20+
echo "version=${php_version}" >> "${GITHUB_OUTPUT}"

bin/should_cache.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ if [ $should_cache -eq 0 ]; then
1515
fi
1616

1717
echo "::debug::We ${will_cache} the dependencies because ignore-cache is set to '${ignore_cache}'"
18-
echo "::set-output name=do-cache::${should_cache}"
18+
echo "do-cache=${should_cache}" >> "${GITHUB_OUTPUT}"

tests/expect/cache_key_01.exp

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#!/usr/bin/env -S expect -f
22

3+
# For testing environment variables written to GITHUB_ENV
34
set gitHubEnvFile cache_key_01.txt
45
set ::env(GITHUB_ENV) $gitHubEnvFile
56

7+
# For testing outputs variables written to GITHUB_OUTPUT
8+
set gitHubOutputFile cache_key_output_01.txt
9+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
611
set timeout 3
712
spawn ../../bin/cache_key.sh
813
match_max 100000
914

1015
expect -exact "::debug::Cache primary key is 'php-composer-locked'"
1116
expect -exact "::debug::Cache restore keys are 'php-composer-locked-'"
12-
expect -exact "::set-output name=key::php-composer-locked"
17+
1318
expect eof
1419

20+
# Confirm environment variables.
1521
set fp [open $gitHubEnvFile r]
1622
set fileData [read $fp]
1723
close $fp
@@ -27,5 +33,19 @@ if { $expectedValue != $fileData } {
2733
exit 1
2834
}
2935

36+
# Verify output variables have been set correctly.
37+
set fp [open $gitHubOutputFile r]
38+
set fileData [read $fp]
39+
close $fp
40+
41+
set expectedValue "key=php-composer-locked\n"
42+
43+
if { $expectedValue != $fileData } {
44+
puts "\nExpected output variable does not match. Received:\n"
45+
puts $fileData
46+
exit 1
47+
}
48+
3049
# Clean up
3150
file delete $gitHubEnvFile
51+
file delete $gitHubOutputFile

tests/expect/cache_key_02.exp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/usr/bin/env -S expect -f
22

3+
# For testing environment variables written to GITHUB_ENV
34
set gitHubEnvFile cache_key_02.txt
45
set ::env(GITHUB_ENV) $gitHubEnvFile
56

7+
# For testing outputs variables written to GITHUB_OUTPUT
8+
set gitHubOutputFile cache_key_output_02.txt
9+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
611
set timeout 3
712
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "" "" "long-files-hash"
813
match_max 100000
914

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

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

35+
# Verify output variables have been set correctly.
36+
set fp [open $gitHubOutputFile r]
37+
set fileData [read $fp]
38+
close $fp
39+
40+
set expectedValue "key=Linux-php-8.1.1-composer-locked-long-files-hash\n"
41+
42+
if { $expectedValue != $fileData } {
43+
puts "\nExpected output variable does not match. Received:\n"
44+
puts $fileData
45+
exit 1
46+
}
47+
3048
# Clean up
3149
file delete $gitHubEnvFile
50+
file delete $gitHubOutputFile

tests/expect/cache_key_03.exp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/usr/bin/env -S expect -f
22

3+
# For testing environment variables written to GITHUB_ENV
34
set gitHubEnvFile cache_key_03.txt
45
set ::env(GITHUB_ENV) $gitHubEnvFile
56

7+
# For testing outputs variables written to GITHUB_OUTPUT
8+
set gitHubOutputFile cache_key_output_03.txt
9+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
611
set timeout 3
712
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "locked" "" "long-files-hash"
813
match_max 100000
914

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

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

35+
# Verify output variables have been set correctly.
36+
set fp [open $gitHubOutputFile r]
37+
set fileData [read $fp]
38+
close $fp
39+
40+
set expectedValue "key=Linux-php-8.1.1-composer-locked-long-files-hash\n"
41+
42+
if { $expectedValue != $fileData } {
43+
puts "\nExpected output variable does not match. Received:\n"
44+
puts $fileData
45+
exit 1
46+
}
47+
3048
# Clean up
3149
file delete $gitHubEnvFile
50+
file delete $gitHubOutputFile

tests/expect/cache_key_04.exp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/usr/bin/env -S expect -f
22

3+
# For testing environment variables written to GITHUB_ENV
34
set gitHubEnvFile cache_key_04.txt
45
set ::env(GITHUB_ENV) $gitHubEnvFile
56

7+
# For testing outputs variables written to GITHUB_OUTPUT
8+
set gitHubOutputFile cache_key_output_04.txt
9+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
611
set timeout 3
712
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "lowest" "--ignore-platform-reqs --optimize-autoloader" "long-files-hash"
813
match_max 100000
914

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

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

35+
# Verify output variables have been set correctly.
36+
set fp [open $gitHubOutputFile r]
37+
set fileData [read $fp]
38+
close $fp
39+
40+
set expectedValue "key=Linux-php-8.1.1-composer---ignore-platform-reqs---optimize-autoloader-lowest-long-files-hash\n"
41+
42+
if { $expectedValue != $fileData } {
43+
puts "\nExpected output variable does not match. Received:\n"
44+
puts $fileData
45+
exit 1
46+
}
47+
3048
# Clean up
3149
file delete $gitHubEnvFile
50+
file delete $gitHubOutputFile

tests/expect/cache_key_05.exp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/usr/bin/env -S expect -f
22

3+
# For testing environment variables written to GITHUB_ENV
34
set gitHubEnvFile cache_key_05.txt
45
set ::env(GITHUB_ENV) $gitHubEnvFile
56

7+
# For testing outputs variables written to GITHUB_OUTPUT
8+
set gitHubOutputFile cache_key_output_05.txt
9+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
611
set timeout 3
712
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "locked" "" "long-files-hash" "my-custom-key"
813
match_max 100000
914

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

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

35+
# Verify output variables have been set correctly.
36+
set fp [open $gitHubOutputFile r]
37+
set fileData [read $fp]
38+
close $fp
39+
40+
set expectedValue "key=my-custom-key\n"
41+
42+
if { $expectedValue != $fileData } {
43+
puts "\nExpected output variable does not match. Received:\n"
44+
puts $fileData
45+
exit 1
46+
}
47+
3048
# Clean up
3149
file delete $gitHubEnvFile
50+
file delete $gitHubOutputFile

tests/expect/cache_key_06.exp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/usr/bin/env -S expect -f
22

3+
# For testing environment variables written to GITHUB_ENV
34
set gitHubEnvFile cache_key_06.txt
45
set ::env(GITHUB_ENV) $gitHubEnvFile
56

7+
# For testing outputs variables written to GITHUB_OUTPUT
8+
set gitHubOutputFile cache_key_output_06.txt
9+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
611
set timeout 3
712
spawn ../../bin/cache_key.sh "Linux" "8.1.1" "" "" "long-files-hash" "" "path/to/working/dir"
813
match_max 100000
914

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

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

35+
# Verify output variables have been set correctly.
36+
set fp [open $gitHubOutputFile r]
37+
set fileData [read $fp]
38+
close $fp
39+
40+
set expectedValue "key=Linux-php-8.1.1-composer-locked-path/to/working/dir-long-files-hash\n"
41+
42+
if { $expectedValue != $fileData } {
43+
puts "\nExpected output variable does not match. Received:\n"
44+
puts $fileData
45+
exit 1
46+
}
47+
3048
# Clean up
3149
file delete $gitHubEnvFile
50+
file delete $gitHubOutputFile

tests/expect/cache_key_07.exp

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#!/usr/bin/env -S expect -f
22

3+
# For testing environment variables written to GITHUB_ENV
34
set gitHubEnvFile cache_key_07.txt
45
set ::env(GITHUB_ENV) $gitHubEnvFile
56

7+
# For testing outputs variables written to GITHUB_OUTPUT
8+
set gitHubOutputFile cache_key_output_07.txt
9+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
611
set timeout 3
712
spawn ../../bin/cache_key.sh "Windows" "8.0.2" "foobar" "" "some-other-hash"
813
match_max 100000
914

1015
expect -exact "::debug::Cache primary key is 'Windows-php-8.0.2-composer-locked-some-other-hash'"
1116
expect -exact "::debug::Cache restore keys are 'Windows-php-8.0.2-composer-locked-'"
12-
expect -exact "::set-output name=key::Windows-php-8.0.2-composer-locked-some-other-hash"
1317
expect eof
1418

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

35+
# Verify output variables have been set correctly.
36+
set fp [open $gitHubOutputFile r]
37+
set fileData [read $fp]
38+
close $fp
39+
40+
set expectedValue "key=Windows-php-8.0.2-composer-locked-some-other-hash\n"
41+
42+
if { $expectedValue != $fileData } {
43+
puts "\nExpected output variable does not match. Received:\n"
44+
puts $fileData
45+
exit 1
46+
}
47+
3048
# Clean up
3149
file delete $gitHubEnvFile
50+
file delete $gitHubOutputFile

tests/expect/composer_paths_01.exp

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env -S expect -f
22

3+
set gitHubOutputFile composer_paths_01.txt
4+
set ::env(GITHUB_OUTPUT) $gitHubOutputFile
5+
36
set timeout 3
47
spawn ../../bin/composer_paths.sh
58
match_max 100000
@@ -9,9 +12,19 @@ expect "::debug::Composer path is '*'\r
912
::debug::Composer cache directory found at '*'\r
1013
::debug::File composer.json found at './composer.json'\r
1114
::debug::File composer.lock path computed as './composer.lock'\r
12-
::set-output name=command::*\r
13-
::set-output name=cache-dir::*\r
14-
::set-output name=json::./composer.json\r
15-
::set-output name=lock::./composer.lock\r
1615
"
1716
expect eof
17+
18+
# Verify output variables have been set correctly.
19+
set fp [open $gitHubOutputFile r]
20+
set fileData [read $fp]
21+
close $fp
22+
23+
if {[regexp {^composer_command=\S*\s*cache-dir=\S*\s*json=\./composer\.json\s*lock=./composer.lock\s*$} $fileData] == 0} {
24+
puts "\nExpected output variable does not match. Received:\n"
25+
puts $fileData
26+
exit 1
27+
}
28+
29+
# Clean up
30+
file delete $gitHubOutputFile

0 commit comments

Comments
 (0)