Skip to content

Commit

Permalink
Merge pull request #28 from Nightapes/git_provider
Browse files Browse the repository at this point in the history
Git provider and hooks
  • Loading branch information
fwiedmann authored Jan 5, 2020
2 parents 6211095 + d92438b commit 1342714
Show file tree
Hide file tree
Showing 24 changed files with 530 additions and 191 deletions.
105 changes: 44 additions & 61 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,51 @@
name: Go
on: [push, pull_request]
jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Lint
run: |
export PATH=$PATH:$(go env GOPATH)/bin
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.18.0
golangci-lint run ./...
- name: Run tests
run: go test ./...

- name: Build binary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
./build/go-semantic-release-temp next --no-cache --loglevel trace
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o build/go-semantic-release.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
- name: Build Docker image for master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.ref == 'refs/heads/master'
run: |
docker build -t nightapes/go-semantic-release:latest .
docker build -t nightapes/go-semantic-release:"$(./build/go-semantic-release next)" .
- name: Push Docker image for master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.ref == 'refs/heads/master'
run: |
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
docker push nightapes/go-semantic-release:latest
docker push nightapes/go-semantic-release:"$(./build/go-semantic-release next)"
- name: Build Docker image
if: github.ref != 'refs/heads/master'
run: |
docker build -t nightapes/go-semantic-release:development .
- name: Push Docker image
if: github.ref != 'refs/heads/master'
run: |
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
docker push nightapes/go-semantic-release:development
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./build/go-semantic-release-temp release --loglevel trace
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Lint
run: |
export PATH=$PATH:$(go env GOPATH)/bin
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.18.0
golangci-lint run ./...
- name: Run tests
run: go test ./...

- name: Build binary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
./build/go-semantic-release-temp next --no-cache --loglevel trace
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o build/go-semantic-release.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
- name: Build Docker image
if: github.ref != 'refs/heads/master'
run: |
docker build -t nightapes/go-semantic-release:development .
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
docker push nightapes/go-semantic-release:development
- name: Push Docker image
if: github.ref != 'refs/heads/master'
run: |
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
./build/go-semantic-release-temp release --loglevel trace
11 changes: 9 additions & 2 deletions .release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
release: 'github'
release: "github"
github:
repo: "go-semantic-release"
user: "nightapes"
Expand All @@ -13,4 +13,11 @@ assets:
changelog:
docker:
latest: true
repository: "nightapes/go-semantic-release"
repository: "nightapes/go-semantic-release"
hooks:
preRelease:
- docker build -t nightapes/go-semantic-release:latest .
- docker build -t nightapes/go-semantic-release:$RELEASE_VERSION .
postRelease:
- docker push nightapes/go-semantic-release:latest
- docker push nightapes/go-semantic-release:$RELEASE_VERSION
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| ---------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
| `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
| `git` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
| `git` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | |
| `bitbuckt` | Comming soon | :white_check_mark: | | | :white_check_mark: | |


Expand Down Expand Up @@ -37,6 +37,11 @@ assets:
compress: false
- name: ./build/go-semantic-release.exe
compress: false
hooks:
preRelease:
- name: echo $RELEASE_VERSION
postRelease:
- name: echo $RELEASE_VERSION
```
#### CommitFormat
Expand Down Expand Up @@ -65,7 +70,7 @@ branch:
<branch-name>: <kind>
```

#### Relase
#### Release

At the moment we support releases to gitlab and github.

Expand Down Expand Up @@ -95,6 +100,20 @@ gitlab:
customUrl: <https://your.gitlab>
```

##### Git only

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


```yml
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
```


#### Assets

You can upload assets to a release
Expand All @@ -108,6 +127,10 @@ assets:
compress: false
```

#### Hooks

Hooks will run when calling `release`. Hooks run only if a release will be triggered.

#### Changelog

Following variables can be used for templates:
Expand Down
7 changes: 6 additions & 1 deletion cmd/go-semantic-release/commands/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ var changelogCmd = &cobra.Command{
return err
}

s, err := semanticrelease.New(readConfig(config), repository)
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
if err != nil {
return err
}

s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/go-semantic-release/commands/next.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ var nextCmd = &cobra.Command{
return err
}

s, err := semanticrelease.New(readConfig(config), repository)
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
if err != nil {
return err
}

s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/go-semantic-release/commands/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ var releaseCmd = &cobra.Command{
return err
}

s, err := semanticrelease.New(readConfig(config), repository)
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
if err != nil {
return err
}

s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/go-semantic-release/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func init() {
rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel")
rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file")
rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build")
rootCmd.PersistentFlags().Bool("no-checks", false, "Ignore missing values and envs")
}

func readConfig(file string) *config.ReleaseConfig {
Expand Down
7 changes: 6 additions & 1 deletion cmd/go-semantic-release/commands/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ var setCmd = &cobra.Command{
return err
}

s, err := semanticrelease.New(readConfig(config), repository)
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
if err != nil {
return err
}

s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/go-semantic-release/commands/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ var zipCmd = &cobra.Command{
return err
}

s, err := semanticrelease.New(readConfig(config), repository)
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
if err != nil {
return err
}

s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -72,14 +74,17 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestWriteAndReadCache(t *testing.T) {
Author: "Author",
Hash: "Hash",
},
ParsedMessage: "add gitlab as relase option",
ParsedMessage: "add gitlab as release option",
Scope: "releaser",
ParsedBreakingChangeMessage: "",
Tag: "feat",
Expand Down
10 changes: 7 additions & 3 deletions internal/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func ReadAllEnvs() map[string]string {
}

//GetCIProvider get provider
func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderConfig, error) {
func GetCIProvider(gitUtil *gitutil.GitUtil, configCheck bool, envs map[string]string) (*ProviderConfig, error) {

services := []Service{
Travis{},
GithubActions{},
GitlabCI{},
Git{gitUtil: gitUtil}, // GIt must be the last option to check
Git{gitUtil: gitUtil}, // Git must be the last option to check
}

for _, service := range services {
Expand All @@ -57,5 +57,9 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC
}
log.Debugf("%s", err.Error())
}
return nil, fmt.Errorf("could not find any CI, if running locally set env CI=true")
if configCheck {
return nil, fmt.Errorf("could not find any CI, if running locally set env CI=true")

}
return Git{gitUtil: gitUtil}.detect(map[string]string{"CI": "true"})
}
2 changes: 1 addition & 1 deletion internal/ci/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestCi(t *testing.T) {
}

for _, config := range testConfigs {
provider, err := ci.GetCIProvider(gitUtilInMemory, config.envs)
provider, err := ci.GetCIProvider(gitUtilInMemory, true, config.envs)
assert.Equalf(t, config.hasError, err != nil, "Service %s should have error: %t -> %s", config.service, config.hasError, err)
assert.Equalf(t, config.result, provider, "Service %s should have provider", config.service)
}
Expand Down
Loading

0 comments on commit 1342714

Please sign in to comment.