You've already forked go-semantic-release
Compare commits
23 Commits
feat--Add-
...
v2.2.9
| Author | SHA1 | Date | |
|---|---|---|---|
| 5636fecc14 | |||
| b13699d2f8 | |||
| f7f395c30f | |||
| 0bcede8594 | |||
| 34589749ba | |||
| b38abd00f2 | |||
| 913783cf08 | |||
| d701ce2352 | |||
| 4d0d1e4319 | |||
| c4cecdebb4 | |||
| ad8d69452d | |||
| 7f8ed11f79 | |||
| 6d1f8f0a9a | |||
| 3a93293318 | |||
| 1712dbdbaf | |||
| a442a82d15 | |||
| 70b6cbe8df | |||
| c981a99424 | |||
| a2b32024a1 | |||
| 8f5e47eecd | |||
| 274cabf05a | |||
| 77fb819342 | |||
| 0b309228d3 |
@@ -1,2 +1,10 @@
|
||||
*
|
||||
!build/
|
||||
!build/
|
||||
!cmd/
|
||||
!internal/
|
||||
!pkg/
|
||||
!scripts/
|
||||
!Dockerfile*
|
||||
!.dockerignore
|
||||
!go.mod
|
||||
!go.sum
|
||||
11
.githooks/commit-msg
Executable file
11
.githooks/commit-msg
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Run the script and get the return code if successful of if fails
|
||||
./scripts/commit-filter-check.sh && rc=$? || rc=$?
|
||||
echo return code : $rc
|
||||
if [ ${rc} = 1 ]; then
|
||||
echo "Script return code 1 so commit failed"
|
||||
exit 1
|
||||
else
|
||||
echo "No error returned so commit successful"
|
||||
fi
|
||||
31
.release.yml
31
.release.yml
@@ -1,32 +1,29 @@
|
||||
release: "github"
|
||||
github:
|
||||
release: "gitea"
|
||||
gitea:
|
||||
repo: "go-semantic-release"
|
||||
user: "nightapes"
|
||||
user: "cybercinch"
|
||||
url: "https://hub.cybercinch.nz"
|
||||
commitFormat: angular
|
||||
branch:
|
||||
master: release
|
||||
beta: beta
|
||||
develop: beta
|
||||
assets:
|
||||
- name: ./build/go-semantic-release.linux_x86_64
|
||||
- path: ./build/go-semantic-release.linux_amd64
|
||||
compress: true
|
||||
- name: ./build/go-semantic-release.windows_i386.exe
|
||||
- path: ./build/go-semantic-release.linux_arm64
|
||||
compress: true
|
||||
- name: ./build/go-semantic-release.windows_x86_64.exe
|
||||
- path: ./build/go-semantic-release.windows_i386.exe
|
||||
compress: true
|
||||
- name: ./build/go-semantic-release.darwin_x86_64
|
||||
- path: ./build/go-semantic-release.windows_amd64.exe
|
||||
compress: true
|
||||
- path: ./build/go-semantic-release.darwin_amd64
|
||||
compress: true
|
||||
changelog:
|
||||
docker:
|
||||
latest: true
|
||||
repository: "nightapes/go-semantic-release"
|
||||
repository: "cybercinch/go-semantic-release"
|
||||
showAuthors: true
|
||||
|
||||
hooks:
|
||||
preRelease:
|
||||
- docker build -t nightapes/go-semantic-release:latest .
|
||||
- docker tag nightapes/go-semantic-release:latest docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:$RELEASE_VERSION
|
||||
- docker tag nightapes/go-semantic-release:latest nightapes/go-semantic-release:$RELEASE_VERSION
|
||||
postRelease:
|
||||
- docker push nightapes/go-semantic-release:latest
|
||||
- docker push nightapes/go-semantic-release:$RELEASE_VERSION
|
||||
- docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:$RELEASE_VERSION
|
||||
preRelease: []
|
||||
postRelease: []
|
||||
|
||||
114
.woodpecker.yml
Normal file
114
.woodpecker.yml
Normal file
@@ -0,0 +1,114 @@
|
||||
variables:
|
||||
- &platforms 'linux/arm64,linux/amd64'
|
||||
- &docker_creds
|
||||
username:
|
||||
from_secret: hub_username_cybercinch
|
||||
password:
|
||||
from_secret: docker_password_cybercinch
|
||||
- &pypi_creds
|
||||
username:
|
||||
from_secret: hub_username_cybercinch
|
||||
password:
|
||||
from_secret: docker_password_cybercinch
|
||||
- build_args: &build_args
|
||||
- TAG: ${CI_COMMIT_TAG}
|
||||
clone:
|
||||
git:
|
||||
image: woodpeckerci/plugin-git
|
||||
settings:
|
||||
partial: false
|
||||
tags: true
|
||||
|
||||
steps:
|
||||
build-release:
|
||||
image: docker.io/cybercinch/go-semrelease:golang1.20
|
||||
pull: true
|
||||
commands:
|
||||
- >
|
||||
GOOS=linux
|
||||
GOARCH=amd64
|
||||
CGO_ENABLED=0
|
||||
go build -o build/go-semantic-release.linux_amd64 -ldflags "-w -s --X main.version=`go-semantic-release next`"
|
||||
./cmd/go-semantic-release/
|
||||
- >
|
||||
GOOS=linux
|
||||
GOARCH=arm64
|
||||
CGO_ENABLED=0
|
||||
go build -o build/go-semantic-release.linux_arm64 -ldflags "-w -s --X main.version=`go-semantic-release next`"
|
||||
./cmd/go-semantic-release/
|
||||
- >
|
||||
GOOS=windows
|
||||
GOARCH=386
|
||||
CGO_ENABLED=0
|
||||
go build -o build/go-semantic-release.windows_i386.exe -ldflags "-w -s -X main.version=`go-semantic-release next`"
|
||||
./cmd/go-semantic-release/
|
||||
- >
|
||||
GOOS=windows
|
||||
GOARCH=amd64
|
||||
CGO_ENABLED=0
|
||||
go build -o build/go-semantic-release.windows_amd64.exe -ldflags "-w -s -X main.version=`go-semantic-release next`"
|
||||
./cmd/go-semantic-release/
|
||||
- >
|
||||
GOOS=darwin
|
||||
GOARCH=amd64
|
||||
CGO_ENABLED=0
|
||||
go build -o build/go-semantic-release.darwin_amd64 -ldflags "-w -s -X main.version=`go-semantic-release next`"
|
||||
./cmd/go-semantic-release/
|
||||
- go-semantic-release --loglevel debug release # Actually make the release on Gitea. Uploading assets
|
||||
environment:
|
||||
GITEA_TOKEN:
|
||||
from_secret: gitea_token
|
||||
GITEA_URL:
|
||||
from_secret: gitea_server_url
|
||||
when:
|
||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||
event:
|
||||
- push
|
||||
- manual
|
||||
|
||||
publish-docker-tagged:
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
pull: true
|
||||
settings:
|
||||
<<: *docker_creds
|
||||
token:
|
||||
from_secret: depot_token
|
||||
registry: hub.cybercinch.nz
|
||||
repo: cybercinch/${CI_REPO_NAME}
|
||||
dockerfile: Dockerfile
|
||||
platforms: *platforms
|
||||
build_args:
|
||||
- TAG=${CI_COMMIT_TAG}
|
||||
tags:
|
||||
- latest
|
||||
- ${CI_COMMIT_TAG}
|
||||
logins:
|
||||
- registry: https://hub.cybercinch.nz/
|
||||
username: cybercinch
|
||||
password:
|
||||
from_secret: docker_password_cybercinch
|
||||
when:
|
||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||
event:
|
||||
- tag
|
||||
|
||||
publish-docker-develop:
|
||||
image: docker.io/cybercinch/woodpecker-plugin-depot
|
||||
pull: true
|
||||
settings:
|
||||
<<: *docker_creds
|
||||
token:
|
||||
from_secret: depot_token
|
||||
repohost: hub.cybercinch.nz
|
||||
repo: cybercinch/${CI_REPO_NAME}
|
||||
project:
|
||||
from_secret: depot_project
|
||||
dockerfile: Dockerfile.dev
|
||||
push: true
|
||||
platforms: linux/amd64
|
||||
tags: ["develop"]
|
||||
when:
|
||||
branch: develop
|
||||
event:
|
||||
- push
|
||||
- manual
|
||||
14
Dockerfile
14
Dockerfile
@@ -1,8 +1,20 @@
|
||||
FROM alpine:3.14
|
||||
ARG TARGETPLATFORM
|
||||
# Set by build-arg
|
||||
ARG TAG=v2.2.3
|
||||
|
||||
# Strip out the prefix
|
||||
ENV PLAT=${TARGETPLATFORM//"linux/"/}
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
COPY ./build/go-semantic-release.linux_x86_64 /usr/local/bin/go-semantic-release
|
||||
ADD https://hub.cybercinch.nz/cybercinch/go-semantic-release/releases/download/${TAG}/go-semantic-release.linux_${PLAT}.zip /tmp
|
||||
RUN apk add --no-cache unzip && \
|
||||
unzip -d /tmp /tmp/go-semantic-release.linux_${PLAT}.zip && \
|
||||
ls && \
|
||||
ls /tmp && \
|
||||
mv /tmp/go-semantic-release.linux_${PLAT} /usr/local/bin/go-semantic-release && \
|
||||
rm -f /tmp/go-semantic-release.linux_${PLAT}.zip
|
||||
|
||||
USER 1000
|
||||
|
||||
|
||||
23
Dockerfile.dev
Normal file
23
Dockerfile.dev
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM golang:1.20 as build
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
# Copy code into build container
|
||||
COPY . /code/
|
||||
|
||||
RUN GOOS=linux \
|
||||
GOARCH=amd64 \
|
||||
CGO_ENABLED=0 \
|
||||
go build -o build/go-semantic-release.linux_x86_64 -ldflags "-w -s --X main.version=`go-semantic-release next`" \
|
||||
./cmd/go-semantic-release/
|
||||
|
||||
|
||||
FROM alpine:3.14
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
COPY --from=build /code/build/go-semantic-release.linux_x86_64 /usr/local/bin/go-semantic-release
|
||||
|
||||
USER 1000
|
||||
|
||||
ENTRYPOINT [ "go-semantic-release" ]
|
||||
@@ -36,6 +36,7 @@ func New(c *config.GiteaProvider, checkConfig bool) (*GiteaClient, error) {
|
||||
if err != nil && checkConfig {
|
||||
return &GiteaClient{}, err
|
||||
}
|
||||
|
||||
c.AccessToken = token
|
||||
|
||||
if c.URL == "" {
|
||||
@@ -114,11 +115,13 @@ func (g *GiteaClient) makeRelease(releaseVersion *shared.ReleaseVersion, generat
|
||||
Title: generatedChangelog.Title,
|
||||
Note: generatedChangelog.Content,
|
||||
IsPrerelease: prerelease}
|
||||
|
||||
g.client.CreateRelease(g.config.User, g.config.Repo, opt)
|
||||
|
||||
// TODO Test if this prevents release double-up
|
||||
release, _, err := g.client.CreateRelease(g.config.User, g.config.Repo, opt)
|
||||
|
||||
g.log.Debugf("Release response: %+v", *release)
|
||||
|
||||
if err != nil {
|
||||
g.log.Debugf("Release Error response: %+v", err)
|
||||
if strings.Contains(err.Error(), "Release is has no Tag") {
|
||||
g.log.Infof("A release with tag %s already exits, will not perform a release or update", tag)
|
||||
return nil
|
||||
@@ -126,7 +129,6 @@ func (g *GiteaClient) makeRelease(releaseVersion *shared.ReleaseVersion, generat
|
||||
return fmt.Errorf("could not create release: %s", err.Error())
|
||||
}
|
||||
g.release = release
|
||||
g.log.Debugf("Release response: %+v", *release)
|
||||
g.log.Infof("Created release")
|
||||
return nil
|
||||
|
||||
|
||||
199
internal/releaser/gitea/gitea_test.go
Normal file
199
internal/releaser/gitea/gitea_test.go
Normal file
@@ -0,0 +1,199 @@
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type testHelperMethodStruct struct {
|
||||
config config.GitHubProvider
|
||||
valid bool
|
||||
}
|
||||
|
||||
type testReleaseStruct struct {
|
||||
config config.GitHubProvider
|
||||
releaseVersion *shared.ReleaseVersion
|
||||
generatedChangelog *shared.GeneratedChangelog
|
||||
requestResponseBody string
|
||||
requestResponseCode int
|
||||
valid bool
|
||||
}
|
||||
|
||||
var testNewClient = []testHelperMethodStruct{
|
||||
{config: config.GitHubProvider{
|
||||
Repo: "foo",
|
||||
User: "bar",
|
||||
},
|
||||
valid: true,
|
||||
},
|
||||
|
||||
{config: config.GitHubProvider{
|
||||
Repo: "foo",
|
||||
User: "bar",
|
||||
CustomURL: "https://test.com",
|
||||
},
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
|
||||
var lastVersion, _ = semver.NewVersion("1.0.0")
|
||||
var newVersion, _ = semver.NewVersion("2.0.0")
|
||||
|
||||
var testReleases = []testReleaseStruct{
|
||||
{
|
||||
config: config.GitHubProvider{
|
||||
Repo: "foo",
|
||||
User: "bar",
|
||||
},
|
||||
releaseVersion: &shared.ReleaseVersion{
|
||||
Last: shared.ReleaseVersionEntry{
|
||||
Version: lastVersion,
|
||||
Commit: "foo",
|
||||
},
|
||||
Next: shared.ReleaseVersionEntry{
|
||||
Version: newVersion,
|
||||
Commit: "bar",
|
||||
},
|
||||
Branch: "master",
|
||||
},
|
||||
generatedChangelog: &shared.GeneratedChangelog{
|
||||
Title: "title",
|
||||
Content: "content",
|
||||
},
|
||||
requestResponseBody: "{ \"url\": \"https://api.github.com/repos/octocat/Hello-World/releases/1\", \"html_url\": \"https://github.com/octocat/Hello-World/releases/v1.0.0\", \"assets_url\": \"https://api.github.com/repos/octocat/Hello-World/releases/1/assets\", \"upload_url\": \"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}\", \"tarball_url\": \"https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0\", \"zipball_url\": \"https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0\", \"id\": 1, \"node_id\": \"MDc6UmVsZWFzZTE=\", \"tag_name\": \"v1.0.0\", \"target_commitish\": \"master\", \"name\": \"v1.0.0\", \"body\": \"Description of the release\", \"draft\": false, \"prerelease\": false, \"created_at\": \"2013-02-27T19:35:32Z\", \"published_at\": \"2013-02-27T19:35:32Z\", \"author\": { \"login\": \"octocat\", \"id\": 1, \"node_id\": \"MDQ6VXNlcjE=\", \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\", \"gravatar_id\": \"\", \"url\": \"https://api.github.com/users/octocat\", \"html_url\": \"https://github.com/octocat\", \"followers_url\": \"https://api.github.com/users/octocat/followers\", \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\", \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\", \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\", \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\", \"organizations_url\": \"https://api.github.com/users/octocat/orgs\", \"repos_url\": \"https://api.github.com/users/octocat/repos\", \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\", \"received_events_url\": \"https://api.github.com/users/octocat/received_events\", \"type\": \"User\", \"site_admin\": false }, \"assets\": [ ]}",
|
||||
requestResponseCode: 200,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
config: config.GitHubProvider{
|
||||
Repo: "foo",
|
||||
User: "bar",
|
||||
},
|
||||
releaseVersion: &shared.ReleaseVersion{
|
||||
Last: shared.ReleaseVersionEntry{
|
||||
Version: lastVersion,
|
||||
Commit: "foo",
|
||||
},
|
||||
Next: shared.ReleaseVersionEntry{
|
||||
Version: newVersion,
|
||||
Commit: "bar",
|
||||
},
|
||||
Branch: "master",
|
||||
},
|
||||
generatedChangelog: &shared.GeneratedChangelog{
|
||||
Title: "title",
|
||||
Content: "content",
|
||||
},
|
||||
requestResponseCode: 400,
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
|
||||
func initHTTPServer(respCode int, body string) *httptest.Server {
|
||||
|
||||
return httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
log.Infof("Got call from %s %s", req.Method, req.URL.String())
|
||||
|
||||
rw.WriteHeader(respCode)
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
|
||||
if _, err := rw.Write([]byte(body)); err != nil {
|
||||
log.Info(err)
|
||||
}
|
||||
|
||||
}))
|
||||
}
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
for _, testOject := range testNewClient {
|
||||
if testOject.valid {
|
||||
os.Setenv("GITHUB_TOKEN", "XXX")
|
||||
}
|
||||
|
||||
_, err := New(&testOject.config, true)
|
||||
assert.Equal(t, testOject.valid, err == nil)
|
||||
|
||||
os.Unsetenv("GITHUB_TOKEN")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCommitURL(t *testing.T) {
|
||||
os.Setenv("GITHUB_TOKEN", "XX")
|
||||
for _, testOject := range testNewClient {
|
||||
client, _ := New(&testOject.config, false)
|
||||
actualURL := client.GetCommitURL()
|
||||
if testOject.config.CustomURL != "" {
|
||||
expectedURL := fmt.Sprintf("%s/api/v3/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
|
||||
assert.EqualValues(t, expectedURL, actualURL)
|
||||
|
||||
} else {
|
||||
expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo)
|
||||
assert.EqualValues(t, expectedURL, actualURL)
|
||||
}
|
||||
}
|
||||
os.Unsetenv("GITHUB_TOKEN")
|
||||
|
||||
}
|
||||
|
||||
func TestGetCompareURL(t *testing.T) {
|
||||
os.Setenv("GITHUB_TOKEN", "XX")
|
||||
for _, testOject := range testNewClient {
|
||||
client, _ := New(&testOject.config, false)
|
||||
actualURL := client.GetCompareURL("1", "2")
|
||||
if testOject.config.CustomURL != "" {
|
||||
expectedURL := fmt.Sprintf("%s/api/v3/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2")
|
||||
assert.EqualValues(t, expectedURL, actualURL)
|
||||
|
||||
} else {
|
||||
expectedURL := fmt.Sprintf("%s/%s/%s/compare/%s...%s", "https://github.com", testOject.config.User, testOject.config.Repo, "1", "2")
|
||||
assert.EqualValues(t, expectedURL, actualURL)
|
||||
}
|
||||
}
|
||||
os.Unsetenv("GITHUB_TOKEN")
|
||||
|
||||
}
|
||||
|
||||
func TestCreateRelease(t *testing.T) {
|
||||
os.Setenv("GITHUB_TOKEN", "XX")
|
||||
|
||||
for _, testObejct := range testReleases {
|
||||
if testObejct.valid {
|
||||
server := initHTTPServer(testObejct.requestResponseCode, testObejct.requestResponseBody)
|
||||
testObejct.config.CustomURL = server.URL
|
||||
client, _ := New(&testObejct.config, false)
|
||||
|
||||
err := client.makeRelease(testObejct.releaseVersion, testObejct.generatedChangelog)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
assert.Equal(t, testObejct.valid, err == nil)
|
||||
|
||||
server.Close()
|
||||
|
||||
} else {
|
||||
testObejct.config.CustomURL = "http://foo"
|
||||
client, _ := New(&testObejct.config, false)
|
||||
|
||||
err := client.makeRelease(testObejct.releaseVersion, testObejct.generatedChangelog)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
assert.Error(t, err)
|
||||
}
|
||||
}
|
||||
os.Unsetenv("GITHUB_TOKEN")
|
||||
|
||||
}
|
||||
85
scripts/commit-filter-check.sh
Executable file
85
scripts/commit-filter-check.sh
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
commit_message_check (){
|
||||
# Get the current branch and apply it to a variable
|
||||
currentbranch=`git branch | grep \* | cut -d ' ' -f2`
|
||||
|
||||
# Gets the commits for the current branch and outputs to file
|
||||
git log $currentbranch --pretty=format:"%H" --not master > shafile.txt
|
||||
|
||||
# loops through the file an gets the message
|
||||
for i in `cat ./shafile.txt`;
|
||||
do
|
||||
# gets the git commit message based on the sha
|
||||
gitmessage=`git log --format=%B -n 1 "$i"`
|
||||
|
||||
####################### TEST STRINGS comment out line 13 to use #########################################
|
||||
#gitmessage="feat sdasdsadsaas (AEROGEAR-asdsada)"
|
||||
#gitmessage="feat(some txt): some txt (AEROGEAR-****)"
|
||||
#gitmessage="docs(some txt): some txt (AEROGEAR-1234)"
|
||||
#gitmessage="fix(some txt): some txt (AEROGEAR-5678)"
|
||||
#########################################################################################################
|
||||
|
||||
# Checks gitmessage for string feat, fix, docs and breaking, if the messagecheck var is empty if fails
|
||||
messagecheck=`echo $gitmessage | grep -w "chore\|feat\|fix\|docs\|breaking"`
|
||||
if [ -z "$messagecheck" ]
|
||||
then
|
||||
echo "Your commit message must begin with one of the following"
|
||||
echo " feat(feature-name)"
|
||||
echo " fix(fix-name)"
|
||||
echo " docs(docs-change)"
|
||||
echo " "
|
||||
fi
|
||||
if [ ${PerformProjectCheck} == "true" ]; then
|
||||
#check the gitmessage for the Jira number
|
||||
messagecheck=`echo $gitmessage | grep "(${ProjectID}-"`
|
||||
if [ -z "$messagecheck" ]
|
||||
then
|
||||
echo "Your commit message must end with the following"
|
||||
echo " (${ProjectID}-****)"
|
||||
echo "Where **** is the Jira number"
|
||||
echo " "
|
||||
fi
|
||||
fi
|
||||
messagecheck=`echo $gitmessage | grep ": "`
|
||||
if [ -z "$messagecheck" ]
|
||||
then
|
||||
echo "Your commit message has a formatting error please take note of special characters '():' position and use in the example below"
|
||||
echo " type(some txt): some txt (${ProjectID}-****)"
|
||||
echo "Where 'type' is fix, feat, docs or breaking and **** is the Jira number"
|
||||
echo " "
|
||||
fi
|
||||
|
||||
if [ ${PerformProjectCheck} == "true" ]; then
|
||||
# All checks run at the same time by pipeing from one grep to another
|
||||
messagecheck=`echo $gitmessage | grep -w "chore\|feat\|fix\|docs\|breaking" | grep "(${ProjectID}-" | grep ": "`
|
||||
else
|
||||
# All checks run at the same time by pipeing from one grep to another
|
||||
messagecheck=`echo $gitmessage | grep -w "chore\|feat\|fix\|docs\|breaking" | grep ": "`
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# check to see if the messagecheck var is empty
|
||||
if [ -z "$messagecheck" ]
|
||||
then
|
||||
echo "The commit message with sha: '$i' failed "
|
||||
echo "Please review the following :"
|
||||
echo " "
|
||||
echo $gitmessage
|
||||
echo " "
|
||||
rm shafile.txt >/dev/null 2>&1
|
||||
set -o errexit
|
||||
else
|
||||
echo "$messagecheck"
|
||||
echo "'$i' commit message passed"
|
||||
fi
|
||||
done
|
||||
rm shafile.txt >/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
ProjectID="NA" # Set to your Jira Project ID if want to track references to tickets.
|
||||
PerformProjectCheck="false" # Set true if ProjectID is set and you want to ensure Jira ref is included on commit.
|
||||
# Calling the function
|
||||
commit_message_check
|
||||
Reference in New Issue
Block a user