Skip to content

Commit

Permalink
Enable trace based on debug flag (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Jan 27, 2023
1 parent 312448d commit 99580de
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- v1
pull_request:

env:
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG }}

jobs:
test1:
name: Test Update Needed
Expand Down Expand Up @@ -35,7 +38,7 @@ jobs:
continue-on-error: true
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Test Action
id: test
uses: ./
Expand Down Expand Up @@ -100,7 +103,7 @@ jobs:
continue-on-error: true
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Test Action
id: test
uses: ./
Expand Down
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,54 @@ build:
> **Note**
>
> If any of the platforms is not present in either the base-image or the image, the action will exit with an error.

## Debugging

To debug the action, you can set the `DEBUG` environment variable to `true` in the workflow file. The variable can be set at any level.

```yaml
name: Check docker image
on:
schedule:
- cron: '0 4 * * *'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Check if update available
id: check
uses: lucacome/docker-image-update-checker@v1
with:
base-image: nginx:1.21.0
image: user/app:latest
env:
DEBUG: true
```

To make it more convenient, you can use `${{ secrets.ACTIONS_STEP_DEBUG }}` to enable debugging only when needed.

```yaml
name: Check docker image
on:
schedule:
- cron: '0 4 * * *'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Check if update available
id: check
uses: lucacome/docker-image-update-checker@v1
with:
base-image: nginx:1.21.0
image: user/app:latest
env:
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG }}
```

This works even when re-running the action with the `Re-run job` button and the `Enable debug logging` checkbox checked.
To read more about debugging actions, see [Debugging actions](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging).
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runs:
steps:
- id: run-script
run: |
result=$(base=${{ inputs.base-image }} image=${{ inputs.image }} platforms=${{ inputs.platforms }} ${{ github.action_path }}/docker.sh)
result=$(TRACE=${{ env.DEBUG == 'true' && '1' || '0' }} base=${{ inputs.base-image }} image=${{ inputs.image }} platforms=${{ inputs.platforms }} ${{ github.action_path }}/docker.sh)
echo "result=${result}" >>$GITHUB_OUTPUT
shell: bash

Expand Down

0 comments on commit 99580de

Please sign in to comment.