Skip to content

Commit

Permalink
Merge pull request #363 from mjpieters/auto_debug
Browse files Browse the repository at this point in the history
Default debug to current runner debug state
  • Loading branch information
joshmgross committed Apr 5, 2023
2 parents 57c10d4 + ea954ff commit d7906e4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
59 changes: 39 additions & 20 deletions .github/workflows/integration.yml
Expand Up @@ -187,7 +187,11 @@ jobs:
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
test-debug:
name: 'Integration test: debug option'
strategy:
matrix:
environment: ['', 'debug-integration-test']
environment: ${{ matrix.environment }}
name: "Integration test: debug option (runner.debug mode ${{ matrix.environment && 'enabled' || 'disabled' }})"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -204,6 +208,7 @@ jobs:
script: |
const log = github.log
return {
runnerDebugMode: core.isDebug(),
debug: log.debug === console.debug,
info: log.info === console.info
}
Expand All @@ -215,6 +220,7 @@ jobs:
script: |
const log = github.log
return {
runnerDebugMode: core.isDebug(),
debug: log.debug === console.debug,
info: log.info === console.info
}
Expand All @@ -226,26 +232,39 @@ jobs:
script: |
const log = github.log
return {
runnerDebugMode: core.isDebug(),
debug: log.debug === console.debug,
info: log.info === console.info
}
- run: |
echo "- Validating debug default"
expected='{debug:false,info:false}'
if [[ "${{steps.debug-default.outputs.result}}" != "$expected" ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.debug-default.outputs.result}}"
exit 1
fi
echo "- Validating debug set to true"
expected='{debug:true,info:true}'
if [[ "${{steps.debug-true.outputs.result}}" != "$expected" ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.debug-true.outputs.result}}"
exit 1
fi
echo "- Validating debug set to false"
expected='{debug:false,info:false}'
if [[ "${{steps.debug-false.outputs.result}}" != "$expected" ]]; then
echo $'::error::\u274C' "Expected '$expected', got ${{steps.debug-false.outputs.result}}"
exit 1
fi
- id: evaluate-tests
name: Evaluate test outputs
env:
RDMODE: ${{ runner.debug == '1' }}
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
4 changes: 2 additions & 2 deletions action.yml
Expand Up @@ -13,8 +13,8 @@ inputs:
default: ${{ github.token }}
required: false
debug:
description: Whether to tell the GitHub client to log details of its requests
default: false
description: Whether to tell the GitHub client to log details of its requests. true or false. Default is to run in debug mode when the GitHub Actions step debug logging is turned on.
default: ${{ runner.debug == '1' }}
user-agent:
description: An optional user-agent string
default: actions/github-script
Expand Down

0 comments on commit d7906e4

Please sign in to comment.