Skip to content

Dynamically place go version in README #21

@MSevey

Description

@MSevey

From chatgpt

Yes, you can dynamically pull the Go version from a go.mod file and display it in your README.md file by using a simple script that reads the version from go.mod and updates README.md. Here’s a basic example using a shell script to automate this.

1. Create a Shell Script

Create a script, for example, called update-readme.sh:

#!/bin/bash

# Extract the Go version from go.mod
GO_VERSION=$(grep '^go ' go.mod | awk '{print $2}')

# Update README.md by replacing the placeholder or existing Go version
sed -i "" -e "s/Go Version: .*/Go Version: $GO_VERSION/" README.md

This script:

  • Reads the Go version from go.mod.
  • Updates README.md by finding a line containing "Go Version:" and replacing it with the current Go version.

2. Use a Placeholder in README.md

In your README.md, set up a placeholder like this:

# Project Title

This project uses:

- **Go Version:** [dynamically set here]

Run the script to replace [dynamically set here] with the actual version.

3. Automate the Update

To keep this up-to-date, you can add the script as a part of your build or CI pipeline, or run it manually whenever you update go.mod.

Let me know if you’d like to automate this further!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions