Skip to content

Commit 3c6daad

Browse files
committed
ci: update-go workflow to keep go version in sync
Signed-off-by: CrazyMax <[email protected]>
1 parent 5f49931 commit 3c6daad

File tree

2 files changed

+145
-8
lines changed

2 files changed

+145
-8
lines changed

.github/workflows/update-go.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: update-go
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch:
9+
schedule:
10+
- cron: '0 */6 * * *'
11+
12+
jobs:
13+
pkgs:
14+
uses: ./.github/workflows/.pkgs.yml
15+
16+
build:
17+
runs-on: ubuntu-24.04
18+
needs:
19+
- pkgs
20+
steps:
21+
-
22+
name: Checkout
23+
uses: actions/checkout@v6
24+
-
25+
name: Get GO_VERSION from upstream repositories
26+
id: get-go-versions
27+
uses: actions/github-script@v8
28+
env:
29+
INPUT_PKGS: ${{ needs.pkgs.outputs.list }}
30+
with:
31+
script: |
32+
const inpPkgs = JSON.parse(core.getInput('pkgs'));
33+
34+
const goVersions = [];
35+
for (const pkg of inpPkgs) {
36+
await core.group(`Getting go version for ${pkg} package`, async () => {
37+
let pkgRepo = '';
38+
let pkgRef = '';
39+
let pkgDockerfile = '';
40+
await exec.getExecOutput('docker', ['buildx', 'bake', `metadata-${pkg}`, '--print'], {
41+
ignoreReturnCode: true,
42+
silent: true
43+
}).then(res => {
44+
if (res.stderr.length > 0 && res.exitCode != 0) {
45+
throw new Error(res.stderr);
46+
}
47+
const dt = JSON.parse(res.stdout.trim());
48+
pkgRepo = dt.target[`metadata-${pkg}`].args.PKG_REPO;
49+
pkgRef = dt.target[`metadata-${pkg}`].args.PKG_REF;
50+
pkgDockerfile = dt.target[`metadata-${pkg}`].args.PKG_REMOTE_DOCKERFILE;
51+
});
52+
53+
let goVersion = '';
54+
core.info(`Fetching GO_VERSION from ${pkgRepo}#${pkgRef}`);
55+
await exec.getExecOutput('docker', ['buildx', 'build', '--call', 'outline,format=json', '-f', pkgDockerfile, `${pkgRepo}#${pkgRef}`], {
56+
ignoreReturnCode: true,
57+
silent: true
58+
}).then(res => {
59+
if (res.stderr.length > 0 && res.exitCode != 0) {
60+
core.warning(`Failed to fetch outline: ${res.stderr}`);
61+
return;
62+
}
63+
const outline = JSON.parse(res.stdout.trim());
64+
goVersion = outline.args.find(arg => arg.name === 'GO_VERSION')?.value;
65+
if (!goVersion) {
66+
core.info(JSON.stringify(outline, null, 2));
67+
core.warning(`GO_VERSION not found from outline request`);
68+
return;
69+
}
70+
core.info(`Found GO_VERSION: ${goVersion}`);
71+
});
72+
73+
if (goVersion) {
74+
goVersions.push({ pkg: pkg, go_version: goVersion });
75+
}
76+
});
77+
}
78+
79+
core.setOutput('list', JSON.stringify(goVersions));
80+
-
81+
name: Set GO_VERSION in docker-bake.hcl and Dockerfiles
82+
uses: actions/github-script@v8
83+
env:
84+
INPUT_GO_VERSIONS: ${{ steps.get-go-versions.outputs.list }}
85+
with:
86+
script: |
87+
const fs = require('fs');
88+
const path = require('path');
89+
90+
const inpGoVersions = JSON.parse(core.getInput('go_versions'));
91+
92+
for (const item of inpGoVersions) {
93+
const bakefilePath = 'docker-bake.hcl';
94+
core.info(`Updating GO_VERSION to ${item.go_version} in ${bakefilePath} for _pkg-${item.pkg} target`);
95+
let bakeContent = fs.readFileSync(bakefilePath, 'utf8');
96+
const bakeRegex = new RegExp(
97+
`target "_pkg-${item.pkg}" \\{[\\s\\S]*?GO_VERSION = GO_VERSION != null && GO_VERSION != "" \\? GO_VERSION : "([^"]+)"`,
98+
'm'
99+
);
100+
bakeContent = bakeContent.replace(bakeRegex, (match, p1) => {
101+
return match.replace(p1, item.go_version);
102+
});
103+
fs.writeFileSync(bakefilePath, bakeContent);
104+
105+
const dockerfilePath = path.join('pkg', item.pkg, 'Dockerfile');
106+
core.info(`Updating GO_VERSION to ${item.go_version} in ${dockerfilePath}`);
107+
let dockerfileContent = fs.readFileSync(dockerfilePath, 'utf8');
108+
const dockerfileRegex = /^ARG GO_VERSION=.*$/m;
109+
dockerfileContent = dockerfileContent.replace(dockerfileRegex, `ARG GO_VERSION="${item.go_version}"`);
110+
fs.writeFileSync(dockerfilePath, dockerfileContent);
111+
}
112+
113+
await exec.exec(`git diff --color=always`);
114+
-
115+
name: Commit changes
116+
run: |
117+
git add -A .
118+
-
119+
name: Create PR
120+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
121+
with:
122+
base: main
123+
branch: bot/update-go
124+
signoff: true
125+
delete-branch: true
126+
title: "chore: align go version from upstream repositories"
127+
body: |
128+
Keep Go versions in sync with upstream repositories.
129+
draft: false

