Skip to content

Commit 998145e

Browse files
committed
fix script for cargo-nextest- with release prefix
1 parent e7294a4 commit 998145e

File tree

4 files changed

+62
-28
lines changed

4 files changed

+62
-28
lines changed

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ RUN url="https://github.com/rhysd/actionlint/releases/download/${ACTIONLINT_VERS
123123

124124
# checksec checks binaries for security issues.
125125
FROM apt-base as checksec
126-
ARG CHECKSEC_VERSION=3.0.2 # repo=slimm609/checksec.sh
127-
RUN url="https://raw.githubusercontent.com/slimm609/checksec.sh/${CHECKSEC_VERSION}/checksec" ; \
126+
ARG CHECKSEC_VERSION=2.7.1 # ignore
127+
RUN url="https://raw.githubusercontent.com/slimm609/checksec/${CHECKSEC_VERSION}/checksec" ; \
128128
scurl -o /usr/local/bin/checksec "$url" && chmod 755 /usr/local/bin/checksec
129129

130130
# shellcheck lints shell scripts.
@@ -161,9 +161,9 @@ RUN url="https://github.com/google/protobuf/releases/download/$PROTOC_VERSION/pr
161161

162162
# cargo-action-fmt formats `cargo build` JSON output to Github Actions annotations.
163163
FROM apt-base as cargo-action-fmt
164-
ARG CARGO_ACTION_FMT_VERSION=v2.0.1 # repo=olix0r/cargo-action-fmt
165-
RUN url="https://github.com/olix0r/cargo-action-fmt/releases/download/release%2Fv${CARGO_ACTION_FMT_VERSION}/cargo-action-fmt-x86_64-unknown-linux-gnu" ; \
166-
scurl -o /usr/local/bin/cargo-action-fmt "$url" && chmod +x /usr/local/bin/cargo-action-fmt
164+
ARG CARGO_ACTION_FMT_VERSION=v1.0.4 # ignore
165+
RUN url="https://github.com/olix0r/cargo-action-fmt/releases/download/release%2F${CARGO_ACTION_FMT_VERSION}/cargo-action-fmt-${CARGO_ACTION_FMT_VERSION}-x86_64-unknown-linux-musl.tar.gz" ; \
166+
scurl "$url" | tar zvxf - -C /usr/local/bin cargo-action-fmt
167167

168168
# cargo-deny checks cargo dependencies for licensing and RUSTSEC security issues.
169169
FROM apt-base as cargo-deny
@@ -173,7 +173,7 @@ RUN url="https://github.com/EmbarkStudios/cargo-deny/releases/download/${CARGO_D
173173

174174
# cargo-nextest is a nicer test runner.
175175
FROM apt-base as cargo-nextest
176-
ARG NEXTEST_VERSION=cargo-nextest-0.9.99 # repo=nextest-rs/nextest
176+
ARG NEXTEST_VERSION=0.9.99 # repo=nextest-rs/nextest,prefix=cargo-nextest-
177177
RUN url="https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-${NEXTEST_VERSION}/cargo-nextest-${NEXTEST_VERSION}-x86_64-unknown-linux-gnu.tar.gz" ; \
178178
scurl "$url" | tar zvxf - -C /usr/local/bin cargo-nextest
179179

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ sync-k3s-images:
7575

7676
minimum-k8s := '20'
7777

78+
update-versions:
79+
go run ./update-versions.go --in-place
80+
7881
# Inspect a k3s image by tag
7982
_k3s-inspect tag:
8083
skopeo inspect 'docker://{{ k3s-image }}:{{ tag }}'

repos/linkerd2-proxy

Submodule linkerd2-proxy updated 339 files

update-versions.go

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const (
3333
httpTimeout = 10 * time.Second
3434
goDLIndexURL = "https://go.dev/dl/?mode=json"
3535
userAgent = "update-versions/1.0 (+https://github.com/linkerd/dev)"
36-
commentRepo = "repo="
3736
)
3837

