Git Product home page Git Product logo

go-semantic-release's Introduction

go-semantic-release

go-semantic-release

Release Types

Type Implemented Git tag Changelog Release Write access git Api token
github
gitlab
git
bitbucket Comming soon

Supported CI Pipelines

  • Github Actions
  • Gitlab CI
  • Travis CI
  • Custom CI, set enviroment CI=true

Download

You can download the newest version under releases

or

you can use a Docker image

docker pull nightapes/go-semantic-release:<VERSION> or docker pull docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:<VERSION>

How to use

go-semantic-release config file Create a file with the name .release.yml or anything else, but you need to set to every command -c <your config file>

Example config

commitFormat: angular
branch:
  master: release
release: 'github'
github:
  repo: "go-semantic-release"
  user: "nightapes"
assets:
  - name: ./build/go-semantic-release
    compress: false
  - name: ./build/go-semantic-release.exe
    compress: false
hooks:
  preRelease:
    - name: echo $RELEASE_VERSION
  postRelease:
    - name: echo $RELEASE_VERSION
integrations:
  npm:
    enabled: true

CommitFormat

Supported formats:

Branch

You can define which kind of release should be created for different branches.

Supported release kinds:

  • release -> v1.0.0
  • rc -> v1.0.0-rc.0
  • beta -> v1.0.0-beta.0
  • alpha -> v1.0.0-alpha.0

Add a branch config to your config

branch:
  <branch-name>: <kind>

Release

At the moment we support releases to gitlab and github.

Github

You need to set the env GITHUB_TOKEN with an access token.

release: 'github'
github:
  user: "<user/group"
  repo: "<repositroyname>"
  ## Optional, if you are not using github.com
  customUrl: <https://your.github>
  ## Optional, if you want to change the default tag prefix ("v")
  tagPrefix: ""
Gitlab

You need to set the env GITLAB_ACCESS_TOKEN with an personal access token.

release: 'gitlab'
gitlab:
  repo: "<repositroyname>"  ## Example group/project
  ## Optional, if your not using gitlab.com
  customUrl: <https://your.gitlab>
  ## Optional, if you want to change the default tag prefix ("v")
  tagPrefix: ""

You can find an example .gitlab-ci.yml in the examples folder.

Git only

Only via https at the moment. You need write access to your git repository

release: 'git'
git:
  email: "<email>" # Used for creating tag
  user: "<user>" : # Used for creating tag and pushing
  auth: "<token>" # Used for pushing, can be env "$GIT_TOKEN", will be replaced with env
  ## Optional, if you want to change the default tag prefix ("v")
  tagPrefix: ""

Assets

You can upload assets to a release

Support for gitlab and github. If you want, you can let the file be compressed before uploading

assets:
  - name: ./build/go-semantic-release
    compress: false

Hooks

Hooks will run when calling release. Hooks run only if a release will be triggered. You can define hooks which run before or after the release. The shell commands will run in order, you can access the current release version via an environment variable RELEASE_VERSION

hooks:
  preRelease:
  - name: echo $RELEASE_VERSION
  postRelease:
  - name: echo $RELEASE_VERSION

Integrations

Integrations are simple helpers to make integration with existing tools easier. At the moment npm is supported, the integration will set the version before release to the package.json

integrations:
  npm:
    enabled: true

Changelog

Following variables and objects can be used for templates:

Top level

Field Type Description
Commits string Fully rendered commit messages. This is left for backward compatibility.
CommitsContent commitsContent Raw parsed commit data. Use this if you want to customize the output.
Version string Next release version
Now time.Time Current time of generating changelog
Backtick string Backtick character
HasDocker bool If a docker repository is set in the config.
HasDockerLatest bool If latest image was uploaded
DockerRepository string Docker repository

commitsContent

Field Type Description
Commits map[string][]AnalyzedCommit Commits grouped by commit type
BreakingChanges []AnalyzedCommit Analyzed commit structure
Order []string Ordered list of types
HasURL bool If a URL is available for commits
URL string URL for to the commit with {{hash}} suffix

AnalyzedCommit

Field Type Description
Commit Commit Original GIT commit
Tag string Type of commit (e.g. feat, fix, ...)
TagString string Full name of the type
Scope bool Scope value from the commit
Subject string URL for to the commit with {{hash}} suffix
MessageBlocks map[string][]MessageBlock Different sections of a message (e.g. body, footer etc.)
IsBreaking bool If this commit contains a breaking change
Print bool Should this commit be included in Changelog output

Commit

Field Type Description
Message string Original git commit message
Author string Name of the author
Hash string Commit hash value "

MessageBlock

Field Type Description
Label string Label for a block (optional). This will usually be a token used in a footer
Content string The parsed content of a block
changelog:
  printAll: false ## Print all valid commits to changelog
  title: "v{{.Version}} ({{.Now.Format "2006-01-02"}})" ## Used for releases (go template)
  templatePath: "./examples/changelog.tmpl"    ## Path to a template file (go template)
  showAuthors: false  ## Show authors in changelog
  showBodyAsHeader: false  ## Show all bodies of the commits as header of changelog (useful for squash commit flow to show long text in release)
Docker

You can print a help text for a docker image

changelog:
  docker: 
    latest: false ## If you uploaded a latest image
    repository: ## Your docker repository, which is used for docker run
NPM

You can print a help text for a npm package

changelog:
  npm:
    name: ## Name of the npm package
    repository: ## Your docker repository, which is used for docker run

Version

go-semantic-release has two modes for calculating the version: automatic or manual.

Automatic

Version will be calculated on the next or release command

Manual

If you don't want that go-semantic-release is calculating the version from the commits, you can set the version by hand with following command:

./go-semantic-release set 1.1.1

Print version

Print the next version, can be used to add version to your program

./go-semantic-release next // show next version (calculated by new commits since last version)
./go-semantic-release last // show last released version 

Example with go-lang

go build -ldflags "--X main.version=`./go-semantic-release next`"

Create release

./go-semantic-release release 

Write changelog to file

This will write all changes beginning from the last git tag til HEAD to a changelog file. Default changelog file name if nothing is given via --file: CHANGELOG.md. Note that per default the new changelog will be prepended to the existing file. With --max-file-size a maximum sizes of the changelog file in megabytes can be specified. If the size exceeds the limit, the current changelog file will be moved to a new file called <filename>-<1-n>.<file extension>. The new changelog will be written to the <filename>. The default maximum file size limit is 10 megabytes.

./go-semantic-release changelog --max-file-size 10

This will overwrite the given changelog file if its existing, if not it will be created.

./go-semantic-release changelog --overwrite

Build from source

go build ./cmd/go-semantic-release/

Testing

go test ./... 

Linting

curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
golangci-lint run ./...

go-semantic-release's People

Contributors

dearchap avatar ferencovonmatterhorn avatar fwiedmann avatar maulik13 avatar nightapes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-semantic-release's Issues

Allow rendering of full changelog using the TemplatePath parameter

At the moment file specified by the TemplatePath variable only renders the wrapping text for the changelog. The commit list cannot be customized. It would be great to have this file be used for rendering of the full changelog for a given version including the commit list.

I have also attached a PR. I have made sure the old fields are still there so that current templates do not break. Please have a look.

Detecting breaking changes in analyzers diverges from conventions

While working on modifying analyzers for storing a structured message, I found out that there is a test case in changelog (LINK) where the commit message is:

feat: my new commit 

my first break: BREAKING CHANGE: change api to v2

According to the conventions (both angular and conventionalcommit) this will not be recognized as a breaking change. But in the current code this is identified as a breaking change. While this gives flexibility it diverges from the convention. Are you guys ok with fixing this behavior?

Follow the commit structure with subject, body, footer in the parsed commit message

At the moment, analyzer only parses the message in to two fields ParsedMessage and ParsedBreakingChangeMessage. Commit messages with a body and a footer are then not rendered nicely in the changelog. If the commit analyzer would parse the messages to follow the commit structure (see blow) and populate the fields (type, subject, body, footer) that would make it much easier to render them in a changelog. The subject line will always be used as a bullet point and body/footer can be rendered as a sub point or a note.

Both conventional commits and angular project define the following structure for the commit messages.

<type>(<scope>): <subject>

<body>

<footer>

Creates no release when merges merge requests

Hi,

when i create a merge request and merge this, then no new release is created.

feature-branch-commits:
fix(*): fixed ...

development-commits after merge:
Merge feature-branch-commits into development.


Creates no release.
direct commit to development with message fix(*): fixed... 

creates release

Expected:

Commit Message "Merge feature-branch-commits into development" should create an release.

If no fix/feat commit is in commit list, create default release message

version 1.10.2 is broken: invalid memory address or nil pointer dereference

.release content:

commitFormat: "angular"
branch:
  master: "release"
  develop: "rc"
release: "gitlab"
gitlab:
  repo: PROJECT-GROUP/sub-project-group/repository-name
  customUrl: https://git.my.org/
  tagPrefix: ""

build string:

$ CGO_ENABLED=0 go build -ldflags="-s -w" -a -installsuffix cgo -o build/go-semantic-release ./cmd/go-semantic-release/

comand to check:

$ ./go-semantic-release next

expected result:

$ ./go-semantic-release next
1.0.1-rc.0

actual result:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x14ff0da]

goroutine 1 [running]:
github.com/go-git/go-git/v5/plumbing.(*Reference).Hash(...)
	/Users/redacted/go/pkg/mod/github.com/go-git/go-git/[email protected]/plumbing/reference.go:183
github.com/Nightapes/go-semantic-release/internal/gitutil.(*GitUtil).GetCommits(0xc0000ba680, 0x0, 0x175cf3f, 0x31, 0xc0000ebb00, 0x1, 0x1)
	/Users/redacted/tmp/go-semantic-release-1.10.2/internal/gitutil/gitutil.go:126 +0x3a
github.com/Nightapes/go-semantic-release/pkg/semanticrelease.(*SemanticRelease).GetNextVersion(0xc0000d8820, 0xc00011c750, 0x0, 0x0, 0xc0000d8820, 0x0)
	/Users/redacted/tmp/go-semantic-release-1.10.2/pkg/semanticrelease/semantic-release.go:103 +0x138
github.com/Nightapes/go-semantic-release/cmd/go-semantic-release/commands.glob..func5(0x1b87ac0, 0x1bbd418, 0x0, 0x0, 0x0, 0x0)
	/Users/redacted/tmp/go-semantic-release-1.10.2/cmd/go-semantic-release/commands/next.go:52 +0x23d
github.com/spf13/cobra.(*Command).execute(0x1b87ac0, 0x1bbd418, 0x0, 0x0, 0x1b87ac0, 0x1bbd418)
	/Users/redacted/go/pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0x1b87fc0, 0x1006045, 0xc00008c058, 0x101a501)
	/Users/redacted/go/pkg/mod/github.com/spf13/[email protected]/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/redacted/go/pkg/mod/github.com/spf13/[email protected]/command.go:897
github.com/Nightapes/go-semantic-release/cmd/go-semantic-release/commands.Execute(0x0, 0x0)
	/Users/redacted/tmp/go-semantic-release-1.10.2/cmd/go-semantic-release/commands/root.go:28 +0x55
main.main()
	/Users/redacted/tmp/go-semantic-release-1.10.2/cmd/go-semantic-release/main.go:10 +0x39

note: no issues for v1.10.1

Error: could not get commits object not found 🤔

Unfortunately, I'm having difficulty running this for the first time on a new repository.

release.yml

name: release

on:
  push:
    branches:
    - main

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      ...
  
  release:
    name: Release
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - uses: actions/download-artifact@v2
        with:
          name: binaries

      - name: Login to Github registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.REGISTRY_TOKEN }}
      
      - name: Install semantic-release
        run: |
          wget https://github.com/Nightapes/go-semantic-release/releases/download/v2.0.1/go-semantic-release.linux_x86_64.zip
          unzip go-semantic-release.linux_x86_64.zip
          chmod +x go-semantic-release.linux_x86_64
      
      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
        run: |
          ls
          ./go-semantic-release.linux_x86_64 release --loglevel trace

.release.yml

release: github
github:
  repo: stewartgo
  user: t-h-o
commitFormat: conventional
branch:
  main: release
assets:
  - path: stewart.linux_x86_64
    compress: false
  - path: stewart.windows_x86_64.exe
    compress: false
changelog:
  docker:
    latest: true
    repository: "ghcr.io/t-h-o/stewart"
hooks:
  preRelease:
    - make docker-build -e VERSION=$RELEASE_VERSION
  postRelease:
    - make docker-push

Output

