-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental: reusable workflow to enable debug mode
- Loading branch information
Showing
2 changed files
with
103 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# This workflow is called from integration.yml as a [reusable] worflow.; this | ||
# technique makes it possible to set the `ACTIONS_STEP_DEBUG` secret for just | ||
# this test. | ||
# | ||
# [reusable]: https://docs.github.com/en/actions/using-workflows/reusing-workflows | ||
|
||
name: Integration (debug parameter test) | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
ACTIONS_STEP_DEBUG: | ||
description: 'Set to "true" to enable debug logging' | ||
required: true | ||
|
||
jobs: | ||
test-debug: | ||
name: "Integration test: debug option (runner debug: ${{ (runner.debug == '1' && 'ON') || 'OFF' }})" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: ~/.npm | ||
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}} | ||
restore-keys: ${{runner.os}}-npm- | ||
- run: npm ci | ||
- id: debug-default | ||
name: Default debug not set | ||
uses: ./ | ||
with: | ||
script: | | ||
const log = github.log | ||
return { | ||
runnerDebugMode: core.isDebug(), | ||
debug: log.debug === console.debug, | ||
info: log.info === console.info | ||
} | ||
- id: debug-true | ||
name: Debug set to true | ||
uses: ./ | ||
with: | ||
debug: true | ||
script: | | ||
const log = github.log | ||
return { | ||
runnerDebugMode: core.isDebug(), | ||
debug: log.debug === console.debug, | ||
info: log.info === console.info | ||
} | ||
- id: debug-false | ||
name: Debug set to false | ||
uses: ./ | ||
with: | ||
debug: false | ||
script: | | ||
const log = github.log | ||
return { | ||
runnerDebugMode: core.isDebug(), | ||
debug: log.debug === console.debug, | ||
info: log.info === console.info | ||
} | ||
- id: evaluate-tests | ||
name: Evaluate test outputs | ||
env: | ||
RDMODE: ${{ (runner.debug == '1' && 'true') || 'false' }} | ||
run: | | ||
# tests table, pipe separated: label | output | expected | ||
# leading and trailing spaces on any field are trimmed | ||
tests=$(cat << 'TESTS' | ||
Validating debug default |\ | ||
${{ steps.debug-default.outputs.result }} |\ | ||
{"runnerDebugMode":${{ env.RDMODE }},"debug":${{ env.RDMODE }},"info":${{ env.RDMODE }}} | ||
Validating debug set to true |\ | ||
${{ steps.debug-true.outputs.result }} |\ | ||
{"runnerDebugMode":${{ env.RDMODE }},"debug":true,"info":true} | ||
Validating debug set to false |\ | ||
${{ steps.debug-false.outputs.result }} |\ | ||
{"runnerDebugMode":${{ env.RDMODE }},"debug":false,"info":false} | ||
TESTS | ||
) | ||
strim() { shopt -s extglob; lt="${1##+( )}"; echo "${lt%%+( )}"; } | ||
while IFS='|' read label output expected; do | ||
label="$(strim "$label")"; output="$(strim "$output")"; expected="$(strim "$expected")" | ||
echo -n "- $label:" | ||
if [[ "$output" != "$expected" ]]; then | ||
echo $'\n::error::\u274C' "Expected '$expected', got '$output'" | ||
exit 1 | ||
fi | ||
echo $' \u2705' | ||
done <<< "$tests" | ||
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters