Skip to content

Commit 0178878

Browse files
committed
Fixes all codacy issues
1 parent dbf905e commit 0178878

8 files changed

Lines changed: 171 additions & 159 deletions

File tree

.github/workflows/build_images.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@ jobs:
5454
runs-on: ubuntu-latest
5555
steps:
5656
- name: Checkout repository
57-
uses: actions/checkout@v4
57+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
5858

5959
- name: Setup QEMU
60-
uses: docker/setup-qemu-action@v3
60+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
6161

6262
- name: Install cosign
63-
uses: sigstore/cosign-installer@v3
63+
uses: sigstore/cosign-installer@7e8b541eb2e61bf99390e1afd4be13a184e9ebc5 # v3.10.1
6464

6565
- name: Setup Docker Buildx
6666
run: |
6767
make buildx-init
6868
6969
- name: Login to GitHub Container Registry
70-
uses: docker/login-action@v3.4.0
70+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
7171
with:
7272
registry: ghcr.io
7373
username: ${{ github.actor }}
7474
password: ${{ secrets.GITHUB_TOKEN }}
7575

7676
- name: Set up python
77-
uses: actions/setup-python@v5
77+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
7878
with:
7979
python-version: '3.x'
8080

.github/workflows/pr_test_latest.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
tags: ${{ steps.get-tags.outputs.tags }}
2828
steps:
2929
- name: Checkout repository
30-
uses: actions/checkout@v4
30+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
3131

3232
- name: Set up Python
33-
uses: actions/setup-python@v5
33+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
3434
with:
3535
python-version: '3.x'
3636

@@ -109,12 +109,12 @@ jobs:
109109
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
110110
steps:
111111
- name: Checkout repository
112-
uses: actions/checkout@v4
112+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
113113

114114
- name: Set up Go
115-
uses: actions/setup-go@v5
115+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
116116
with:
117-
go-version: '1.23'
117+
go-version: '1.25'
118118
cache-dependency-path: tests/go.sum
119119

120120
- name: Pull image

.github/workflows/test_images.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ jobs:
9494
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
9595
steps:
9696
- name: Checkout repository
97-
uses: actions/checkout@v4
97+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
9898

9999
- name: Set up Go
100-
uses: actions/setup-go@v5
100+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
101101
with:
102-
go-version: '1.23'
102+
go-version: '1.25'
103103
cache-dependency-path: tests/go.sum
104104

105105
- name: Pull image

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
.vscode
33
.DS_Store
44

5+
# Python
6+
__pycache__/
7+
8+
# Go binaries
9+
tests/tests
10+

scripts/build_pgedge_images.py

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,49 @@ def add_tag(repo: str, existing_tag: Tag, new_tag: Tag, dry_run: bool):
297297
)
298298

299299