Dockerfile
Makefile
cmd
config
go-semantic-release.linux_x86_64
go-semantic-release.linux_x86_64.zip
go.mod
go.sum
internal
main.go
stewart.linux_x86_64
stewart.windows_x86_64.exe
time="2021-09-27T05:52:48Z" level=trace msg="Found config release: github\ngithub:\n  repo: stewartgo\n  user: t-h-o\ncommitFormat: conventional\nbranch:\n  main: release\nassets:\n  - path: stewart.linux_x86_64\n    compress: false\n  - path: stewart.windows_x86_64.exe\n    compress: false\nchangelog:\n  docker:\n    latest: true\n    repository: \"ghcr.io/t-h-o/stewart\"\nhooks:\n  preRelease:\n    - make docker-build -e VERSION=$RELEASE_VERSION\n  postRelease:\n    - make docker-push\n"
time="2021-09-27T05:52:48Z" level=trace msg="Found config &{CommitFormat:conventional Branch:map[main:release] Analyzer:{TokenSeparators:[]} Changelog:{PrintAll:false TemplateTitle: TemplatePath: Docker:{Latest:true Repository:ghcr.io/t-h-o/stewart} NPM:{Repository: PackageName:}} Release:github GitHubProvider:{Repo:stewartgo User:t-h-o CustomURL: AccessToken: TagPrefix:<nil>} GitLabProvider:{Repo: CustomURL: AccessToken: TagPrefix:<nil>} GitProvider:{Email: Username: Auth: SSH:false TagPrefix:<nil>} Assets:[{Path:stewart.linux_x86_64 Rename: Name: Compress:false} {Path:stewart.windows_x86_64.exe Rename: Name: Compress:false}] Checksum:{Algorithm:} Hooks:{PreRelease:[make docker-build -e VERSION=$RELEASE_VERSION] PostRelease:[make docker-push]} Integrations:{NPM:{Enabled:false Path:}} ReleaseTitle: IsPreRelease:false}"
time="2021-09-27T05:52:48Z" level=debug msg="Commit format set to conventional"
time="2021-09-27T05:52:48Z" level=debug msg="initialize new github-provider"
time="2021-09-27T05:52:48Z" level=debug msg="check if GITHUB_TOKEN environment variable is set"
time="2021-09-27T05:52:48Z" level=debug msg="not running on travis"
time="2021-09-27T05:52:48Z" level=debug msg="GITHUB_EVENT_NAME=push, not running on pr"
time="2021-09-27T05:52:48Z" level=info msg="Found CI: GithubActions CI"
time="2021-09-27T05:52:48Z" level=trace msg="Found CI config: &{IsPR:false PR: PRBranch: Branch:main Tag: Commit:c29fee211db5142fac6d9bcaaaf88642a886a1f9 BuildURL: Service:GithubActions Name:GithubActions CI}"
time="2021-09-27T05:52:48Z" level=debug msg="Ignore .version file if exits, false"
time="2021-09-27T05:52:48Z" level=warning msg="Could not read cache .version, will ignore cache"
time="2021-09-27T05:52:48Z" level=debug msg="Found no tags"
time="2021-09-27T05:52:48Z" level=info msg="This is the first release, will set version to 1.0.0"
time="2021-09-27T05:52:48Z" level=debug msg="Could not get next version"
Error: could not get commits object not found

I see that it's failing on line 109 in semantic-release.go, but I'm not sure why? Any pointers?

Allow grouping of footers per changelog

Hey guys, I am back with more requests :)

I am trying to have some of our team members get onboard using semantic-release using go-semantic-release. And they have one use case for a changelog where they would like footers to be grouped in to a separate section.

Example,
The team will write configuration changes in a separate footer for multiple commits.

feat: ...

Config-Change: foo.bar is added to handle the drink count. 

When a release is created they would then like to gather all "Config-Change" entries in to a dedicated section like so:


# CHANGELOG.md

Config Changes

  • foo.bar is added to handle the drink count
  • foo.super block is added to handle superpowers
    {
      "foo": {
         "super": {
             "activate": false,
             "boo": 3
        }
      }
    }
    

If you guys want, I can look in to this.

Add npm tooling

Allow update of version in package json
Print npm usage in changelog

Error: could not get commits object not found gitlab-ci.yml

Hello,

It hits error when pipeline runs. I have already set GITLAB_ACCESS_TOKEN env in CI/CD environment settings.

Here is the .release.yml

