diff --git a/.github/workflows/_charm-quality-checks.yaml b/.github/workflows/_charm-quality-checks.yaml index 4d4b2314..4e63bbaf 100644 --- a/.github/workflows/_charm-quality-checks.yaml +++ b/.github/workflows/_charm-quality-checks.yaml @@ -7,6 +7,16 @@ on: type: string required: false default: . + log-path: + type: string + description: | + Path to a directory where the .txt logfiles for an integration testing run will be stored. + Relative and absolute file paths are both allowed. + Relative paths are rooted against the charm repository root. + Paths that begin with a wildcard character should be quoted to avoid being + interpreted as YAML aliases. + required: false + default: .logs provider: type: string description: "The provider to choose for integration tests ('machine', 'microk8s', or 'k8s')" @@ -403,3 +413,36 @@ jobs: with: timeout-minutes: 30 limit-access-to-actor: true + - name: Determine log files location + id: get_log_path + run: | + # if the user gave us a relative path, interpret it from the charm-path root. + # if path starts with / it's absolute, else it's relative, and we prepend the (absolute) charm-path to it + case "${{ inputs.log-path }}" in + /*) log_path="${{ inputs.log-path }}" ;; + *) log_path="${{ inputs.charm-path }}/${{ inputs.log-path }}" ;; + esac + echo "log path is: $log_path" + echo "log_path=$log_path" >> "$GITHUB_OUTPUT" + - name: Show logs + run: | + if test -d "${{ steps.get_log_path.outputs.log_path }}"; then + for filename in ${{ steps.get_log_path.outputs.log_path }}/*.txt; do + # begin collapsible log group for each file found in the folder; + # this is github CI markup + # cfr: https://github.com/go-task/task/issues/647 + printf '\n::group:: %s\n' "$filename" + cat "$filename" + printf "\n::endgroup::\n" + done + else + echo "${{ steps.get_log_path.outputs.log_path }} not found" + fi + - name: Upload logs + uses: actions/upload-artifact@v4 + # defaults to 'warn' on failure + with: + name: charm-logs${{ (inputs.charm-path && inputs.charm-path != '.') && format('-{0}', inputs.charm-path) || '' }}-${{ matrix.suite }} + include-hidden-files: true + # we assume that log_path is never going to be an empty string; but it may well be a non-existing directory. + path: ${{ steps.get_log_path.outputs.log_path }} \ No newline at end of file diff --git a/.github/workflows/charm-pull-request.yaml b/.github/workflows/charm-pull-request.yaml index 84cb38fa..ed72b7fa 100644 --- a/.github/workflows/charm-pull-request.yaml +++ b/.github/workflows/charm-pull-request.yaml @@ -8,6 +8,16 @@ on: default: '.' required: false type: string + log-path: + type: string + description: | + Path to a directory where the .txt logfiles for an integration testing run will be stored. + Relative and absolute file paths are both allowed. + Relative paths are rooted against the charm repository root. + Paths that begin with a wildcard character should be quoted to avoid being + interpreted as YAML aliases. + required: false + default: .logs provider: description: "The provider to choose for either machine or k8s tests ('machine', 'microk8s', or 'k8s')" default: 'k8s' @@ -128,6 +138,7 @@ jobs: secrets: inherit with: charm-path: ${{ inputs.charm-path }} + log-path: ${{ inputs.log-path }} provider: ${{ inputs.provider }} charmcraft-channel: ${{ inputs.charmcraft-channel }} juju-channel: ${{ inputs.juju-channel }} diff --git a/README.md b/README.md index fae655c8..4bafa7ff 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ block-beta qualitychecksslow["Quality Checks (integration)"] pack["Pack the charm"] integration["Integration tests"] + displaylogs["Display logs"] + uploadlogs["Upload logs zipfile"] end