Skip to content

image-pushed

image-pushed #672

name: Interchain Test
on:
repository_dispatch:
types: [image-pushed]
workflow_dispatch:
inputs:
from_version:
description: 'Version to upgrade from'
required: false
type: string
to_version:
description: 'Version to upgrade to (defaults to current branch/tag)'
required: false
type: string
upgrade_name:
description: 'Name of the upgrade'
required: false
type: string
# Least-privilege by default; grant per-job if needed.
permissions:
contents: read
pull-requests: write
statuses: write
jobs:
prepare-matrix:
runs-on: depot-ubuntu-22.04-4
steps:
- name: Get metadata
id: get-metadata
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
RAW_REF_NAME: ${{ github.ref_name }}
RAW_TO_VERSION: ${{ inputs.to_version }}
PD_REF_NAME: ${{ github.event.client_payload.ref_name }}
PD_TAG_NAME: ${{ github.event.client_payload.tag_name }}
PD_PR_NUMBER: ${{ github.event.client_payload.pr_number }}
PD_PR_HEAD_SHA: ${{ github.event.client_payload.pr_head_sha }}
run: |
set -euo pipefail
if [[ "${EVENT_NAME}" == 'repository_dispatch' ]]; then
ref="${PD_REF_NAME:-}"
tag="${PD_TAG_NAME:-}"
pr_num="${PD_PR_NUMBER:-}"
pr_sha="${PD_PR_HEAD_SHA:-}"
if [[ -n "$tag" ]]; then
echo "ref_name=${ref}" >> "$GITHUB_OUTPUT"
echo "tag_name=${tag}" >> "$GITHUB_OUTPUT"
else
echo "ref_name=${ref}" >> "$GITHUB_OUTPUT"
echo "tag_name=${ref}" >> "$GITHUB_OUTPUT"
fi
echo "pr_number=${pr_num}" >> "$GITHUB_OUTPUT"
echo "pr_head_sha=${pr_sha}" >> "$GITHUB_OUTPUT"
else
ref="${RAW_REF_NAME:-}"
tover="${RAW_TO_VERSION:-}"
if [[ -n "$tover" ]]; then
chosen="$tover"
else
chosen="$ref"
fi
echo "ref_name=${ref}" >> "$GITHUB_OUTPUT"
echo "tag_name=${chosen}" >> "$GITHUB_OUTPUT"
echo "pr_number=" >> "$GITHUB_OUTPUT"
echo "pr_head_sha=" >> "$GITHUB_OUTPUT"
fi
- name: Check out repository code
uses: actions/checkout@v5
with:
ref: ${{ steps.get-metadata.outputs.ref_name }}
- name: Setup go
uses: actions/setup-go@v5
- name: Post pending status
if: steps.get-metadata.outputs.pr_head_sha != ''
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ steps.get-metadata.outputs.pr_head_sha }}',
state: 'pending',
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: 'Interchain tests are running...',
context: 'Interchain Tests'
});
- name: Prepare matrix
id: generate-matrix
env:
FROM_VERSION: ${{ inputs.from_version }}
UPGRADE_NAME: ${{ inputs.upgrade_name }}
TAG_NAME: ${{ steps.get-metadata.outputs.tag_name }}
run: |
set -euo pipefail
cd ./tests/interchain
echo "Using FROM_VERSION=${FROM_VERSION:-auto}"
echo "Using UPGRADE_NAME=${UPGRADE_NAME:-auto}"
echo "Using TAG_NAME=${TAG_NAME:-(none)}"
matrix_json="$(go run ./matrix_tool/main.go "$TAG_NAME")"
echo "matrix=$matrix_json" >> "$GITHUB_OUTPUT"
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
ref_name: ${{ steps.get-metadata.outputs.ref_name }}
pr_number: ${{ steps.get-metadata.outputs.pr_number }}
pr_head_sha: ${{ steps.get-metadata.outputs.pr_head_sha }}
test:
needs: prepare-matrix
runs-on: depot-ubuntu-22.04-4
name: "${{ matrix.previous_version }} -> ${{ matrix.test_version }} test ${{ matrix.test_name }}"
strategy:
matrix:
${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
fail-fast: false
max-parallel: 10
steps:
- name: Check out repository code
uses: actions/checkout@v5
with:
ref: ${{ needs.prepare-matrix.outputs.ref_name }}
- name: Setup go
uses: actions/setup-go@v5
- name: Run test
env:
TEST_DOCKER_REGISTRY: "ghcr.io/${{ github.repository_owner }}"
TEST_OLD_GAIA_IMAGE_VERSION: "${{ matrix.previous_version }}"
TEST_NEW_GAIA_IMAGE_VERSION: "${{ matrix.test_version }}"
TEST_UPGRADE_NAME: "${{ matrix.upgrade_name }}"
run: |
set -euo pipefail
cd ./tests/interchain
go install github.com/mfridman/tparse@latest
set -o pipefail
go test -v ./... -failfast -p 1 -timeout 5h -run="^${{ matrix.test_name }}" -json | tee "../../output-${{ matrix.previous_version }}-${{ matrix.test_name }}.json" | tparse -follow -all
- name: Upload output
uses: actions/upload-artifact@v4
if: always()
with:
name: output-${{ matrix.previous_version }}-${{ matrix.test_name }}
path: output-${{ matrix.previous_version }}-${{ matrix.test_name }}.json
test-report:
needs: [test, prepare-matrix]
if: always()
runs-on: depot-ubuntu-22.04-4
steps:
- name: Download all artifacts
uses: actions/download-artifact@v6
with:
path: ./outputs
- name: Setup go
uses: actions/setup-go@v5
- name: Prep report
env:
TEST_MATRIX: ${{ needs.prepare-matrix.outputs.matrix }}
run: |
set -euo pipefail
go install github.com/becheran/go-testreport@latest
TEST_VERSION="$(echo "$TEST_MATRIX" | jq -r '.test_version[0]')"
UPGRADE_NAME="$(echo "$TEST_MATRIX" | jq -r '.upgrade_name[0]')"
echo "$TEST_MATRIX" | jq -r '.previous_version[]' | while read -r PREV_VERSION; do
cat ./outputs/output-"${PREV_VERSION}"-*/*.json > "combined-${PREV_VERSION}.json"
go-testreport -vars="Title:${PREV_VERSION} -> ${UPGRADE_NAME} (${TEST_VERSION})" -output="test-report-${PREV_VERSION}.md" -input="combined-${PREV_VERSION}.json" || true
echo '' >> "test-report-${PREV_VERSION}.md"
done
cat test-report-*.md > test-report.md
cat test-report.md > "$GITHUB_STEP_SUMMARY"
- name: Upload output
uses: actions/upload-artifact@v4
with:
name: test-report
path: test-report.md
post-commit-status:
needs: [test, prepare-matrix]
if: always() && needs.prepare-matrix.outputs.pr_head_sha != ''
runs-on: depot-ubuntu-22.04-4
steps:
- name: Set commit status
uses: actions/github-script@v7
with:
script: |
const testJob = context.payload.workflow_run ||
(await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId
})).data.jobs.find(j => j.name.includes('test'));
const conclusion = '${{ needs.test.result }}';
const state = conclusion === 'success' ? 'success' : 'failure';
const description = conclusion === 'success'
? 'All interchain tests passed'
: 'Some interchain tests failed';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ needs.prepare-matrix.outputs.pr_head_sha }}',
state: state,
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: description,
context: 'Interchain Tests'
});