Skip to content

Commit

Permalink
test.yml: upload failed-logs as an artifact if test-templates.sh
Browse files Browse the repository at this point in the history
…fails and `failed-logs` exists.

silence yamllint

test:yml: switch to `if: always()`, if the previous step uses `retry`

test.yml: change to `failure-logs`

upload_failure_logs_if_exists: fix error: required property is missing: shell

upload_failure_logs_if_exists: ensure the artifact name is unique.

upload_failure_logs_if_exists: normalize suffix input

upload_failure_logs_if_exists: add description comment to normalize-suffix

Signed-off-by: Norio Nomura <[email protected]>
  • Loading branch information
norio-nomura committed Jul 24, 2024
1 parent 3075bd9 commit 8741f67
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/actions/upload_failure_logs_if_exists/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'upload failure-logs if exists'
description: 'upload failure-logs if exists'
inputs:
suffix:
description: suffix to append to the name of the artifact
required: false
default: ''
runs:
using: "composite"
steps:
- name: "Check if failure-logs exists"
if: always()
id: check-if-failure-logs-exists
run: echo "exists=$([ -d "failure-logs" ] && echo "true" || echo "false")" >> "$GITHUB_OUTPUT"
shell: bash
- id: normalize-suffix
# To avoid using special characters in artifact name, normalize the suffix
if: steps.check-if-failure-logs-exists.outputs.exists == 'true'
run: |
suffix="${{ inputs.suffix }}"
suffix="${suffix//[^a-zA-Z0-9_]/_}"
suffix="${suffix:+-$suffix}"
echo "result=$suffix" >> "$GITHUB_OUTPUT"
shell: bash
- name: "Upload failure-logs"
if: steps.check-if-failure-logs-exists.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: failure-logs-${{ github.job }}${{ steps.normalize-suffix.outputs.result }}
path: failure-logs/
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ jobs:
# GHA macOS is slow and flaky, so we only test default.yaml here.
# Other yamls are tested on Linux instances.
#
- if: always()
uses: ./.github/actions/upload_failure_logs_if_exists
- name: "Show cache"
if: always()
run: ./hack/debug-cache.sh
Expand Down Expand Up @@ -258,6 +260,10 @@ jobs:
retry_on: error
max_attempts: 3
command: ./hack/test-templates.sh templates/${{ matrix.template }}
- if: always()
uses: ./.github/actions/upload_failure_logs_if_exists
with:
suffix: ${{ matrix.template }}
- name: "Show cache"
run: ./hack/debug-cache.sh

Expand Down Expand Up @@ -357,6 +363,8 @@ jobs:
retry_on: error
max_attempts: 3
command: ./hack/test-templates.sh templates/vmnet.yaml
- if: always()
uses: ./.github/actions/upload_failure_logs_if_exists

upgrade:
name: "Upgrade test"
Expand Down Expand Up @@ -425,3 +433,7 @@ jobs:
env:
LIMACTL_CREATE_ARGS: "--vm-type vz --mount-type virtiofs --rosetta --network vzNAT"
run: ./hack/test-templates.sh templates/${{ matrix.template }}
- if: failure()
uses: ./.github/actions/upload_failure_logs_if_exists
with:
suffix: ${{ matrix.template }}
4 changes: 3 additions & 1 deletion hack/test-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ function diagnose() {
tail "$HOME/.lima/${NAME}"/*.log
limactl shell "$NAME" systemctl --no-pager status
limactl shell "$NAME" systemctl --no-pager
limactl shell "$NAME" sudo cat /var/log/cloud-init-output.log
mkdir -p failure-logs
cp -pf "$HOME/.lima/${NAME}"/*.log failure-logs/
limactl shell "$NAME" sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log
set +x -e
}

Expand Down

0 comments on commit 8741f67

Please sign in to comment.