fear(ci): add github actions

This commit is contained in:
Nightapes
2019-08-21 21:39:05 +02:00
parent 7857b5f6f3
commit 89f4842a2b
4 changed files with 62 additions and 1 deletions

View File

@@ -28,9 +28,11 @@ jobs:
golangci-lint run ./... golangci-lint run ./...
- name: Run tests - name: Run tests
run: go test -v ./... run: go test ./...
- name: Build binary - name: Build binary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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/
go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/ go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/

View File

@@ -42,6 +42,7 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC
services := []Service{ services := []Service{
Travis{}, Travis{},
GithubActions{},
Git{gitUtil: gitUtil}, // GIt must be the last option to check Git{gitUtil: gitUtil}, // GIt must be the last option to check
} }

View File

@@ -89,6 +89,28 @@ func TestCi(t *testing.T) {
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"}, result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
hasError: false, hasError: false,
}, },
{
service: "Github Actions PR",
envs: map[string]string{
"GITHUB_EVENT_NAME": "pull_request",
"GITHUB_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
"GITHUB_REF": "master",
"GITHUB_ACTION": "action",
},
result: &ci.ProviderConfig{IsPR: true, PR: "", PRBranch: "", Branch: "master", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
hasError: false,
},
{
service: "Github Actions Push",
envs: map[string]string{
"GITHUB_EVENT_NAME": "push",
"GITHUB_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
"GITHUB_REF": "refs/heads/feature-branch-1",
"GITHUB_ACTION": "action",
},
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "refs/heads/feature-branch-1", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
hasError: false,
},
} }
for _, config := range testConfigs { for _, config := range testConfigs {

View File

@@ -0,0 +1,36 @@
package ci
import (
"fmt"
log "github.com/sirupsen/logrus"
)
//GithubActions struct
type GithubActions struct{}
//Detect if on GithubActions
func (t GithubActions) detect(envs map[string]string) (*ProviderConfig, error) {
if _, exists := envs["GITHUB_ACTION"]; !exists {
return nil, fmt.Errorf("not running on Github Actions")
}
isPR := false
value := envs["GITHUB_EVENT_NAME"]
if value == "pull_request" {
isPR = true
} else {
log.Debugf("GITHUB_EVENT_NAME=%s, not running on pr", value)
}
return &ProviderConfig{
Service: "GithubActions",
Name: "GithubActions CI",
Commit: envs["GITHUB_SHA"],
Branch: envs["GITHUB_REF"],
IsPR: isPR,
}, nil
}