Skip to content

Commit ce93d7b

Browse files
committed
Add PR workflow to test latest images and simplify test output
- Remove CodeRabbit badge from README - Simplify test output: replace box-drawing tables with plain text - Add latest-tags function to build_pgedge_images.py - Add make target to get latest tags - Add PR workflow to automatically test latest images against internal repo
1 parent 8235d8a commit ce93d7b

File tree

5 files changed

+187
-19
lines changed

5 files changed

+187
-19
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
runs-on: ubuntu-latest
23+
outputs:
24+
matrix: ${{ steps.generate.outputs.matrix }}
25+
tags: ${{ steps.get-tags.outputs.tags }}
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: '3.x'
34+
35+
- name: Get latest tags
36+
id: get-tags
37+
run: |
38+
TAGS=$(make latest-tags)
39+
echo "tags=$TAGS" >> $GITHUB_OUTPUT
40+
echo "Latest tags: $TAGS"
41+
42+
- name: Generate test matrix
43+
id: generate
44+
run: |
45+
# Parse tags from make output
46+
TAGS="${{ steps.get-tags.outputs.tags }}"
47+
IFS=',' read -ra TAG_ARRAY <<< "$TAGS"
48+
49+
# Test on both architectures
50+
ARCHS=("x86" "arm")
51+
52+
# Build matrix JSON
53+
matrix_items=""
54+
for tag in "${TAG_ARRAY[@]}"; do
55+
tag=$(echo "$tag" | xargs) # trim whitespace
56+
57+
# Determine flavor from tag
58+
if [[ "$tag" == *"-minimal"* ]]; then
59+
flavor="minimal"
60+
elif [[ "$tag" == *"-standard"* ]]; then
61+
flavor="standard"
62+
else
63+
# Default to standard if not specified
64+
flavor="standard"
65+
fi
66+
67+
for arch in "${ARCHS[@]}"; do
68+
arch=$(echo "$arch" | xargs) # trim whitespace
69+
70+
# Map user-friendly arch names to runner names
71+
if [[ "$arch" == "arm" ]] || [[ "$arch" == "arm64" ]]; then
72+
runner="ubuntu-24.04-arm"
73+
arch_display="arm"
74+
elif [[ "$arch" == "x86" ]] || [[ "$arch" == "amd64" ]]; then
75+
runner="ubuntu-latest"
76+
arch_display="x86"
77+
else
78+
echo "Error: Unknown architecture '$arch'. Use 'x86' or 'arm'"
79+
exit 1
80+
fi
81+
82+
if [[ -n "$matrix_items" ]]; then
83+
matrix_items+=","
84+
fi
85+
matrix_items+="{\"tag\":\"$tag\",\"arch\":\"$arch_display\",\"flavor\":\"$flavor\",\"runner\":\"$runner\"}"
86+
done
87+
done
88+
89+
echo "matrix={\"include\":[$matrix_items]}" >> $GITHUB_OUTPUT
90+
echo "Generated matrix: {\"include\":[$matrix_items]}"
91+
92+
test:
93+
needs: setup
94+
runs-on: ${{ matrix.runner }}
95+
strategy:
96+
fail-fast: false
97+
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
98+
steps:
99+
- name: Checkout repository
100+
uses: actions/checkout@v4
101+
102+
- name: Set up Go
103+
uses: actions/setup-go@v5
104+
with:
105+
go-version: '1.24.11'
106+
cache-dependency-path: tests/go.sum
107+
108+
- name: Login to GitHub Container Registry
109+
env:
110+
GH_USER: ${{ github.actor }}
111+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
run: |
113+
echo "${GH_TOKEN}" | docker login ghcr.io -u "${GH_USER}" --password-stdin
114+
115+
- name: Pull image
116+
run: |
117+
IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.PACKAGE_REPOSITORY }}:${{ matrix.tag }}"
118+
echo "Pulling image: $IMAGE"
119+
docker pull "$IMAGE"
120+
121+
- name: Run tests
122+
run: |
123+
IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.PACKAGE_REPOSITORY }}:${{ matrix.tag }}"
124+
make test-image IMAGE="$IMAGE" FLAVOR="${{ matrix.flavor }}"
125+
126+
results:
127+
needs: [setup, test]
128+
runs-on: ubuntu-latest
129+
if: always()
130+
steps:
131+
- name: Output
132+
run: |
133+
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
134+
echo "" >> $GITHUB_STEP_SUMMARY
135+
echo "| Input | Value |" >> $GITHUB_STEP_SUMMARY
136+
echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY
137+
echo "| Package Repository | ${{ env.PACKAGE_REPOSITORY }} |" >> $GITHUB_STEP_SUMMARY
138+
echo "| Tags | ${{ needs.setup.outputs.tags }} |" >> $GITHUB_STEP_SUMMARY
139+
echo "| Architectures | x86,arm |" >> $GITHUB_STEP_SUMMARY
140+
echo "" >> $GITHUB_STEP_SUMMARY
141+
142+
if [[ "${{ needs.test.result }}" == "success" ]]; then
143+
echo "✅ **All tests passed!**" >> $GITHUB_STEP_SUMMARY
144+
else
145+
echo "❌ **Some tests failed.** Check the job logs for details." >> $GITHUB_STEP_SUMMARY
146+
fi

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ ifndef FLAVOR
6767
$(error FLAVOR is required. Usage: make test-image IMAGE=<image> FLAVOR=<minimal|standard>)
6868
endif
6969
cd tests && go run main.go -image $(IMAGE) -flavor $(FLAVOR)
70+
71+
.PHONY: latest-tags
72+
latest-tags:
73+
@./scripts/build_pgedge_images.py --latest-tags

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# pgEdge Postgres Images
22