docker-bake.hcl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,10 @@ target "_pkg-buildx" {
522522
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-buildx-plugin"
523523
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/buildx.git"
524524
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
525-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/buildx/blob/854a58a65d5ada26ddc8b6ebd60ddb89fa5616a3/Dockerfile#L3
525+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/buildx/blob/master/Dockerfile
526526
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
527527
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
528+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
528529
}
529530
}
530531

@@ -533,9 +534,10 @@ target "_pkg-compose" {
533534
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-compose-plugin"
534535
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/compose.git"
535536
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
536-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/compose/blob/fa081274567ac350f0e5f16abbe51701b320626e/Dockerfile#L18
537+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/compose/blob/main/Dockerfile
537538
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
538539
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
540+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
539541
}
540542
}
541543

@@ -544,10 +546,11 @@ target "_pkg-containerd" {
544546
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "containerd.io"
545547
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/containerd/containerd.git"
546548
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
547-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/containerd/containerd/blob/2d28d98490f53d78c98faecfc91f9fd54cdbc16e/.github/workflows/release.yml#L16
549+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/containerd/containerd/blob/main/.github/workflows/release/Dockerfile
548550
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
549551
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
550552
RUNC_REF = RUNC_REF != null && RUNC_REF != "" ? RUNC_REF : null
553+
PKG_REMOTE_DOCKERFILE = ".github/workflows/release/Dockerfile"
551554
}
552555
}
553556

@@ -556,9 +559,10 @@ target "_pkg-credential-helpers" {
556559
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-credential-helpers"
557560
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/docker-credential-helpers.git"
558561
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
559-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/docker-credential-helpers/blob/b7a754b9ffdf0e99e63ca384435bdacf4bc83e6b/Dockerfile#L3
562+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/docker-credential-helpers/blob/master/Dockerfile
560563
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
561564
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
565+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
562566
}
563567
}
564568

@@ -567,9 +571,10 @@ target "_pkg-docker-cli" {
567571
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-ce-cli"
568572
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/cli.git"
569573
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
570-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/cli/blob/d16defd9e237a02e4e8b8710d9ce4a15472e60c8/Dockerfile#L11
574+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/docker/cli/blob/master/Dockerfile
571575
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
572576
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : "5"
577+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
573578
}
574579
}
575580

@@ -578,9 +583,10 @@ target "_pkg-docker-engine" {
578583
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-ce"
579584
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/docker.git"
580585
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master"
581-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/moby/moby/blob/4b978319922166bab9116b3e60e716a62b9cf130/Dockerfile#L3
586+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.3" # https://github.com/moby/moby/blob/master/Dockerfile
582587
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
583588
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : "5"
589+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
584590
}
585591
}
586592

@@ -589,9 +595,10 @@ target "_pkg-model" {
589595
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-model-plugin"
590596
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/model-runner.git"
591597
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
592-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/model-runner/blob/039f7a31c0365f9161c9b9b6bb3888161d16e388/cmd/cli/Dockerfile#L3
598+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.24.9" # https://github.com/docker/model-runner/blob/main/cmd/cli/Dockerfile
593599
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
594600
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
601+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
595602
}
596603
}
597604

@@ -600,9 +607,10 @@ target "_pkg-cagent" {
600607
PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "cagent"
601608
PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/cagent.git"
602609
PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "main"
603-
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.4" # https://github.com/docker/cagent/blob/259774ed55b2b51c4b602d9636d68a6bb23117ec/Dockerfile#L6
610+
GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.25.4" # https://github.com/docker/cagent/blob/main/Dockerfile
604611
GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm"
605612
PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : ""
613+
PKG_REMOTE_DOCKERFILE = "Dockerfile"
606614
}
607615
}
608616

0 commit comments

Comments
 (0)