You've already forked go-semantic-release
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9f2b163c7 | ||
|
|
4379551982 | ||
|
|
3eb13972ec | ||
|
|
8659b40960 | ||
|
|
7ead374039 | ||
|
|
ee1dc3d8db | ||
|
|
38e4c178ee | ||
|
|
e22d3d07f4 | ||
|
|
46ae2da821 |
12
.github/workflows/main.yml
vendored
12
.github/workflows/main.yml
vendored
@@ -7,10 +7,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Set up Go 1.12
|
||||
- name: Set up Go 1.13
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.12
|
||||
go-version: 1.13
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
- 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.16.0
|
||||
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
|
||||
@@ -31,10 +31,10 @@ jobs:
|
||||
run: |
|
||||
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
||||
./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=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=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: Release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: ./build/go-semantic-release-temp release --loglevel trace
|
||||
run: ./build/go-semantic-release-temp release --loglevel trace
|
||||
11
README.md
11
README.md
@@ -71,23 +71,28 @@ At the moment we support releases to gitlab and github.
|
||||
|
||||
##### Github
|
||||
|
||||
You need to set the env `GITHUB_TOKEN` with an access token.
|
||||
|
||||
```yml
|
||||
release: 'github'
|
||||
github:
|
||||
user: "<user/group"
|
||||
repo: "<repositroyname>"
|
||||
## Optional, if your not using github.com
|
||||
customURL: <https://your.github>
|
||||
customUrl: <https://your.github>
|
||||
```
|
||||
|
||||
##### Gitlab
|
||||
|
||||
You need to set the env `GITLAB_ACCESS_TOKEN` with an personal access token.
|
||||
|
||||
|
||||
```yml
|
||||
release: 'gitlab'
|
||||
gitlab:
|
||||
repo: "<repositroyname>" ## Example group/project
|
||||
## Optional, if your not using gitlab.com
|
||||
customURL: <https://your.gitlab>
|
||||
customUrl: <https://your.gitlab>
|
||||
```
|
||||
|
||||
#### Assets
|
||||
@@ -176,4 +181,4 @@ go test ./...
|
||||
```
|
||||
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 ./...
|
||||
```
|
||||
```
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/Nightapes/go-semantic-release
|
||||
|
||||
go 1.12
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/Masterminds/semver v1.4.2
|
||||
|
||||
@@ -3,10 +3,11 @@ package ci
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
//ProviderConfig struct
|
||||
@@ -43,6 +44,7 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC
|
||||
services := []Service{
|
||||
Travis{},
|
||||
GithubActions{},
|
||||
GitlabCI{},
|
||||
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"},
|
||||
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 {
|
||||
|
||||
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
|
||||
}
|
||||
@@ -42,8 +42,9 @@ func New(config *config.GitLabProvider) (*Client, error) {
|
||||
|
||||
tokenHeader := util.NewAddHeaderTransport(nil, "PRIVATE-TOKEN", accessToken)
|
||||
acceptHeader := util.NewAddHeaderTransport(tokenHeader, "Accept", "application/json")
|
||||
contentHeader := util.NewAddHeaderTransport(acceptHeader, "Content-Type", "application/json")
|
||||
httpClient := &http.Client{
|
||||
Transport: acceptHeader,
|
||||
Transport: contentHeader,
|
||||
Timeout: time.Second * 60,
|
||||
}
|
||||
|
||||
@@ -97,7 +98,7 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
||||
g.Release = tag
|
||||
g.log.Infof("create release with version %s", tag)
|
||||
url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo))
|
||||
g.log.Infof("Send release to %s", url)
|
||||
g.log.Infof("Send release to %s", url)
|
||||
|
||||
bodyBytes, err := json.Marshal(Release{
|
||||
TagName: tag,
|
||||
@@ -109,6 +110,8 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
||||
return err
|
||||
}
|
||||
|
||||
g.log.Tracef("Send release config %s", bodyBytes)
|
||||
|
||||
req, err := http.NewRequest("POST", url, bytes.NewReader(bodyBytes))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create request: %s", err.Error())
|
||||
@@ -124,7 +127,7 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
||||
return err
|
||||
}
|
||||
|
||||
g.log.Infof("Crated release")
|
||||
g.log.Infof("Created release")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
//"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
@@ -109,7 +108,7 @@ func TestCreateRelease(t *testing.T) {
|
||||
},
|
||||
responseBody: "{}",
|
||||
responseCode: 200,
|
||||
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content","assets":{"links":null}}`,
|
||||
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
@@ -133,7 +132,7 @@ func TestCreateRelease(t *testing.T) {
|
||||
},
|
||||
responseBody: "{}",
|
||||
responseCode: 500,
|
||||
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content","assets":{"links":null}}`,
|
||||
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
@@ -158,7 +157,7 @@ func TestCreateRelease(t *testing.T) {
|
||||
},
|
||||
responseCode: 400,
|
||||
responseBody: "{}",
|
||||
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content","assets":{"links":null}}`,
|
||||
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -6,9 +6,6 @@ type Release struct {
|
||||
Name string `json:"name"`
|
||||
Ref string `json:"ref"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Assets struct {
|
||||
Links []*ReleaseLink `json:"links"`
|
||||
} `json:"assets"`
|
||||
}
|
||||
|
||||
// ReleaseLink struct
|
||||
|
||||
Reference in New Issue
Block a user