Console friendly switches and documentation

+ Add ARM64 binary release
+ Draft for github actions.
This commit is contained in:
2021-05-09 04:32:20 +01:00
parent c2efa43dcb
commit 8bbde1f600
8 changed files with 155 additions and 40 deletions
+23 -12
View File
@@ -33,15 +33,21 @@ jobs:
- name: Setting environment variables
id: get_env
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_GITHUB_COMMITS_COUNT=$(git rev-list --count HEAD)
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=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_SHA::$(echo ${GITHUB_SHA::8})"
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:
needs: [ prepare ]
@@ -53,9 +59,6 @@ jobs:
steps:
- name: Checkout repo
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
if: env.ENABLE_CODE_LINT == true
env:
@@ -81,7 +84,6 @@ jobs:
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 }}"
make update
- name: WriteGoList
run: go list -json -m all > go.list
@@ -149,26 +151,35 @@ jobs:
image: "${{ needs.prepare.outputs.DOCKER_IMAGE }}:${{ needs.prepare.outputs.GITHUB_SHA }}"
fail-build: true
release:
name: Create Release
build-binary:
needs: [ prepare, test, code_scans ]
name: Binary compilation and release
runs-on: ubuntu-latest
needs: [ prepare, deploy ]
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
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
run: |
echo "$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h %s")" > .release_notes
- name: Create Release
id: create_release
uses: actions/create-release@main
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.event.repository.name }}/${{ needs.prepare.outputs.RELEASE_VERSION }}
release_name: v${{ needs.prepare.outputs.RELEASE_VERSION }}
files: dist/semver-gen-*
tag_name: ${{ needs.prepare.outputs.RELEASE_VERSION }}
name: ${{ needs.prepare.outputs.RELEASE_VERSION }}
body_path: .release_notes
draft: false
prerelease: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' }}
prerelease: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' }}
+4 -1
View File
@@ -7,4 +7,7 @@ run: build
@./semver-gen
test:
@go test ./... -v -race -cover
@go test ./... -v -race -cover
update:
@go get -u ./...
+15 -5
View File
@@ -18,18 +18,28 @@ Project created overnight, to prove that management of semantic versioning is NO
### Usage
```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
```
Available flags:
** Local repository flag `-l` will always take precedence over remote repository URL **
```yaml
Usage:
semver-gen generate [flags]
semver-gen [command]
Available Commands:
generate Generates semantic version
help Help about any command
Flags:
-c, --config string Path to config file (default "config.yaml")
-g, --generate Generate semantic version
-h, --help help for this command
-r, --repository string Repository URL. If not specified local dir will be used. (default "https://github.com/lukaszraczylo/simple-gql-client")
-h, --help help for semver-gen
-l, --local Use local repository
-r, --repository string Remote repository URL. (default "https://github.com/lukaszraczylo/simple-gql-client")
```
#### Calculations example
+24
View File
@@ -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 }}
+37
View File
@@ -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
View File
@@ -64,6 +64,7 @@ type Setup struct {
Force Force
Generate bool
LocalConfigFile string
UseLocal bool
}
type CommitDetails struct {
@@ -90,18 +91,15 @@ func (s *Setup) CalculateSemver() SemVer {
matchMajor := checkMatches(commitSlice, s.Wording.Major)
if matchPatch {
s.Semver.Patch++
// fmt.Println("Patch version bumped:", commit.Message)
}
if matchMinor {
s.Semver.Minor++
s.Semver.Patch = 1
// fmt.Println("Minor version bumped:", commit.Message)
}
if matchMajor {
s.Semver.Major++
s.Semver.Minor = 0
s.Semver.Patch = 1
// fmt.Println("Major version bumped:", commit.Message)
}
}
return s.Semver
@@ -125,14 +123,27 @@ func (s *Setup) ListCommits() ([]CommitDetails, error) {
}
func (s *Setup) Prepare() error {
u, _ := url.Parse(s.RepositoryName)
s.RepositoryLocalPath = fmt.Sprintf("/tmp/foo/%s", u.Path)
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())
if !repo.UseLocal {
u, err := url.Parse(s.RepositoryName)
if err != nil {
fmt.Println("Unable to parse repository URL", err.Error())
return err
}
s.RepositoryLocalPath = fmt.Sprintf("/tmp/foo/%s", u.Path)
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
}
@@ -165,10 +176,6 @@ func (s *Setup) getSemver() string {
return fmt.Sprintf("%d.%d.%d", s.Semver.Major, s.Semver.Minor, s.Semver.Patch)
}
func (s *Setup) parseFlags() {
}
func main() {
if repo.Generate {
err := repo.ReadConfig(repo.LocalConfigFile)
+25 -7
View File
@@ -22,11 +22,9 @@ import (
"github.com/spf13/cobra"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "semver-gen",
Use: "semver-gen generate [flags]",
Short: "An effortless semantic version generator",
Long: `semver-gen // Lukasz Raczylo, raczylo.com
@@ -39,12 +37,32 @@ func 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() {
repo = &Setup{}
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.")
rootCmd.PersistentFlags().StringVarP(&repo.LocalConfigFile, "config", "c", "config.yaml", "Path to config file")
rootCmd.PersistentFlags().BoolVarP(&repo.Generate, "generate", "g", true, "Generate semantic version")
main()
cobra.OnInitialize(repo.setupCobra)
rootCmd.PersistentFlags().StringVarP(&varRepoName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Remote repository URL.")
rootCmd.PersistentFlags().StringVarP(&varLocalCfg, "config", "c", "config.yaml", "Path to config file")
rootCmd.PersistentFlags().BoolVarP(&varUseLocal, "local", "l", false, "Use local repository")
}
}
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh -l
echo "Hello $1"
echo "::set-output name=semver::$time"