File tree Expand file tree Collapse file tree 5 files changed +84
-0
lines changed Expand file tree Collapse file tree 5 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 89
89
)"
90
90
[[ "${output}" == "${expected}" ]] || \
91
91
(echo >&2 "Ouptput from integration test does not match:" "${output}"; exit 1)
92
+ - name : Execute without recommended shell flags
93
+ uses : ./
94
+ with :
95
+ verbose : true
96
+ derivation-path : ./tests/integration_tests
97
+ shell-flags : ' '
98
+ run : |
99
+ rm -f integration_test3.out
100
+ # This fails. If the recommended flags are set, we should not reach the following
101
+ # statement.
102
+ ls does_not_exist
103
+ echo "HELLO" > integration_test3.out
104
+ - name : Confirm output for Execute without recommended shell flags
105
+ shell : bash
106
+ run : |
107
+ [[ -e integration_test3.out ]] || \
108
+ (echo >&2 "The integration_test3.out does not exist."; exit 1)
109
+ output="$(<./integration_test3.out)"
110
+ expected="$(cat <<-EOF
111
+ HELLO
112
+ EOF
113
+ )"
114
+ [[ "${output}" == "${expected}" ]] || \
115
+ (echo >&2 "Ouptput from integration test does not match:" "${output}"; exit 1)
116
+ - name : Execute with recommended shell flags
117
+ # This step should fail. We will confirm that it failed as expected in the next step.
118
+ continue-on-error : true
119
+ uses : ./
120
+ with :
121
+ verbose : true
122
+ derivation-path : ./tests/integration_tests
123
+ run : |
124
+ rm -f integration_test4.out
125
+ # This fails. If the recommended flags are set, we should not reach the following
126
+ # statement.
127
+ ls does_not_exist
128
+ echo "HELLO" > integration_test4.out
129
+ - name : Confirm output for Execute with recommended shell flags
130
+ shell : bash
131
+ run : |
132
+ if [[ -e integration_test4.out ]]; then
133
+ echo >&2 "The integration_test4.out exists."
134
+ exit 1
135
+ fi
136
+ echo "SUCCESS"
92
137
93
138
all_ci_tests :
94
139
runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ inputs:
22
22
description : |
23
23
The path to directory or the shell.nix or default.nix to use to set up the environment. This
24
24
is the directory where nix-shell is executed.
25
+ shell-flags :
26
+ type : string
27
+ default : set -o errexit -o nounset -o pipefail
28
+ description : These flags will be set before executing the script.
25
29
verbose :
26
30
type : boolean
27
31
description : Enable debug output written to stderr.
38
42
RNS_PURE : ${{ inputs.pure }}
39
43
RNS_DERIVATION_PATH : ${{ inputs.derivation-path }}
40
44
RNS_VERBOSE : ${{ inputs.verbose }}
45
+ # If the client specifies an empty string for the flags, we need to set the RNS_SHELL_FLAGS
46
+ # env variable to the special value false.
47
+ RNS_SHELL_FLAGS : ${{ inputs.shell-flags == '' && 'false' || inputs.shell-flags }}
41
48
run : ${GITHUB_ACTION_PATH}/tools/run_nix_shell.sh
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ run_nix_shell_test(name = "rns_opts_test")
14
14
15
15
run_nix_shell_test (name = "script_file_test" )
16
16
17
+ run_nix_shell_test (name = "shell_flags_test" )
18
+
17
19
run_nix_shell_test (name = "simple_script_test" )
18
20
19
21
run_nix_shell_test (name = "verbose_test" )
Original file line number Diff line number Diff line change
1
+ assert_msg=" default flags will exit with an error code on failure"
2
+ failed=false
3
+ " ${run_nix_shell_sh} " '
4
+ [[ "true" == "false" ]]
5
+ echo "This should not be seen."
6
+ ' > output.txt || failed=true
7
+ output=" $( < output.txt ) "
8
+ assert_equal " " " ${output} " " ${assert_msg} "
9
+ assert_equal " true" " ${failed} " " ${assert_msg} "
10
+
11
+ assert_msg=" with no shell flags, script will exit without an error code on failure"
12
+ success=false
13
+ RNS_SHELL_FLAGS=" false" " ${run_nix_shell_sh} " '
14
+ [[ "true" == "false" ]]
15
+ echo "This should be seen."
16
+ ' > output.txt && success=true
17
+ output=" $( < output.txt ) "
18
+ assert_equal " This should be seen." " ${output} " " ${assert_msg} "
19
+ assert_equal " true" " ${success} " " ${assert_msg} "
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ absolute_path() {
28
28
cwd=" ${RNS_CWD:- } "
29
29
script=" ${RNS_RUN:- } "
30
30
derivation_path=" ${RNS_DERIVATION_PATH:- } "
31
+ # The default flags listed below are equivalent to `set -euo pipefail`.
32
+ shell_flags=" ${RNS_SHELL_FLAGS:- set -o errexit -o nounset -o pipefail} "
31
33
32
34
pure=" ${RNS_PURE:- true} "
33
35
verbose=" ${RNS_VERBOSE:- false} "
@@ -82,9 +84,11 @@ RNS_OPTS: ${RNS_OPTS:-}
82
84
RNS_RUN: ${RNS_RUN:- }
83
85
RNS_DERIVATION_PATH: ${RNS_DERIVATION_PATH:- }
84
86
RNS_PURE: ${RNS_PURE:- }
87
+ RNS_SHELL_FLAGS: ${RNS_SHELL_FLAGS:- }
85
88
cwd: ${cwd:- }
86
89
nix_shell_opts: $( printf " %q " " ${nix_shell_opts[@]} " )
87
90
pure: ${pure:- }
91
+ shell_flags: ${shell_flags:- }
88
92
script: ${script:- }
89
93
derivation_path: ${derivation_path:- }
90
94
===
@@ -136,6 +140,12 @@ if [[ -n "${RNS_OPTS:-}" ]]; then
136
140
fi
137
141
fi
138
142
143
+ # If the client does not want any shell flags, we use the special value "false"
144
+ # to indicate that no flags should be applied.
145
+ if [[ " ${shell_flags:- } " == " false" ]]; then
146
+ shell_flags=" "
147
+ fi
148
+
139
149
if [[ -z " ${script:- } " ]]; then
140
150
fail " A script or a path to a file must be provided."
141
151
fi
@@ -148,6 +158,7 @@ if [[ -n "${cwd:-}" ]]; then
148
158
fi
149
159
150
160
script=" $( cat << -EOF
161
+ ${shell_flags:- }
151
162
${cd_cmd:- }
152
163
${script}
153
164
EOF
You can’t perform that action at this time.
0 commit comments