AutomatedGo

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: GPL-3.0 Imports: 0 Imported by: 0

README

AutomatedGo🐿️

Release Code Coverage Go Report Card GitHub go.mod Go version GitHub Release codecov Go Reference GitHub License Visitor Badge

AutomatedGo is a Go tool that automates the process of checking and updating Go versions in your projects. It can detect the current Go version from various file types, compare it with the latest available version, and download the newest version if an update is available.

Features

  • Detect current Go version from various file types (Dockerfile, go.mod, JSON configs, etc.)
  • Check for the latest available Go version
  • Download the latest Go version if an update is available
  • Checksum validation for downloaded Go versions to ensure integrity
  • Support for different operating systems and architectures

Installation

To install AutomatedGo, use the following command:

go get -u github.com/Nicconike/AutomatedGo

Usage

Basic Usage
AutomatedGo -file <path-to-file> -os <target-os> -arch <target-arch>

This will check the specified file for the current Go version, compare it with the latest available version, and download the new version if an update is available.

[!NOTE] If you don't specify the os and arch type, the tool will download the latest version for your current operating system and architecture.

Minimum required Go version: 1.15

Command-line Options
  • -file or -f: Path to the file containing the current Go version
  • -version or -v: Directly specify the current Go version
  • -os: Target operating system (windows, linux, macOS[darwin])
  • -arch: Target architecture (386[x86], amd64[x86-64], arm64, armv6l[armv6])
Examples
  1. Get version from a Dockerfile:

    AutomatedGo -f Dockerfile
    

    Dockerfile Example

  2. Get version from go.mod:

    AutomatedGo -f go.mod
    

    Go Mod Example

  3. Specify version directly:

    AutomatedGo -v 1.17
    

    Direct Example

  4. Download for a specific OS and architecture:

    AutomatedGo -f version.json -os linux -arch arm64
    

    JSON Example with OS

Also, checkout a real example in the test-AutomatedGo repository where this tool is used to check and update the Go version. And then upload the downloaded Go version to Github using Git LFS.

Supported File Types

AutomatedGo can extract Go versions from various file types, including:

  • Dockerfile
  • go.mod
  • JSON configuration files
  • Plain text files with version information

The tool uses various regex patterns to detect Go versions, making it flexible for different project setups.

Missing any file types you expected to see? Let me know via discussions or discord server.

Contributing

Star⭐ and Fork🍴 the Repo to start with your feature request(or bug) and experiment with the project to implement whatever Idea you might have and sent the Pull Request through 🤙

Please refer Contributing.md to get to know how to contribute to this project. And thank you for considering to contribute.

License

GPLv3 License

Documentation

Overview

Package AutomatedGo provides tools for automating Go version checks and downloads.

Features:

  • Detect current Go version from various file types (Dockerfile, go.mod, JSON configs, etc.)
  • Check for the latest available Go version
  • Download the latest Go version if an update is available
  • Support for different operating systems and architectures
  • Checksum validation for downloaded Go versions to ensure integrity

Do's:

  1. Always check for errors returned by functions in this package.
  2. Use GetLatestVersion() to fetch the most recent Go version information.
  3. Specify the correct target OS and architecture when using DownloadGo().
  4. Ensure you have necessary permissions to download and write files.
  5. Define Go version in your project files using one of these formats: - In go.mod: go 1.x - In Dockerfile: * FROM golang:1.x.x * ENV GO_VERSION=1.x.x - In other files: * go_version = "1.x.x" * GO_VERSION: 1.x.x * golang_version: "1.x.x"
  6. Use the package to automate version checks in your CI/CD pipelines.
  7. Verify checksums of downloaded Go versions for security.

Don'ts:

  1. Don't assume the latest version is always compatible with your project.
  2. Avoid using this package to modify your system's Go installation directly.
  3. Don't use this package in production environments without thorough testing.
  4. Don't ignore version constraints specified in your go.mod file.
  5. Avoid manually modifying files downloaded by this package.
  6. Don't use non-standard formats for specifying Go versions in your project files.

Example usage:

// Get the latest Go version
latestVersion, err := pkg.GetLatestVersion()
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Latest Go version: %s\n", latestVersion)

// Get current version from a file
currentVersion, err := pkg.GetCurrentVersion("go.mod", "")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Current Go version: %s\n", currentVersion)

// Check if update is needed
if pkg.IsNewer(latestVersion, currentVersion) {
    fmt.Println("An update is available")

    // Download the latest Go version
    err = pkg.DownloadGo(latestVersion, "linux", "amd64")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Successfully downloaded new Go version")

    // Verify checksum
    filename := fmt.Sprintf("go%s.linux-amd64.tar.gz", latestVersion)
    checksum, err := pkg.CalculateFileChecksum(filename)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Checksum of downloaded file: %s\n", checksum)
} else {
    fmt.Println("You have the latest version")
}

Functions:

  • GetLatestVersion() (string, error) Fetches the latest available Go version.

  • GetCurrentVersion(filename, version string) (string, error) Detects the current Go version from a file or uses the provided version.

  • IsNewer(version1, version2 string) bool Compares two version strings and returns true if version1 is newer.

  • DownloadGo(version, targetOS, arch string) error Downloads the specified Go version for the given OS and architecture.

  • CalculateFileChecksum(filename string) (string, error) Calculates the SHA256 checksum of the specified file.

For more detailed information and advanced usage, refer to the README.md file and the package documentation at https://pkg.go.dev/github.com/Nicconike/AutomatedGo.

Directories

Path Synopsis
cmd
automatedgo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL