From 0382775b50c17dc13e51875f603c42785f9939cb Mon Sep 17 00:00:00 2001 From: Roemer Date: Mon, 5 Jan 2026 16:06:40 +0000 Subject: [PATCH] feat: Aded gonovate feature --- .github/workflows/ci.yml | 1 + README.md | 1 + build/build.go | 11 +++ features/src/gonovate/README.md | 21 ++++ .../src/gonovate/devcontainer-feature.json | 26 +++++ features/src/gonovate/install.sh | 5 + features/src/gonovate/installer.go | 96 +++++++++++++++++++ features/test/gonovate/install.sh | 8 ++ features/test/gonovate/scenarios.json | 15 +++ features/test/gonovate/test-images.json | 6 ++ override-all.env | 3 + 11 files changed, 193 insertions(+) create mode 100755 features/src/gonovate/README.md create mode 100644 features/src/gonovate/devcontainer-feature.json create mode 100755 features/src/gonovate/install.sh create mode 100644 features/src/gonovate/installer.go create mode 100755 features/test/gonovate/install.sh create mode 100644 features/test/gonovate/scenarios.json create mode 100644 features/test/gonovate/test-images.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ea7dab..b6b4379 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: "git-lfs", "gitlab-cli", "go", + "gonovate", "goreleaser", "instant-client", "jfrog-cli", diff --git a/README.md b/README.md index e2ab4da..db04229 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Below is a list with included features, click on the link for more details. | [git-lfs](./features/src/git-lfs/README.md) | Installs Git LFS. | | [gitlab-cli](./features/src/gitlab-cli/README.md) | Installs the GitLab CLI. | | [go](./features/src/go/README.md) | Installs Go. | +| [gonovate](./features/src/gonovate/README.md) | Installs Gonovate. | | [goreleaser](./features/src/goreleaser/README.md) | Installs GoReleaser. | | [instant-client](./features/src/instant-client/README.md) | Installs the Oracle Instant Client Basic package. | | [jfrog-cli](./features/src/jfrog-cli/README.md) | Installs the JFrog CLI. | diff --git a/build/build.go b/build/build.go index ab35c6c..67bdf62 100644 --- a/build/build.go +++ b/build/build.go @@ -168,6 +168,17 @@ func init() { return publishFeature("go") }) + ////////// gonovate + gotaskr.Task("Feature:gonovate:Package", func() error { + return packageFeature("gonovate") + }) + gotaskr.Task("Feature:gonovate:Test", func() error { + return testFeature("gonovate") + }) + gotaskr.Task("Feature:gonovate:Publish", func() error { + return publishFeature("gonovate") + }) + ////////// goreleaser gotaskr.Task("Feature:goreleaser:Package", func() error { return packageFeature("goreleaser") diff --git a/features/src/gonovate/README.md b/features/src/gonovate/README.md new file mode 100755 index 0000000..5b7e323 --- /dev/null +++ b/features/src/gonovate/README.md @@ -0,0 +1,21 @@ +# Gonovate (gonovate) + +Installs Gonovate. + +## Example Usage + +```json +"features": { + "ghcr.io/postfinance/devcontainer-features/gonovate:0.1.0": { + "version": "latest", + "downloadUrl": "" + } +} +``` + +## Options + +| Option | Description | Type | Default Value | Proposals | +|-----|-----|-----|-----|-----| +| version | The version of Gonovate to install. | string | latest | latest, 0.6.6, 0.5 | +| downloadUrl | The download URL to use for Gonovate binaries. | string | <empty> | https://mycompany.com/artifactory/github-releases-remote | diff --git a/features/src/gonovate/devcontainer-feature.json b/features/src/gonovate/devcontainer-feature.json new file mode 100644 index 0000000..a2fc7fa --- /dev/null +++ b/features/src/gonovate/devcontainer-feature.json @@ -0,0 +1,26 @@ +{ + "id": "gonovate", + "version": "0.1.0", + "name": "Gonovate", + "description": "Installs Gonovate.", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest", + "0.6.6", + "0.5" + ], + "default": "latest", + "description": "The version of Gonovate to install." + }, + "downloadUrl": { + "type": "string", + "default": "", + "proposals": [ + "https://mycompany.com/artifactory/github-releases-remote" + ], + "description": "The download URL to use for Gonovate binaries." + } + } +} \ No newline at end of file diff --git a/features/src/gonovate/install.sh b/features/src/gonovate/install.sh new file mode 100755 index 0000000..13b2b54 --- /dev/null +++ b/features/src/gonovate/install.sh @@ -0,0 +1,5 @@ +. ./functions.sh + +"./installer_$(detect_arch)" \ + -version="${VERSION:-"latest"}" \ + -downloadUrl="${DOWNLOADURL:-""}" diff --git a/features/src/gonovate/installer.go b/features/src/gonovate/installer.go new file mode 100644 index 0000000..321dc98 --- /dev/null +++ b/features/src/gonovate/installer.go @@ -0,0 +1,96 @@ +package main + +import ( + "builder/installer" + "flag" + "fmt" + "os" + "regexp" + + "github.com/roemer/gover" +) + +////////// +// Configuration +////////// + +var versionRegex *regexp.Regexp = regexp.MustCompile(`(?m:)^v(?P(\d+).(\d+)\.(\d+))$`) + +////////// +// Main +////////// + +func main() { + if err := runMain(); err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(1) + } +} + +func runMain() error { + // Handle the flags + version := flag.String("version", "latest", "") + downloadUrl := flag.String("downloadUrl", "", "") + flag.Parse() + + // Load settings from an external file + if err := installer.LoadOverrides(); err != nil { + return err + } + + // Apply override logic for URLs + installer.HandleGitHubOverride(downloadUrl, "roemer/gonovate", "gonovate-download-url") + + // Create and process the feature + feature := installer.NewFeature("Gonovate", true, + &gonovateComponent{ + ComponentBase: installer.NewComponentBase("Gonovate", *version), + DownloadUrl: *downloadUrl, + }) + return feature.Process() +} + +////////// +// Implementation +////////// + +type gonovateComponent struct { + *installer.ComponentBase + DownloadUrl string +} + +func (c *gonovateComponent) GetAllVersions() ([]*gover.Version, error) { + tags, err := installer.Tools.GitHub.GetTags("roemer", "gonovate") + if err != nil { + return nil, err + } + return installer.Tools.Versioning.ParseVersionsFromList(tags, versionRegex, true) +} + +func (c *gonovateComponent) InstallVersion(version *gover.Version) error { + archPart, err := installer.Tools.System.MapArchitecture(map[string]string{ + installer.AMD64: "amd64", + installer.ARM64: "arm64", + }) + if err != nil { + return err + } + // Download the file + fileName := fmt.Sprintf("gonovate-linux-%s-%s.zip", version.Raw, archPart) + downloadUrl, err := installer.Tools.Http.BuildUrl(c.DownloadUrl, "v"+version.Raw, fileName) + if err != nil { + return err + } + if err := installer.Tools.Download.ToFile(downloadUrl, fileName, "gonovate"); err != nil { + return err + } + // Extract it + if err := installer.Tools.Compression.ExtractZip(fileName, "/usr/local/bin/", false); err != nil { + return err + } + // Cleanup + if err := os.Remove(fileName); err != nil { + return err + } + return nil +} diff --git a/features/test/gonovate/install.sh b/features/test/gonovate/install.sh new file mode 100755 index 0000000..2c2131a --- /dev/null +++ b/features/test/gonovate/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +[[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh" +[[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh" + +check_file_exists "/usr/local/bin/gonovate" +check_version "$(gonovate 2>&1 | head -n 1)" "gonovate v0.10.5" diff --git a/features/test/gonovate/scenarios.json b/features/test/gonovate/scenarios.json new file mode 100644 index 0000000..350f295 --- /dev/null +++ b/features/test/gonovate/scenarios.json @@ -0,0 +1,15 @@ +{ + "install": { + "build": { + "dockerfile": "Dockerfile", + "options": [ + "--add-host=host.docker.internal:host-gateway" + ] + }, + "features": { + "./gonovate": { + "version": "0.10.5" + } + } + } +} \ No newline at end of file diff --git a/features/test/gonovate/test-images.json b/features/test/gonovate/test-images.json new file mode 100644 index 0000000..f4cf196 --- /dev/null +++ b/features/test/gonovate/test-images.json @@ -0,0 +1,6 @@ +[ + "mcr.microsoft.com/devcontainers/base:debian-11", + "mcr.microsoft.com/devcontainers/base:debian-12", + "mcr.microsoft.com/devcontainers/base:alpine", + "mcr.microsoft.com/devcontainers/base:ubuntu-24.04" +] \ No newline at end of file diff --git a/override-all.env b/override-all.env index f529a22..5147bb4 100644 --- a/override-all.env +++ b/override-all.env @@ -31,6 +31,9 @@ GO_DOWNLOAD_URL="" GO_LATEST_URL="" GO_VERSIONS_URL="" +# gonovate +GONOVATE_DOWNLOAD_URL="" + # goreleaser GORELEASER_DOWNLOAD_URL=""