Adding tests to postgres images project #2
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: PR Test Latest Images | |
| # This workflow runs on pull requests and tests the latest images | |
| # from the internal repository to ensure they still work with any changes. | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| packages: read | |
| env: | |
| IMAGE_REGISTRY: ghcr.io/pgedge | |
| PACKAGE_REPOSITORY: pgedge-postgres-internal | |
| jobs: | |
| # Get latest tags and generate test matrix | |
| setup: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.generate.outputs.matrix }} | |
| tags: ${{ steps.get-tags.outputs.tags }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Get latest tags | |
| id: get-tags | |
| run: | | |
| TAGS=$(make latest-tags) | |
| echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
| echo "Latest tags: $TAGS" | |
| - name: Generate test matrix | |
| id: generate | |
| run: | | |
| # Parse tags from make output | |
| TAGS="${{ steps.get-tags.outputs.tags }}" | |
| IFS=',' read -ra TAG_ARRAY <<< "$TAGS" | |
| # Test on both architectures | |
| ARCHS=("x86" "arm") | |
| # Build matrix JSON | |
| matrix_items="" | |
| for tag in "${TAG_ARRAY[@]}"; 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 | |
| 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: Pull image | |
| run: | | |
| IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.PACKAGE_REPOSITORY }}:${{ matrix.tag }}" | |
| echo "Pulling image: $IMAGE" | |
| docker pull "$IMAGE" | |
| - name: Run tests | |
| run: | | |
| IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.PACKAGE_REPOSITORY }}:${{ matrix.tag }}" | |
| make test-image IMAGE="$IMAGE" FLAVOR="${{ matrix.flavor }}" | |
| results: | |
| needs: [setup, test] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Output | |
| run: | | |
| echo "## Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Input | Value |" >> $GITHUB_STEP_SUMMARY | |
| echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Package Repository | ${{ env.PACKAGE_REPOSITORY }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Tags | ${{ needs.setup.outputs.tags }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Architectures | x86,arm |" >> $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 |