semver

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: MIT Imports: 5 Imported by: 0

README

Semver

release github

pipeline status Build Status

A Go package to deal with semantic versions as defined at https://semver.org.

Usage

Importing
import "github.com/usvc/semver"
Parsing a semantic version string
semver.Parse("1.0.0-alpha.1+202022022637")
Retrieving semantic version as a string
// setting up fictitious semantic version
version := Semver{
  Prefix: "v",
  VersionCore: semver.VersionCore{
    Major: 1,
    Minor: 2,
    Patch: 3,
  },
  PreRelease: semver.PreRelease{
    "alpha", "1",
  },
  BuildMetadata: semver.BuildMetadata{
    "202022022637",
  },
}

// the magic follows
fmt.Println(version.String())
// v1.2.3-alpha.1+202022022637
Sorting semantic versions
stringVersions := []string{"1.2.1", "3.1.0", "2.0.0", "1.0.0", "2.0.0-alpha"}
semverVersions := semver.Semvers{}
for i := 0; i < len(stringVersions); i++ {
  semverVersion, _ := semver.Parse(stringVersions[i])
  semverVersions = append(semverVersions, *semverVersion)
}
sort.Sort(semverVersions)
for i := 0; i < len(semverVersions); i++ {
  fmt.Println(semverVersions[i].String())
}
// 1.0.0
// 1.2.1
// 2.0.0-alpha
// 2.0.0
// 3.1.0

Development Runbook

Getting Started
  1. Clone this repository
  2. Run make deps to pull in external dependencies
  3. Write some awesome stuff
  4. Run make test to ensure unit tests are passing
  5. Push
Continuous Integration (CI) Pipeline
On Github

Github is used to deploy binaries/libraries because of it's ease of access by other developers.

Releasing

Releasing of the binaries can be done via Travis CI.

  1. On Github, navigate to the tokens settings page (by clicking on your profile picture, selecting Settings, selecting Developer settings on the left navigation menu, then Personal Access Tokens again on the left navigation menu)
  2. Click on Generate new token, give the token an appropriate name and check the checkbox on public_repo within the repo header
  3. Copy the generated token
  4. Navigate to travis-ci.org and access the cooresponding repository there. Click on the More options button on the top right of the repository page and select Settings
  5. Scroll down to the section on Environment Variables and enter in a new NAME with RELEASE_TOKEN and the VALUE field cooresponding to the generated personal access token, and hit Add
On Gitlab

Gitlab is used to run tests and ensure that builds run correctly.

Version Bumping
  1. Run make .ssh
  2. Copy the contents of the file generated at ./.ssh/id_rsa.base64 into an environment variable named DEPLOY_KEY in Settings > CI/CD > Variables
  3. Navigate to the Deploy Keys section of the Settings > Repository > Deploy Keys and paste in the contents of the file generated at ./.ssh/id_rsa.pub with the Write access allowed checkbox enabled
  • DEPLOY_KEY: generate this by running make .ssh and copying the contents of the file generated at ./.ssh/id_rsa.base64
DockerHub Publishing
  1. Login to https://hub.docker.com, or if you're using your own private one, log into yours
  2. Navigate to your security settings at the /settings/security endpoint
  3. Click on Create Access Token, type in a name for the new token, and click on Create
  4. Copy the generated token that will be displayed on the screen
  5. Enter the following varialbes into the CI/CD Variables page at Settings > CI/CD > Variables in your Gitlab repository:
  • DOCKER_REGISTRY_URL: The hostname of the Docker registry (defaults to docker.io if not specified)
  • DOCKER_REGISTRY_USERNAME: The username you used to login to the Docker registry
  • DOCKER_REGISTRY_PASSWORD: The generated access token

Licensing

Code in this package is licensed under the MIT license (click to see full text))

Documentation

Index

Constants

