|
| 1 | +name: PR Test Latest Images |
| 2 | + |
| 3 | +# This workflow runs on pull requests and tests the latest images |
| 4 | +# from the internal repository to ensure they still work with any changes. |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + packages: read |
| 14 | + |
| 15 | +env: |
| 16 | + IMAGE_REGISTRY: ghcr.io/pgedge |
| 17 | + PACKAGE_REPOSITORY: pgedge-postgres-internal |
| 18 | + |
| 19 | +jobs: |
| 20 | + # Get latest tags and generate test matrix |
| 21 | + setup: |
| 22 | + # Skip for forked PRs since they won't have access to internal packages |
| 23 | + if: github.event.pull_request.head.repo.full_name == github.repository |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + matrix: ${{ steps.generate.outputs.matrix }} |
| 27 | + tags: ${{ steps.get-tags.outputs.tags }} |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up Python |
| 33 | + uses: actions/setup-python@v5 |
| 34 | + with: |
| 35 | + python-version: '3.x' |
| 36 | + |
| 37 | + - name: Get latest tags |
| 38 | + id: get-tags |
| 39 | + run: | |
| 40 | + set -e |
| 41 | + TAGS=$(make latest-tags) |
| 42 | + |
| 43 | + # Validate that tags were retrieved successfully |
| 44 | + if [ -z "$TAGS" ]; then |
| 45 | + echo "Error: Failed to retrieve latest tags. make latest-tags returned empty output." |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + |
| 49 | + echo "tags=$TAGS" >> $GITHUB_OUTPUT |
| 50 | + echo "Latest tags: $TAGS" |
| 51 | +
|
| 52 | + - name: Generate test matrix |
| 53 | + id: generate |
| 54 | + run: | |
| 55 | + # Parse tags from make output |
| 56 | + TAGS="${{ steps.get-tags.outputs.tags }}" |
| 57 | + IFS=',' read -ra TAG_ARRAY <<< "$TAGS" |
| 58 | + |
| 59 | + # Test on both architectures |
| 60 | + ARCHS=("x86" "arm") |
| 61 | + |
| 62 | + # Build matrix JSON |
| 63 | + matrix_items="" |
| 64 | + for tag in "${TAG_ARRAY[@]}"; do |
| 65 | + tag=$(echo "$tag" | xargs) # trim whitespace |
| 66 | + |
| 67 | + # Determine flavor from tag |
| 68 | + if [[ "$tag" == *"-minimal"* ]]; then |
| 69 | + flavor="minimal" |
| 70 | + elif [[ "$tag" == *"-standard"* ]]; then |
| 71 | + flavor="standard" |
| 72 | + else |
| 73 | + # Default to standard if not specified |
| 74 | + flavor="standard" |
| 75 | + fi |
| 76 | + |
| 77 | + for arch in "${ARCHS[@]}"; do |
| 78 | + arch=$(echo "$arch" | xargs) # trim whitespace |
| 79 | + |
| 80 | + # Map user-friendly arch names to runner names |
| 81 | + if [[ "$arch" == "arm" ]] || [[ "$arch" == "arm64" ]]; then |
| 82 | + runner="ubuntu-24.04-arm" |
| 83 | + arch_display="arm" |
| 84 | + elif [[ "$arch" == "x86" ]] || [[ "$arch" == "amd64" ]]; then |
| 85 | + runner="ubuntu-latest" |
| 86 | + arch_display="x86" |
| 87 | + else |
| 88 | + echo "Error: Unknown architecture '$arch'. Use 'x86' or 'arm'" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + |
| 92 | + if [[ -n "$matrix_items" ]]; then |
| 93 | + matrix_items+="," |
| 94 | + fi |
| 95 | + matrix_items+="{\"tag\":\"$tag\",\"arch\":\"$arch_display\",\"flavor\":\"$flavor\",\"runner\":\"$runner\"}" |
| 96 | + done |
| 97 | + done |
| 98 | + |
| 99 | + echo "matrix={\"include\":[$matrix_items]}" >> $GITHUB_OUTPUT |
| 100 | + echo "Generated matrix: {\"include\":[$matrix_items]}" |
| 101 | +
|
| 102 | + test: |
| 103 | + # Skip for forked PRs since they won't have access to internal packages |
| 104 | + if: github.event.pull_request.head.repo.full_name == github.repository |
| 105 | + needs: setup |
| 106 | + runs-on: ${{ matrix.runner }} |
| 107 | + strategy: |
| 108 | + fail-fast: false |
| 109 | + matrix: ${{ fromJson(needs.setup.outputs.matrix) }} |
| 110 | + steps: |
| 111 | + - name: Checkout repository |
| 112 | + uses: actions/checkout@v4 |
| 113 | + |
| 114 | + - name: Set up Go |
| 115 | + uses: actions/setup-go@v5 |
| 116 | + with: |
| 117 | + go-version: '1.23' |
| 118 | + cache-dependency-path: tests/go.sum |
| 119 | + |
| 120 | + - name: Pull image |
| 121 | + run: | |
| 122 | + IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.PACKAGE_REPOSITORY }}:${{ matrix.tag }}" |
| 123 | + echo "Pulling image: $IMAGE" |
| 124 | + docker pull "$IMAGE" |
| 125 | +
|
| 126 | + - name: Run tests |
| 127 | + run: | |
| 128 | + IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.PACKAGE_REPOSITORY }}:${{ matrix.tag }}" |
| 129 | + make test-image IMAGE="$IMAGE" FLAVOR="${{ matrix.flavor }}" |
| 130 | +
|
| 131 | + results: |
| 132 | + # Skip for forked PRs since they won't have access to internal packages |
| 133 | + # Also use always() to ensure results are shown even if test job fails |
| 134 | + if: github.event.pull_request.head.repo.full_name == github.repository && always() |
| 135 | + needs: [setup, test] |
| 136 | + runs-on: ubuntu-latest |
| 137 | + steps: |
| 138 | + - name: Output |
| 139 | + run: | |
| 140 | + echo "## Test Results" >> $GITHUB_STEP_SUMMARY |
| 141 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 142 | + echo "| Input | Value |" >> $GITHUB_STEP_SUMMARY |
| 143 | + echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY |
| 144 | + echo "| Package Repository | ${{ env.PACKAGE_REPOSITORY }} |" >> $GITHUB_STEP_SUMMARY |
| 145 | + echo "| Tags | ${{ needs.setup.outputs.tags }} |" >> $GITHUB_STEP_SUMMARY |
| 146 | + echo "| Architectures | x86,arm |" >> $GITHUB_STEP_SUMMARY |
| 147 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 148 | + |
| 149 | + if [[ "${{ needs.test.result }}" == "success" ]]; then |
| 150 | + echo "✅ **All tests passed!**" >> $GITHUB_STEP_SUMMARY |
| 151 | + else |
| 152 | + echo "❌ **Some tests failed.** Check the job logs for details." >> $GITHUB_STEP_SUMMARY |
| 153 | + fi |
0 commit comments