commitFormat: conventional
branch:
  dev: release
release: 'gitlab'
gitlab:
  repo: "<repo_name>"

Here is the .gitlab-ci.yml

deploy-release-management:
  stage: deploy-release-management
  environment:
    name: test
  only:
    refs:
      - dev
  image:
    name: nightapes/go-semantic-release:latest
    entrypoint: [""]
  script:
    - go-semantic-release next

Here is the pipeline job logs.

Using docker image sha256:a94f6e1d7067e24eae9349ee954af5324b4e7ee8483d9bff17fe264456b1e362 for nightapes/go-semantic-release:latest with digest nightapes/go-semantic-release@sha256:a0fe6d7c099e90eadbcd144a23b4cf07caca883062747b5710455e520f880895 ...
$ go-semantic-release next
Error: could not get commits object not found
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

How can we resolve this issue ?

Thanks.

Give a warning if a release is going to create a version smaller than the remote version tag

When creating a release from a local machine the version is calculated from the local commits, however if the local repository has not fetched the tags from remote it would calculate a version that is the same or smaller than the actual/remote version.

A validation step would help ensure that the wrong release is not pushed out due to a user error (of not pulling the changes and tags from remote).

This can also be an issue in the CI environment, if an old job is rerun that creates a release.

release 1.9.0: message block does not have the same indents

I realized that a message block in a changelog does not has the same indent as the headers or footers in a commit. For better readability, I suggest adding spaces to the message block until it aligns with the bullet points, the same for the footer bullet points. I also suggest adding a line break between the header and the message block.

We could use direct HTML templates instead of using markdown.

Quickfix: Adding HTML spaces in the markdown using &nbsp;:

Features

  • angular update angular to include new structured fields (7208dae)

  • conventional parse body and footers according to the rules

       Previous assumption about multiple labeled body blocks and footers is
       not correct. There is only one body text block with multi-line support.
       A footer always starts with a token with a separator.

       - A body ends when a footer is found or text ends.
       - A footer ends when another footer is found or text ends. (a20992a)

  • analyzer update AnalyzedCommit to add flexibility in parsing a message

       This provides flexibility of parsing and rendering structured messages
       with more detail in the changelog and helps extract metadata from the
       message. The new structure can be used to split a message in multiple
       blocks (e.g. footer) (dc4d1c5)

Getting strange errors when trying to execute in scope of pipeline

I'm trying to execute go-semantic-release from docker image in my gitlab CI pipeline.
I am getting strange error:

Using docker image sha256:181cf62eeefdfa3138f0dba256e5583f770f747f0b593d7953eec17acc0469a1 for nightapes/go-semantic-release:latest with digest nightapes/go-semantic-release@sha256:9e362ff31e0a126a928ba3822f06201a2b60bdded2c4988d2f9eacef61ba3290 ...
Error: unknown command "sh" for "go-semantic-release"
Did you mean this?
	set
Run 'go-semantic-release --help' for usage.

Here is my pipeline description:

semver:
  stage: semver
  image:
    name: nightapes/go-semantic-release:latest
  script:
    - go-semantic-release next
  only:
    refs:
      - master
      - semantic-versioning
      - deploy

Running the changelog command only generates log for the current release and overwrites the file

I have been testing the changelog function and I see that it only generates changelog for the current release. Also, with the default output it overwrites the current CHANGELOG.md file, losing the old change logs. And hence I am not able to use the changelog feature from the tool. At the moment I have to rely on another tool for changelog generation.

Here is what I have seen other projects do, which will be very helpful to use the changelog feature.

  • It should be able to generate the entire changelog (or based on tag ranges)
  • It should have a possibility to prepend the change log from the current release to the existing CHANGELOG.md file

How changes for release are calculated?

I am working with laravel app and added some changes to php files
Still last and next commands are showing that there is no changes

commit 892bf8373b793bc73b5d187ebe9f4ccd7eab1258 (HEAD -> semantic-versioning, origin/master, origin/HEAD, master)
Author: Anton Kuryan 
Date:   Wed Aug 25 19:16:26 2021 +0300

    Fixed rules

How to match a tag

I'm trying to match the tag named hello/v0.0.1
In the command line I've tried sematic-release --match hello/v*
But this doesn't work. I didn't find any documentation for this, so can you tell how to match a tag?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.