Add summary for executable verbs (#192)

This commit is contained in:
Matias Pan 2025-09-26 16:29:33 -03:00 committed by GitHub
parent 4f6f256cec
commit 27bae3a184
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 112 additions and 12 deletions

View file

@ -239,6 +239,49 @@ jobs:
exit 1
fi
summary-path:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: "Test summary-path"
id: test-summary-path
uses: ./
with:
version: latest
verb: core
args: version
summary-path: "/tmp/custom-summary.md"
- name: "Check custom summary file"
run: |
if [[ -f "/tmp/custom-summary.md" ]] && [[ -s "/tmp/custom-summary.md" ]]; then
echo "Custom summary file exists and has content"
echo "Content preview:"
head -10 "/tmp/custom-summary.md"
else
echo "Custom summary file missing or empty"
exit 1
fi
enable-github-summary:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: "Test enable-github-summary=true (default)"
id: test-github-summary-enabled
uses: ./
with:
version: latest
verb: core
args: version
- name: "Check github summary enabled"
run: |
if [[ -n "${GITHUB_STEP_SUMMARY}" ]]; then
echo "GitHub step summary was written (default behavior)"
else
echo "GitHub step summary not written when it should have been"
exit 1
fi
nocall:
runs-on: "ubuntu-latest"
steps:

View file

@ -43,18 +43,20 @@ By setting the version to `latest`, this action will install the latest version
### All `with:` input parameter options
| Key | Description | Required | Default |
| --------------- | ----------------------------------------------------------------- | -------- | ------------------ |
| `version` | Dagger Version. Use semver vX.Y.Z or 'latest' | true | 'latest' |
| `commit` | Dagger Dev Commit (overrides `version`) | false | '' |
| `dagger-flags` | Dagger CLI Flags | false | '--progress plain' |
| `verb` | CLI verb (call, run, download, up, functions, shell, query) | false | 'call' |
| `workdir` | The working directory in which to run the Dagger CLI | false | '.' |
| `cloud-token` | Dagger Cloud Token | false | '' |
| `module` | Dagger module to call. Local or Git | false | '' |
| `args` | Arguments to pass to CLI | false | '' |
| `call` | Arguments to pass to CLI (Alias for args with verb:call) | false | '' |
| `shell` | Arguments to pass to CLI (Alias for args with verb:shell) | false | '' |
| Key | Description | Required | Default |
| ------------------------------- | ----------------------------------------------------------------- | -------- | ------------------ |
| `version` | Dagger Version. Use semver vX.Y.Z or 'latest' | true | 'latest' |
| `commit` | Dagger Dev Commit (overrides `version`) | false | '' |
| `dagger-flags` | Dagger CLI Flags | false | '--progress plain' |
| `verb` | CLI verb (call, run, download, up, functions, shell, query) | false | 'call' |
| `workdir` | The working directory in which to run the Dagger CLI | false | '.' |
| `cloud-token` | Dagger Cloud Token | false | '' |
| `module` | Dagger module to call. Local or Git | false | '' |
| `args` | Arguments to pass to CLI | false | '' |
| `call` | Arguments to pass to CLI (Alias for args with verb:call) | false | '' |
| `shell` | Arguments to pass to CLI (Alias for args with verb:shell) | false | '' |
| `summary-path` | File path to write the job summary to | false | '' |
| `enable-github-summary` | Whether to automatically write a GitHub Actions job summary | false | 'false' |
### All output variables

View file

@ -45,6 +45,14 @@ inputs:
description: "Function and arguments for dagger shell"
required: false
default: ""
summary-path:
description: "File path to write the job summary"
required: false
default: ""
enable-github-summary:
description: "Whether to write summary to GITHUB_STEP_SUMMARY"
required: false
default: "false"
outputs:
output:
description: "Job output"
@ -115,6 +123,9 @@ runs:
shell: bash
env:
INPUT_MODULE: ${{ inputs.module }}
VERB: ${{ steps.assemble.outputs.verb }}
CMD: ${{ inputs.args || inputs.call || steps.assemble.outputs.script }}
SCRIPT: ${{ steps.assemble.outputs.script }}
run: |
tmpout=$(mktemp)
tmperr=$(mktemp)
@ -142,3 +153,47 @@ runs:
if [[ -n "$trace_url" ]]; then
echo "traceURL=$trace_url" >> "$GITHUB_OUTPUT"
fi
# Generate job summary content
summary_content(){
echo -e "## Command\n"
echo '```bash'
cmd="dagger $VERB $CMD"
if [[ -n "$INPUT_MODULE" ]]; then
echo -e -E "DAGGER_MODULE=\"$INPUT_MODULE\" $cmd"
else
echo -e -E "$cmd"
fi
echo '```'
if [[ -n "$SCRIPT" ]]; then
echo -e "### Script\n"
echo '```bash'
cat "$SCRIPT"
echo -e "\n"
echo '```'
fi
echo -e "## Dagger trace\n"
if [[ -n "$trace_url" ]]; then
echo "[$trace_url]($trace_url)"
else
echo "No trace available. To setup: [https://dagger.cloud/traces/setup](https://dagger.cloud/traces/setup)"
fi
echo -e "## Dagger version\n"
echo '```bash'
dagger version || true
echo '```'
echo -e "---\n"
}
# Write to custom summary path if specified
if [[ -n "${{ inputs.summary-path }}" ]]; then
summary_content > "${{ inputs.summary-path }}"
fi
# Write to GitHub step summary if enabled (default: true)
if [[ "${{ inputs.enable-github-summary }}" == "true" ]]; then
summary_content > "${GITHUB_STEP_SUMMARY}"
fi