Skip to content

Commit 0049e3f

Browse files
Use deprecated set-output syntax if GITHUB_OUTPUT environment is not available (#255)
* Fallback to set-output if GITHUB_OUTPUT not available * Add Tests to cover old syntax
1 parent f6f7a9c commit 0049e3f

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

entrypoint.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ _main() {
1111

1212
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
1313

14-
echo "changes_detected=true" >> $GITHUB_OUTPUT;
14+
# Check if $GITHUB_OUTPUT is available
15+
# (Feature detection will be removed in late December 2022)
16+
if [ -z ${GITHUB_OUTPUT+x} ]; then
17+
echo "::set-output name=changes_detected::true";
18+
else
19+
echo "changes_detected=true" >> $GITHUB_OUTPUT;
20+
fi
1521

1622
_switch_to_branch
1723

@@ -24,7 +30,13 @@ _main() {
2430
_push_to_github
2531
else
2632

27-
echo "changes_detected=false" >> $GITHUB_OUTPUT;
33+
# Check if $GITHUB_OUTPUT is available
34+
# (Feature detection will be removed in late December 2022)
35+
if [ -z ${GITHUB_OUTPUT+x} ]; then
36+
echo "::set-output name=changes_detected::false";
37+
else
38+
echo "changes_detected=false" >> $GITHUB_OUTPUT;
39+
fi
2840

2941
echo "Working tree clean. Nothing to commit.";
3042
fi
@@ -101,7 +113,14 @@ _local_commit() {
101113
--author="$INPUT_COMMIT_AUTHOR" \
102114
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};
103115

104-
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT;
116+
117+
# Check if $GITHUB_OUTPUT is available
118+
# (Feature detection will be removed in late December 2022)
119+
if [ -z ${GITHUB_OUTPUT+x} ]; then
120+
echo "::set-output name=commit_hash::$(git rev-parse HEAD)";
121+
else
122+
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT;
123+
fi
105124
}
106125

107126
_tag_commit() {

tests/git-auto-commit.bats

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ teardown() {
5757
rm -rf "${FAKE_LOCAL_REPOSITORY}"
5858
rm -rf "${FAKE_REMOTE}"
5959
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
60-
rm "${GITHUB_OUTPUT}"
60+
61+
if [ -z ${GITHUB_OUTPUT+x} ]; then
62+
echo "GITHUB_OUTPUT is not set"
63+
else
64+
rm "${GITHUB_OUTPUT}"
65+
fi
6166
}
6267

6368
# Create a fake remote repository which tests can push against
@@ -997,3 +1002,42 @@ cat_github_output() {
9971002
refute_line --partial "new-file-2.txt"
9981003
refute_line --partial "new-file-3.txt"
9991004
}
1005+
1006+
1007+
@test "It uses old set-output syntax if GITHUB_OUTPUT environment is not available when changes are committed" {
1008+
unset GITHUB_OUTPUT
1009+
1010+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
1011+
1012+
run git_auto_commit
1013+
1014+
assert_success
1015+
1016+
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
1017+
assert_line "INPUT_BRANCH value: ${FAKE_DEFAULT_BRANCH}"
1018+
assert_line "INPUT_FILE_PATTERN: ."
1019+
assert_line "INPUT_COMMIT_OPTIONS: "
1020+
assert_line "::debug::Apply commit options "
1021+
assert_line "INPUT_TAGGING_MESSAGE: "
1022+
assert_line "No tagging message supplied. No tag will be added."
1023+
assert_line "INPUT_PUSH_OPTIONS: "
1024+
assert_line "::debug::Apply push options "
1025+
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
1026+
1027+
assert_line "::set-output name=changes_detected::true"
1028+
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
1029+
}
1030+
1031+
@test "It uses old set-output syntax if GITHUB_OUTPUT environment is not available when no changes have been detected" {
1032+
unset GITHUB_OUTPUT
1033+
1034+
run git_auto_commit
1035+
1036+
assert_success
1037+
1038+
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
1039+
assert_line "Working tree clean. Nothing to commit."
1040+
1041+
assert_line "::set-output name=changes_detected::false"
1042+
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
1043+
}

0 commit comments

Comments
 (0)