mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-07-05 03:54:46 +00:00
Console friendly switches and documentation
+ Add ARM64 binary release + Draft for github actions.
This commit is contained in:
@@ -33,15 +33,21 @@ jobs:
|
|||||||
- name: Setting environment variables
|
- name: Setting environment variables
|
||||||
id: get_env
|
id: get_env
|
||||||
run: |
|
run: |
|
||||||
|
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/lukaszraczylo/semver-generator/releases/latest \
|
||||||
|
| grep browser_download_url \
|
||||||
|
| grep semver-gen-linux-amd64 \
|
||||||
|
| cut -d '"' -f 4)
|
||||||
|
curl -s -L -o semver-gen "$DOWNLOAD_URL" && chmod +x semver-gen
|
||||||
TMP_SANITISED_REPOSITORY_NAME=$(echo ${{ github.event.repository.name }} | sed -e 's|\.|-|g')
|
TMP_SANITISED_REPOSITORY_NAME=$(echo ${{ github.event.repository.name }} | sed -e 's|\.|-|g')
|
||||||
TMP_GITHUB_COMMITS_COUNT=$(git rev-list --count HEAD)
|
TMP_GITHUB_COMMITS_COUNT=$(git rev-list --count HEAD)
|
||||||
TMP_GITHUB_COUNT_NUMBER=$(echo ${GITHUB_RUN_NUMBER})
|
TMP_GITHUB_COUNT_NUMBER=$(echo ${GITHUB_RUN_NUMBER})
|
||||||
|
TMP_RELEASE_VERSION=$(./semver-gen generate -l -c config-release.yaml | sed -e 's|SEMVER ||g')
|
||||||
echo "::set-output name=SANITISED_REPOSITORY_NAME::$TMP_SANITISED_REPOSITORY_NAME"
|
echo "::set-output name=SANITISED_REPOSITORY_NAME::$TMP_SANITISED_REPOSITORY_NAME"
|
||||||
echo "::set-output name=DOCKER_IMAGE::ghcr.io/${{ github.repository_owner }}/$TMP_SANITISED_REPOSITORY_NAME"
|
echo "::set-output name=DOCKER_IMAGE::ghcr.io/${{ github.repository_owner }}/$TMP_SANITISED_REPOSITORY_NAME"
|
||||||
echo "::set-output name=GITHUB_COMMIT_NUMBER::$TMP_GITHUB_COMMITS_COUNT"
|
echo "::set-output name=GITHUB_COMMIT_NUMBER::$TMP_GITHUB_COMMITS_COUNT"
|
||||||
echo "::set-output name=GITHUB_SHA::$(echo ${GITHUB_SHA::8})"
|
echo "::set-output name=GITHUB_SHA::$(echo ${GITHUB_SHA::8})"
|
||||||
echo "::set-output name=GITHUB_RUN_ID::$TMP_GITHUB_COUNT_NUMBER"
|
echo "::set-output name=GITHUB_RUN_ID::$TMP_GITHUB_COUNT_NUMBER"
|
||||||
echo "::set-output name=RELEASE_VERSION::1.$TMP_GITHUB_COMMITS_COUNT.$TMP_GITHUB_COUNT_NUMBER"
|
echo "::set-output name=RELEASE_VERSION::$TMP_RELEASE_VERSION"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
needs: [ prepare ]
|
needs: [ prepare ]
|
||||||
@@ -53,9 +59,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Configure git for private modules
|
|
||||||
run: |
|
|
||||||
git config --global url."https://${{ secrets.GHCR_TOKEN }}:x-oauth-basic@github.com/${{ github.repository_owner }}".insteadOf "https://github.com/${{ github.repository_owner }}"
|
|
||||||
- name: Lint Code Base
|
- name: Lint Code Base
|
||||||
if: env.ENABLE_CODE_LINT == true
|
if: env.ENABLE_CODE_LINT == true
|
||||||
env:
|
env:
|
||||||
@@ -81,7 +84,6 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Configure git for private modules
|
- name: Configure git for private modules
|
||||||
run: |
|
run: |
|
||||||
git config --global url."https://${{ secrets.GHCR_TOKEN }}:x-oauth-basic@github.com/${{ github.repository_owner }}".insteadOf "https://github.com/${{ github.repository_owner }}"
|
|
||||||
make update
|
make update
|
||||||
- name: WriteGoList
|
- name: WriteGoList
|
||||||
run: go list -json -m all > go.list
|
run: go list -json -m all > go.list
|
||||||
@@ -149,26 +151,35 @@ jobs:
|
|||||||
image: "${{ needs.prepare.outputs.DOCKER_IMAGE }}:${{ needs.prepare.outputs.GITHUB_SHA }}"
|
image: "${{ needs.prepare.outputs.DOCKER_IMAGE }}:${{ needs.prepare.outputs.GITHUB_SHA }}"
|
||||||
fail-build: true
|
fail-build: true
|
||||||
|
|
||||||
release:
|
build-binary:
|
||||||
name: Create Release
|
needs: [ prepare, test, code_scans ]
|
||||||
|
name: Binary compilation and release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [ prepare, deploy ]
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- name: Compile binary
|
||||||
|
uses: thatisuday/go-cross-build@v1
|
||||||
|
with:
|
||||||
|
platforms: linux/amd64,darwin/amd64,windows/amd64,linux/arm64,darwin/amd64
|
||||||
|
name: semver-gen
|
||||||
|
package: ./
|
||||||
|
compress: false
|
||||||
|
dest: dist
|
||||||
- name: Get list of the commits since last release
|
- name: Get list of the commits since last release
|
||||||
run: |
|
run: |
|
||||||
echo "$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h %s")" > .release_notes
|
echo "$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h %s")" > .release_notes
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@main
|
uses: softprops/action-gh-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
tag_name: v${{ github.event.repository.name }}/${{ needs.prepare.outputs.RELEASE_VERSION }}
|
files: dist/semver-gen-*
|
||||||
release_name: v${{ needs.prepare.outputs.RELEASE_VERSION }}
|
tag_name: ${{ needs.prepare.outputs.RELEASE_VERSION }}
|
||||||
|
name: ${{ needs.prepare.outputs.RELEASE_VERSION }}
|
||||||
body_path: .release_notes
|
body_path: .release_notes
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' }}
|
prerelease: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' }}
|
||||||
|
|||||||
@@ -7,4 +7,7 @@ run: build
|
|||||||
@./semver-gen
|
@./semver-gen
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@go test ./... -v -race -cover
|
@go test ./... -v -race -cover
|
||||||
|
|
||||||
|
update:
|
||||||
|
@go get -u ./...
|
||||||
@@ -18,18 +18,28 @@ Project created overnight, to prove that management of semantic versioning is NO
|
|||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash$ ./semver-gen -g
|
bash$ ./semver-gen generate -r https://github.com/nextapps-de/winbox
|
||||||
|
SEMVER 9.0.10
|
||||||
|
bash$ ./semver-gen generate -l
|
||||||
SEMVER 5.1.1
|
SEMVER 5.1.1
|
||||||
```
|
```
|
||||||
|
|
||||||
Available flags:
|
** Local repository flag `-l` will always take precedence over remote repository URL **
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
Usage:
|
||||||
|
semver-gen generate [flags]
|
||||||
|
semver-gen [command]
|
||||||
|
|
||||||
|
Available Commands:
|
||||||
|
generate Generates semantic version
|
||||||
|
help Help about any command
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-c, --config string Path to config file (default "config.yaml")
|
-c, --config string Path to config file (default "config.yaml")
|
||||||
-g, --generate Generate semantic version
|
-h, --help help for semver-gen
|
||||||
-h, --help help for this command
|
-l, --local Use local repository
|
||||||
-r, --repository string Repository URL. If not specified local dir will be used. (default "https://github.com/lukaszraczylo/simple-gql-client")
|
-r, --repository string Remote repository URL. (default "https://github.com/lukaszraczylo/simple-gql-client")
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Calculations example
|
#### Calculations example
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
# action.yml
|
||||||
|
name: 'Semantic Version Generator'
|
||||||
|
description: 'Automagic semantic version generator'
|
||||||
|
inputs:
|
||||||
|
config-file:
|
||||||
|
description: 'Configuration file'
|
||||||
|
required: false
|
||||||
|
repository-url:
|
||||||
|
description: 'Repository URL'
|
||||||
|
required: false
|
||||||
|
default: 'https://github.com/lukaszraczylo/simple-gql-client'
|
||||||
|
repository-local:
|
||||||
|
description: 'Use already cloned repository'
|
||||||
|
required: false
|
||||||
|
outputs:
|
||||||
|
semantic-version: # id of output
|
||||||
|
description: 'Calculated semantic version'
|
||||||
|
runs:
|
||||||
|
using: 'docker'
|
||||||
|
image: 'Dockerfile'
|
||||||
|
args:
|
||||||
|
- ${{ inputs.config-file }}
|
||||||
|
- ${{ inputs.repository-url }}
|
||||||
|
- ${{ inputs.repository-local }}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2021 LUKASZ RACZYLO <lukasz$raczylo,com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// generateCmd represents the generate command
|
||||||
|
var generateCmd = &cobra.Command{
|
||||||
|
Use: "generate [flags]",
|
||||||
|
Short: "Generates semantic version",
|
||||||
|
Long: `Semantic version generation using your configuration file and fuzzy matching of git commit messages.
|
||||||
|
Please refer to documentation on https://github.com/lukaszraczylo/semver-generator for more information.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
repo.Generate = true
|
||||||
|
repo.setupCobra()
|
||||||
|
main()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(generateCmd)
|
||||||
|
}
|
||||||
+22
-15
@@ -64,6 +64,7 @@ type Setup struct {
|
|||||||
Force Force
|
Force Force
|
||||||
Generate bool
|
Generate bool
|
||||||
LocalConfigFile string
|
LocalConfigFile string
|
||||||
|
UseLocal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitDetails struct {
|
type CommitDetails struct {
|
||||||
@@ -90,18 +91,15 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
matchMajor := checkMatches(commitSlice, s.Wording.Major)
|
matchMajor := checkMatches(commitSlice, s.Wording.Major)
|
||||||
if matchPatch {
|
if matchPatch {
|
||||||
s.Semver.Patch++
|
s.Semver.Patch++
|
||||||
// fmt.Println("Patch version bumped:", commit.Message)
|
|
||||||
}
|
}
|
||||||
if matchMinor {
|
if matchMinor {
|
||||||
s.Semver.Minor++
|
s.Semver.Minor++
|
||||||
s.Semver.Patch = 1
|
s.Semver.Patch = 1
|
||||||
// fmt.Println("Minor version bumped:", commit.Message)
|
|
||||||
}
|
}
|
||||||
if matchMajor {
|
if matchMajor {
|
||||||
s.Semver.Major++
|
s.Semver.Major++
|
||||||
s.Semver.Minor = 0
|
s.Semver.Minor = 0
|
||||||
s.Semver.Patch = 1
|
s.Semver.Patch = 1
|
||||||
// fmt.Println("Major version bumped:", commit.Message)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s.Semver
|
return s.Semver
|
||||||
@@ -125,14 +123,27 @@ func (s *Setup) ListCommits() ([]CommitDetails, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Setup) Prepare() error {
|
func (s *Setup) Prepare() error {
|
||||||
u, _ := url.Parse(s.RepositoryName)
|
if !repo.UseLocal {
|
||||||
s.RepositoryLocalPath = fmt.Sprintf("/tmp/foo/%s", u.Path)
|
u, err := url.Parse(s.RepositoryName)
|
||||||
os.RemoveAll(s.RepositoryLocalPath)
|
if err != nil {
|
||||||
s.RepositoryHandler, err = git.PlainClone(s.RepositoryLocalPath, false, &git.CloneOptions{
|
fmt.Println("Unable to parse repository URL", err.Error())
|
||||||
URL: s.RepositoryName,
|
return err
|
||||||
})
|
}
|
||||||
if err != nil {
|
s.RepositoryLocalPath = fmt.Sprintf("/tmp/foo/%s", u.Path)
|
||||||
fmt.Println("Unable to reach repository", err.Error())
|
os.RemoveAll(s.RepositoryLocalPath)
|
||||||
|
s.RepositoryHandler, err = git.PlainClone(s.RepositoryLocalPath, false, &git.CloneOptions{
|
||||||
|
URL: s.RepositoryName,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Unable to reach repository", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s.RepositoryHandler, err = git.PlainOpen(s.RepositoryLocalPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Unable to reach repository", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -165,10 +176,6 @@ func (s *Setup) getSemver() string {
|
|||||||
return fmt.Sprintf("%d.%d.%d", s.Semver.Major, s.Semver.Minor, s.Semver.Patch)
|
return fmt.Sprintf("%d.%d.%d", s.Semver.Major, s.Semver.Minor, s.Semver.Patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Setup) parseFlags() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if repo.Generate {
|
if repo.Generate {
|
||||||
err := repo.ReadConfig(repo.LocalConfigFile)
|
err := repo.ReadConfig(repo.LocalConfigFile)
|
||||||
|
|||||||
+25
-7
@@ -22,11 +22,9 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cfgFile string
|
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "semver-gen",
|
Use: "semver-gen generate [flags]",
|
||||||
Short: "An effortless semantic version generator",
|
Short: "An effortless semantic version generator",
|
||||||
Long: `semver-gen // Lukasz Raczylo, raczylo.com
|
Long: `semver-gen // Lukasz Raczylo, raczylo.com
|
||||||
|
|
||||||
@@ -39,12 +37,32 @@ func Execute() {
|
|||||||
cobra.CheckErr(rootCmd.Execute())
|
cobra.CheckErr(rootCmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Setup) setupCobra() {
|
||||||
|
r.RepositoryName, err = rootCmd.Flags().GetString("repository")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
r.LocalConfigFile, err = rootCmd.Flags().GetString("config")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
r.UseLocal = varUseLocal
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
varRepoName, varLocalCfg string
|
||||||
|
varUseLocal bool
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
repo = &Setup{}
|
repo = &Setup{}
|
||||||
if !strings.HasSuffix(os.Args[0], ".test") {
|
if !strings.HasSuffix(os.Args[0], ".test") {
|
||||||
rootCmd.PersistentFlags().StringVarP(&repo.RepositoryName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Repository URL. If not specified local dir will be used.")
|
cobra.OnInitialize(repo.setupCobra)
|
||||||
rootCmd.PersistentFlags().StringVarP(&repo.LocalConfigFile, "config", "c", "config.yaml", "Path to config file")
|
rootCmd.PersistentFlags().StringVarP(&varRepoName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Remote repository URL.")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&repo.Generate, "generate", "g", true, "Generate semantic version")
|
rootCmd.PersistentFlags().StringVarP(&varLocalCfg, "config", "c", "config.yaml", "Path to config file")
|
||||||
main()
|
rootCmd.PersistentFlags().BoolVarP(&varUseLocal, "local", "l", false, "Use local repository")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh -l
|
||||||
|
|
||||||
|
echo "Hello $1"
|
||||||
|
|
||||||
|
echo "::set-output name=semver::$time"
|
||||||
Reference in New Issue
Block a user