View Source
const (
	// RegexpWithCaptureGroup is a string regular expression that
	// also captures the capture groups [
	// 	Prefix,
	// 	Major,
	// 	Minor,
	// 	Patch,
	// 	PreRelease,
	// 	BuildMetadata,
	// ]. this expression is a modified form from https://semver.org
	RegexpWithCaptureGroup = `` /* 258-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func IsValid

func IsValid(semver string) bool

IsValid checks whether the provided :semver matches the semver grammar specification

Types

type BuildMetadata

type BuildMetadata []string

BuildMetadata stores the `build-metadata` section of a semantic version that's appended after a plus sign ('+')

func (BuildMetadata) String

func (bm BuildMetadata) String() string

String returns a string representation of the build metadata

type PreRelease

type PreRelease []string

PreRelease defines the pre-release label often appended after a hypen ('-') in a semantic version

func (PreRelease) String

func (pr PreRelease) String() string

String returns the string representation of the pre- release label

type PreReleases

type PreReleases []PreRelease

PreReleases is a sortable slice of PreRelease structures

func (PreReleases) Len

func (prs PreReleases) Len() int

Len implements sort.Interface's Len()

func (PreReleases) Less

func (prs PreReleases) Less(i, j int) bool

Less implements sort.Interface's Less()

func (PreReleases) Swap

func (prs PreReleases) Swap(i, j int)

Swap implements sort.Interface's Swap()

type Semver

type Semver struct {
	Prefix        string        `json:"prefix"`
	VersionCore   VersionCore   `json:"version_core"`
	PreRelease    PreRelease    `json:"pre_release"`
	BuildMetadata BuildMetadata `json:"build_metadata"`
}

Semver stores information about a semantic version as defined at https://semver.org

func Parse

func Parse(semver string) *Semver

Parse receives a string and returns a Semver instance that represents the semantic version

func (*Semver) BumpMajor

func (semver *Semver) BumpMajor()

BumpMajor bumps the major version

func (*Semver) BumpMinor

func (semver *Semver) BumpMinor()

BumpMinor bumps the minor version

func (*Semver) BumpPatch

func (semver *Semver) BumpPatch()

BumpPatch bumps the patch version

func (*Semver) BumpPreRelease

func (semver *Semver) BumpPreRelease() error

BumpPreRelease bumps the pre-release version if applicable, if pre-release does not have a numerical version, returns an error

func (*Semver) SetBuildMetadata

func (semver *Semver) SetBuildMetadata(labels ...string)

SetBuildMetadata sets the build-metadata section of the semantic version

func (*Semver) SetPreRelease

func (semver *Semver) SetPreRelease(labels ...string)

SetPreRelease sets the pre-release section of the semantic version

func (Semver) String

func (semver Semver) String() string

String returns the string representation of this instance of the Semver struct

type Semvers

type Semvers []*Semver

Semvers is a slice of Semver structures with sorting capabilities

func (Semvers) Len

func (semvers Semvers) Len() int

Len implements sort.Interface's Len()

func (Semvers) Less

func (semvers Semvers) Less(i, j int) bool

Less implements sort.Interface's Less()

func (Semvers) Swap

func (semvers Semvers) Swap(i, j int)

Swap implements sort.Interface's Swap()

type VersionCore

type VersionCore struct {
	Major uint `json:"major"`
	Minor uint `json:"minor"`
	Patch uint `json:"patch"`
}

VersionCore represents the major, minor, and patch versions section of a semantic version

func (VersionCore) String

func (vc VersionCore) String() string

String returns the string representation of the VersionCore structure

type VersionCores

type VersionCores []VersionCore

VersionCores is a sortable slice of VersionCore structures

func (VersionCores) Len

func (vcs VersionCores) Len() int

Len implements sort.Interface's Len()

func (VersionCores) Less

func (vcs VersionCores) Less(i, j int) bool

Less implements sort.Interface's Less()

func (VersionCores) Swap

func (vcs VersionCores) Swap(i, j int)

Swap implements sort.Interface's Swap()

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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