3938
var (
@@ -132,6 +131,47 @@ func latestRustMinorVersion(ctx context.Context) (string, error) {
132131
return parts[0] + "." + parts[1], nil
133132
}
134133

134+
// parseHints extracts repo and prefix hints from a comment suffix like "# repo=owner/repo,prefix=xyz-"
135+
func parseHints(suffix string) (repo, prefix string) {
136+
s := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(suffix), "#"))
137+
for _, part := range strings.Split(s, ",") {
138+
kv := strings.SplitN(strings.TrimSpace(part), "=", 2)
139+
log.Printf("Parsing hint: %q -> %v", part, kv)
140+
if len(kv) != 2 {
141+
continue
142+
}
143+
switch kv[0] {
144+
case "repo":
145+
repo = kv[1]
146+
case "prefix":
147+
prefix = kv[1]
148+
}
149+
}
150+
return
151+
}
152+
153+
// latestGitHubTagWithPrefix lists releases and returns the first tag without the given prefix
154+
func latestGitHubTagWithPrefix(ctx context.Context, repo, prefix string) (string, error) {
155+
// fetch up to 100 releases and skip prereleases
156+
var releases []struct {
157+
TagName string `json:"tag_name"`
158+
Prerelease bool `json:"prerelease"`
159+
}
160+
url := fmt.Sprintf("https://api.github.com/repos/%s/releases?per_page=100", repo)
161+
if err := httpGetJSON(ctx, url, githubToken, &releases); err != nil {
162+
return "", err
163+
}
164+
for _, r := range releases {
165+
if r.Prerelease {
166+
continue
167+
}
168+
if strings.HasPrefix(r.TagName, prefix) {
169+
return strings.TrimPrefix(r.TagName, prefix), nil
170+
}
171+
}
172+
return "", fmt.Errorf("no release found for %q with prefix %q", repo, prefix)
173+
}
174+
135175
// ----------------------------------------------------------------------------
136176
// ARG line updater
137177
// ----------------------------------------------------------------------------
@@ -142,38 +182,29 @@ func updateARG(ctx context.Context, line string) (newLine string, changed bool,
142182
return line, false, nil
143183
}
144184

145-
prefix, name, curVal, suffix := m[1], m[2], m[3], m[4]
146-
repoHint := extractRepoHint(suffix)
185+
prefixIndent, name, curVal, suffix := m[1], m[2], m[3], m[4]
186+
repoHint, prefixHint := parseHints(suffix)
147187

148188
var newVal string
149-
switch name {
150-
case "GO_TAG":
189+
switch {
190+
case prefixHint != "" && repoHint != "":
191+
newVal, err = latestGitHubTagWithPrefix(ctx, repoHint, prefixHint)
192+
case name == "GO_TAG":
151193
newVal, err = latestGoMinorVersion(ctx)
152-
case "RUST_TAG":
194+
case name == "RUST_TAG":
153195
newVal, err = latestRustMinorVersion(ctx)
154-
default:
155-
if repoHint == "" {
156-
return line, false, nil
157-
}
196+
case repoHint != "":
158197
newVal, err = latestGitHubTag(ctx, repoHint)
198+
default:
199+
return line, false, nil
159200
}
160201
if err != nil {
161202
return "", false, err
162203
}
163204
if newVal == curVal {
164205
return line, false, nil
165206
}
166-
return fmt.Sprintf("%s%s=%s%s\n", prefix, name, newVal, suffix), true, nil
167-
}
168-
169-
func extractRepoHint(comment string) string {
170-
if idx := strings.Index(comment, "#"); idx >= 0 {
171-
comment = comment[idx+1:]
172-
if pos := strings.Index(comment, commentRepo); pos >= 0 {
173-
return strings.Fields(comment[pos+len(commentRepo):])[0]
174-
}
175-
}
176-
return ""
207+
return fmt.Sprintf("%s%s=%s%s\n", prefixIndent, name, newVal, suffix), true, nil
177208
}
178209

179210
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)