You've already forked go-semantic-release
fix(ci): add gitlab ci detection
This commit is contained in:
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -31,8 +31,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
||||||
./build/go-semantic-release-temp next --no-cache --loglevel trace
|
./build/go-semantic-release-temp next --no-cache --loglevel trace
|
||||||
go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
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 go build -o build/go-semantic-release.exe -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: Release
|
- name: Release
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ At the moment we support releases to gitlab and github.
|
|||||||
|
|
||||||
##### Github
|
##### Github
|
||||||
|
|
||||||
|
You need to set the env `GITHUB_TOKEN` with an access token.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
release: 'github'
|
release: 'github'
|
||||||
github:
|
github:
|
||||||
@@ -82,6 +84,9 @@ github:
|
|||||||
|
|
||||||
##### Gitlab
|
##### Gitlab
|
||||||
|
|
||||||
|
You need to set the env `GITLAB_ACCESS_TOKEN` with an personal access token.
|
||||||
|
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
release: 'gitlab'
|
release: 'gitlab'
|
||||||
gitlab:
|
gitlab:
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/Nightapes/go-semantic-release
|
module github.com/Nightapes/go-semantic-release
|
||||||
|
|
||||||
go 1.12
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/semver v1.4.2
|
github.com/Masterminds/semver v1.4.2
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ package ci
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ProviderConfig struct
|
//ProviderConfig struct
|
||||||
@@ -43,6 +44,7 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC
|
|||||||
services := []Service{
|
services := []Service{
|
||||||
Travis{},
|
Travis{},
|
||||||
GithubActions{},
|
GithubActions{},
|
||||||
|
GitlabCI{},
|
||||||
Git{gitUtil: gitUtil}, // GIt must be the last option to check
|
Git{gitUtil: gitUtil}, // GIt must be the last option to check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,19 @@ func TestCi(t *testing.T) {
|
|||||||
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "feature-branch-1", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "feature-branch-1", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
service: "GitLab CI/CD PR",
|
||||||
|
envs: map[string]string{
|
||||||
|
"GITLAB_CI": "true",
|
||||||
|
"CI_COMMIT_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"CI_COMMIT_REF_NAME": "master",
|
||||||
|
"CI_COMMIT_TAG": "tag",
|
||||||
|
"CI_PROJECT_URL": "https://my.gitlab.com",
|
||||||
|
"CI_PIPELINE_ID": "1",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "tag", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://my.gitlab.com/pipelines/1", Service: "gitlab", Name: "GitLab CI/CD"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, config := range testConfigs {
|
for _, config := range testConfigs {
|
||||||
|
|||||||
26
internal/ci/gitlab_ci.go
Normal file
26
internal/ci/gitlab_ci.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package ci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
//GitlabCI struct
|
||||||
|
type GitlabCI struct{}
|
||||||
|
|
||||||
|
//Detect if on GitlabCI
|
||||||
|
func (t GitlabCI) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
|
if _, exists := envs["GITLAB_CI"]; !exists {
|
||||||
|
return nil, fmt.Errorf("not running on gitlab")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ProviderConfig{
|
||||||
|
Service: "gitlab",
|
||||||
|
Name: "GitLab CI/CD",
|
||||||
|
Commit: envs["CI_COMMIT_SHA"],
|
||||||
|
Tag: envs["CI_COMMIT_TAG"],
|
||||||
|
BuildURL: envs["CI_PROJECT_URL"] + "/pipelines/" + envs["CI_PIPELINE_ID"],
|
||||||
|
Branch: envs["CI_COMMIT_REF_NAME"],
|
||||||
|
IsPR: false,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user