3-
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/pgEdge/postgres-images?utm_source=oss&utm_medium=github&utm_campaign=pgEdge%2Fpostgres-images&labelColor=171717&color=FF570A&link=https%3A%2F%2Fcoderabbit.ai&label=CodeRabbit+Reviews)
4-
53
This repository provides build scripts for generating pgEdge Postgres container images supporting Postgres versions 16, 17 and 18.
64

75
Images are built from pgEdge Enterprise Postgres packages using a rockylinux9-ubi base image.

scripts/build_pgedge_images.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import subprocess
7+
import sys
78

89
from dataclasses import dataclass
910

@@ -397,5 +398,31 @@ def main():
397398
logging.info(f"{tag} is already up-to-date")
398399

399400

401+
def get_latest_tags() -> list[str]:
402+
"""
403+
Returns a list of the latest mutable tags (without epoch) for all images
404+
that are marked as latest for their Postgres major version.
405+
Returns tags in the format: {postgres_major}-spock{spock_major}-{flavor}
406+
"""
407+
latest_tags = []
408+
for image in all_images:
409+
if image.is_latest_for_pg_major:
410+
# Get the tag without epoch and without postgres minor version
411+
tag = Tag(
412+
postgres_version=image.postgres_major,
413+
flavor=image.flavor,
414+
spock_version=image.spock_major,
415+
)
416+
latest_tags.append(str(tag))
417+
return latest_tags
418+
419+
400420
if __name__ == "__main__":
421+
# Check if we're being called to output latest tags
422+
if len(sys.argv) > 1 and sys.argv[1] == "--latest-tags":
423+
tags = get_latest_tags()
424+
# Output as comma-separated list
425+
print(",".join(tags))
426+
sys.exit(0)
427+
401428
main()

tests/main.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ func parseFlags() (string, string) {
8989
}
9090

9191
func printHeader(image, flavor string) {
92-
fmt.Printf("╔══════════════════════════════════════════════════════════════════╗\n")
93-
fmt.Printf("║ pgEdge Postgres Image Test Suite ║\n")
94-
fmt.Printf("╠══════════════════════════════════════════════════════════════════╣\n")
95-
fmt.Printf("║ Image: %-56s║\n", truncateString(image, 56))
96-
fmt.Printf("║ Flavor: %-56s║\n", flavor)
97-
fmt.Printf("╚══════════════════════════════════════════════════════════════════╝\n")
92+
fmt.Println("pgEdge Postgres Image Test Suite")
93+
fmt.Println()
94+
fmt.Printf(" Image: %s\n", truncateString(image, 80))
95+
fmt.Printf(" Flavor: %s\n", flavor)
9896
fmt.Println()
9997
}
10098

@@ -157,9 +155,7 @@ func runExtensionTests(cli *client.Client, ctx context.Context, image, flavor st
157155
}
158156

159157
func printPhaseHeader(title string) {
160-
fmt.Println("═══════════════════════════════════════════════════════════════════")
161-
fmt.Printf(" %s\n", title)
162-
fmt.Println("═══════════════════════════════════════════════════════════════════")
158+
fmt.Printf("%s\n", title)
163159
fmt.Println()
164160
}
165161

@@ -178,17 +174,14 @@ func printSummary(errorCount int, flavor string) {
178174
}
179175

180176
fmt.Println()
181-
fmt.Printf("╔══════════════════════════════════════════════════════════════════╗\n")
182-
fmt.Printf("║ Test Summary ║\n")
183-
fmt.Printf("╠══════════════════════════════════════════════════════════════════╣\n")
184-
fmt.Printf("║ Tests Executed: %-48d║\n", testsRun)
185-
fmt.Printf("║ Errors: %-48d║\n", errorCount)
177+
fmt.Println("Test Summary")
178+
fmt.Printf(" Tests Executed: %d\n", testsRun)
179+
fmt.Printf(" Errors: %d\n", errorCount)
186180
if errorCount == 0 {
187-
fmt.Printf(" Status: %-48s║\n", "✅ ALL TESTS PASSED")
181+
fmt.Printf(" Status: ✅ ALL TESTS PASSED\n")
188182
} else {
189-
fmt.Printf(" Status: %-48s║\n", "❌ SOME TESTS FAILED")
183+
fmt.Printf(" Status: ❌ SOME TESTS FAILED\n")
190184
}
191-
fmt.Printf("╚══════════════════════════════════════════════════════════════════╝\n")
192185
}
193186

194187
func truncateString(s string, maxLen int) string {

0 commit comments

Comments
 (0)