test-images #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: test-images | |
| # This workflow can be triggered manually from any branch. | |
| # Select the branch in the GitHub Actions UI when triggering the workflow. | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| package_repository: | |
| description: "Package repository name (e.g., pgedge-postgres-internal, pgedge-postgres)" | |
| type: string | |
| default: "pgedge-postgres-internal" | |
| required: false | |
| tags: | |
| description: "Comma-separated list of tags to test (e.g., 17-spock5-standard,17-spock5-minimal)" | |
| type: string | |
| required: true | |
| architectures: | |
| description: "Comma-separated list of architectures to test (x86,arm)" | |
| type: string | |
| default: "x86,arm" | |
| required: false | |
| permissions: | |
| contents: read | |
| packages: read | |
| env: | |
| IMAGE_REGISTRY: ghcr.io/pgedge | |
| jobs: | |
| # Parse inputs and generate the test matrix | |
| setup: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.generate.outputs.matrix }} | |
| steps: | |
| - name: Generate test matrix | |
| id: generate | |
| run: | | |
| # Parse tags | |
| IFS=',' read -ra TAGS <<< "${{ inputs.tags }}" | |
| # Parse architectures | |
| IFS=',' read -ra ARCHS <<< "${{ inputs.architectures }}" | |
| # Build matrix JSON | |
| matrix_items="" | |
| for tag in "${TAGS[@]}"; do | |
| tag=$(echo "$tag" | xargs) # trim whitespace | |
| # Determine flavor from tag | |
| if [[ "$tag" == *"-minimal"* ]]; then | |
| flavor="minimal" | |
| elif [[ "$tag" == *"-standard"* ]]; then | |
| flavor="standard" | |
| else | |
| # Default to standard if not specified | |
| flavor="standard" | |
| fi | |
| for arch in "${ARCHS[@]}"; do | |
| arch=$(echo "$arch" | xargs) # trim whitespace | |
| # Map user-friendly arch names to runner names | |
| # Accept "arm" or "arm64" -> use ubuntu-24.04-arm | |
| # Accept "x86" or "amd64" -> use ubuntu-latest | |
| if [[ "$arch" == "arm" ]] || [[ "$arch" == "arm64" ]]; then | |
| runner="ubuntu-24.04-arm" | |
| arch_display="arm" | |
| elif [[ "$arch" == "x86" ]] || [[ "$arch" == "amd64" ]]; then | |
| runner="ubuntu-latest" | |
| arch_display="x86" | |
| else | |
| echo "Error: Unknown architecture '$arch'. Use 'x86' or 'arm'" | |
| exit 1 | |
| fi | |
| if [[ -n "$matrix_items" ]]; then | |
| matrix_items+="," | |
| fi | |
| matrix_items+="{\"tag\":\"$tag\",\"arch\":\"$arch_display\",\"flavor\":\"$flavor\",\"runner\":\"$runner\"}" | |
| done | |
| done | |
| echo "matrix={\"include\":[$matrix_items]}" >> $GITHUB_OUTPUT | |
| echo "Generated matrix: {\"include\":[$matrix_items]}" | |
| test: | |
| needs: setup | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.setup.outputs.matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.24.11' | |
| cache-dependency-path: tests/go.sum | |
| - name: Login to GitHub Container Registry | |
| env: | |
| GH_USER: ${{ github.actor }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "${GH_TOKEN}" | docker login ghcr.io -u "${GH_USER}" --password-stdin | |
| - name: Pull image | |
| run: | | |
| IMAGE="${{ env.IMAGE_REGISTRY }}/${{ inputs.package_repository }}:${{ matrix.tag }}" | |
| echo "Pulling image: $IMAGE" | |
| docker pull "$IMAGE" | |
| - name: Run tests | |
| run: | | |
| IMAGE="${{ env.IMAGE_REGISTRY }}/${{ inputs.package_repository }}:${{ matrix.tag }}" | |
| make test-image IMAGE="$IMAGE" FLAVOR="${{ matrix.flavor }}" | |
| results-summary: | |
| needs: [setup, test] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Output | |
| run: | | |
| echo "| Input | Value |" >> $GITHUB_STEP_SUMMARY | |
| echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Package Repository | ${{ inputs.package_repository }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Tags | ${{ inputs.tags }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Architectures | ${{ inputs.architectures }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [[ "${{ needs.test.result }}" == "success" ]]; then | |
| echo "✅ **All tests passed!**" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ **Some tests failed.** Check the job logs for details." >> $GITHUB_STEP_SUMMARY | |
| fi |