300+
def _log_config(config: "Config") -> None:
301+
if config.dry_run:
302+
logging.info("dry run enabled. build and publish actions will be skipped.")
303+
if config.republish:
304+
logging.info("republish enabled. images will be republished.")
305+
if config.no_cache:
306+
logging.info("no cache enabled. images will be built without cache.")
307+
if config.only_postgres_version:
308+
logging.info(f"only postgres {config.only_postgres_version} enabled. other images will be skipped.")
309+
if config.only_spock_version:
310+
logging.info(f"only spock {config.only_spock_version} enabled. other images will be skipped.")
311+
if config.only_arch:
312+
logging.info(f"only arch {config.only_arch} enabled. other images will be skipped.")
313+
314+
315+
def _should_skip_image(image: "PgEdgeImage", config: "Config") -> bool:
316+
if config.only_postgres_version and image.postgres_version != config.only_postgres_version:
317+
return True
318+
if config.only_spock_version and image.spock_version != config.only_spock_version:
319+
return True
320+
return False
321+
322+
323+
def _process_extra_tags(config: "Config", image: "PgEdgeImage", published: set) -> None:
324+
for tag in image.extra_tags:
325+
tag_published = published_digests(config.repo, tag)
326+
if len(tag_published) == 0 or not tag_published.issubset(published) or config.republish:
327+
add_tag(repo=config.repo, existing_tag=image.build_tag, new_tag=tag, dry_run=config.dry_run)
328+
else:
329+
logging.info(f"{tag} is already up-to-date")
330+
331+
332+
def _process_image(config: "Config", image: "PgEdgeImage") -> None:
333+
published = published_digests(config.repo, image.build_tag)
334+
if len(published) == 0 or config.republish:
335+
build(repo=config.repo, image=image, dry_run=config.dry_run, no_cache=config.no_cache, only_arch=config.only_arch)
336+
digest = index_digest(config.repo, image.build_tag)
337+
sign(repo=config.repo, digest=digest, dry_run=config.dry_run)
338+
else:
339+
logging.info(f"{image.build_tag} is already published")
340+
_process_extra_tags(config, image, published)
341+
342+
300343
def main():
301344
logging.basicConfig(
302345
level=logging.INFO,
@@ -305,84 +348,18 @@ def main():
305348

306349
config = Config.from_env()
307350

308-
# If list_latest_tags is enabled, output tags and exit
309351
if config.list_latest_tags:
310-
tags = get_latest_tags()
311-
# Output as comma-separated list
312-
print(",".join(tags))
352+
print(",".join(get_latest_tags()))
313353
return
314354

315-
if config.dry_run:
316-
logging.info("dry run enabled. build and publish actions will be skipped.")
317-
318-
if config.republish:
319-
logging.info("republish enabled. images will be republished.")
320-
321-
if config.no_cache:
322-
logging.info("no cache enabled. images will be built without cache.")
323-
324-
if config.only_postgres_version:
325-
logging.info(
326-
f"only postgres {config.only_postgres_version} enabled. other images will be skipped."
327-
)
328-
329-
if config.only_spock_version:
330-
logging.info(
331-
f"only spock {config.only_spock_version} enabled. other images will be skipped."
332-
)
333-
334-
if config.only_arch:
335-
logging.info(
336-
f"only arch {config.only_arch} enabled. other images will be skipped."
337-
)
338-
355+
_log_config(config)
339356
validate_images(all_images)
340357

341358
for image in all_images:
342-
if (
343-
config.only_postgres_version
344-
and image.postgres_version != config.only_postgres_version
345-
) or (
346-
config.only_spock_version
347-
and image.spock_version != config.only_spock_version
348-
):
359+
if _should_skip_image(image, config):
349360
logging.info(f"skipping image {image.build_tag}")
350361
continue
351-
352-
published = published_digests(config.repo, image.build_tag)
353-
if len(published) == 0 or config.republish:
354-
build(
355-
repo=config.repo,
356-
image=image,
357-
dry_run=config.dry_run,
358-
no_cache=config.no_cache,
359-
only_arch=config.only_arch,
360-
)
361-
362-
id = index_digest(config.repo, image.build_tag)
363-
sign(
364-
repo=config.repo,
365-
digest=id,
366-
dry_run=config.dry_run,
367-
)
368-
else:
369-
logging.info(f"{image.build_tag} is already published")
370-
371-
for tag in image.extra_tags:
372-
tag_published = published_digests(config.repo, tag)
373-
if (
374-
len(tag_published) == 0
375-
or not tag_published.issubset(published)
376-
or config.republish
377-
):
378-
add_tag(
379-
repo=config.repo,
380-
existing_tag=image.build_tag,
381-
new_tag=tag,
382-
dry_run=config.dry_run,
383-
)
384-
else:
385-
logging.info(f"{tag} is already up-to-date")
362+
_process_image(config, image)
386363

387364

388365
def get_latest_tags() -> list[str]:

tests/go.mod

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
module github.com/pgedge/postgres-images/tests
22

3-
go 1.24.11
3+
go 1.25.8
44

55
require github.com/docker/docker v28.0.0+incompatible
66

77
require (
88
github.com/Microsoft/go-winio v0.4.14 // indirect
9+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
910
github.com/containerd/log v0.1.0 // indirect
1011
github.com/distribution/reference v0.6.0 // indirect
1112
github.com/docker/go-connections v0.5.0 // indirect
1213
github.com/docker/go-units v0.5.0 // indirect
1314
github.com/felixge/httpsnoop v1.0.4 // indirect
14-
github.com/go-logr/logr v1.4.2 // indirect
15+
github.com/go-logr/logr v1.4.3 // indirect
1516
github.com/go-logr/stdr v1.2.2 // indirect
1617
github.com/gogo/protobuf v1.3.2 // indirect
1718
github.com/moby/docker-image-spec v1.3.1 // indirect
@@ -20,13 +21,14 @@ require (
2021
github.com/opencontainers/go-digest v1.0.0 // indirect
2122
github.com/opencontainers/image-spec v1.1.0 // indirect
2223
github.com/pkg/errors v0.9.1 // indirect
24+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
2325
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
24-
go.opentelemetry.io/otel v1.29.0 // indirect
25-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect
26-
go.opentelemetry.io/otel/metric v1.29.0 // indirect
27-
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
28-
go.opentelemetry.io/otel/trace v1.29.0 // indirect
29-
golang.org/x/sys v0.25.0 // indirect
26+
go.opentelemetry.io/otel v1.40.0 // indirect
27+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0 // indirect
28+
go.opentelemetry.io/otel/metric v1.40.0 // indirect
29+
go.opentelemetry.io/otel/sdk v1.40.0 // indirect
30+
go.opentelemetry.io/otel/trace v1.40.0 // indirect
31+
golang.org/x/sys v0.40.0 // indirect
3032
golang.org/x/time v0.14.0 // indirect
3133
gotest.tools/v3 v3.5.1 // indirect
3234
)

0 commit comments

Comments
 (0)