You've already forked go-semantic-release
Compare commits
25 Commits
| 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 | |||
| 141f297c87 | |||
| 2236fe923c |
@@ -1,2 +1,10 @@
|
||||
*
|
||||
!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" ]
|
||||
19
README.md
19
README.md
@@ -9,7 +9,8 @@
|
||||
| `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` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | |
|
||||
| `bitbucket` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||
| `bitbucket` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||
| `gitea` | Coming soon | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
|
||||
|
||||
## Supported CI Pipelines
|
||||
@@ -97,7 +98,7 @@ branch:
|
||||
|
||||
#### Release
|
||||
|
||||
At the moment we support releases to gitlab and github.
|
||||
At the moment we support releases to gitlab, github and gitea.
|
||||
|
||||
##### Github
|
||||
|
||||
@@ -144,6 +145,20 @@ git:
|
||||
## Optional, if you want to change the default tag prefix ("v")
|
||||
tagPrefix: ""
|
||||
```
|
||||
##### Gitea
|
||||
|
||||
You need to set the env `GITEA_TOKEN` with an access token.
|
||||
|
||||
```yml
|
||||
release: 'gitea'
|
||||
gitea:
|
||||
user: "<user/group"
|
||||
repo: "<repositoryname>"
|
||||
## URL of your Gitea instance
|
||||
Url: <https://your.github>
|
||||
## Optional, if you want to change the default tag prefix ("v")
|
||||
tagPrefix: ""
|
||||
```
|
||||
|
||||
|
||||
#### Assets
|
||||
|
||||
13
go.mod
13
go.mod
@@ -17,6 +17,13 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davidmz/go-pageant v1.0.2 // indirect
|
||||
github.com/go-fed/httpsig v1.1.0 // indirect
|
||||
github.com/hashicorp/go-version v1.6.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.17.1
|
||||
github.com/Microsoft/go-winio v0.6.0 // indirect
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
|
||||
github.com/acomagu/bufpipe v1.0.3 // indirect
|
||||
@@ -39,10 +46,10 @@ require (
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/xanzy/ssh-agent v0.3.3 // indirect
|
||||
golang.org/x/crypto v0.6.0 // indirect
|
||||
golang.org/x/crypto v0.17.0 // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/net v0.7.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
|
||||
38
go.sum
38
go.sum
@@ -1,4 +1,5 @@
|
||||
cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
|
||||
code.gitea.io/sdk/gitea v0.17.1 h1:3jCPOG2ojbl8AcfaUCRYLT5MUcBMFwS0OSK2mA5Zok8=
|
||||
code.gitea.io/sdk/gitea v0.17.1/go.mod h1:aCnBqhHpoEWA180gMbaCtdX9Pl6BWBAuuP2miadoTNM=
|
||||
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
|
||||
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
|
||||
@@ -14,7 +15,6 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuW
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/bwesterb/go-ristretto v1.2.2/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
|
||||
github.com/cloudflare/circl v1.3.2 h1:VWp8dY3yH69fdM7lM6A1+NhhVoDu9vqK0jOgmkQHFWk=
|
||||
github.com/cloudflare/circl v1.3.2/go.mod h1:+CauBF6R70Jqcyl8N2hC8pAXYbWkGIezuSbuGLtRhnw=
|
||||
@@ -23,10 +23,14 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
|
||||
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
|
||||
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
|
||||
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
|
||||
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
|
||||
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
|
||||
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
|
||||
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
|
||||
github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||
@@ -44,7 +48,6 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github/v25 v25.1.3 h1:Ht4YIQgUh4l4lc80fvGnw60khXysXvlgPxPP8uJG3EA=
|
||||
@@ -52,6 +55,8 @@ github.com/google/go-github/v25 v25.1.3/go.mod h1:6z5pC69qHtrPJ0sXPsj4BLnd82b+r6
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
|
||||
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
||||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
@@ -110,18 +115,20 @@ github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM
|
||||
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
@@ -130,8 +137,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
|
||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s=
|
||||
golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I=
|
||||
@@ -141,6 +148,7 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -153,26 +161,31 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
@@ -185,7 +198,6 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
//ProviderConfig struct
|
||||
// ProviderConfig struct
|
||||
type ProviderConfig struct {
|
||||
IsPR bool
|
||||
PR string
|
||||
@@ -23,12 +23,12 @@ type ProviderConfig struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
//Service interface
|
||||
// Service interface
|
||||
type Service interface {
|
||||
detect(envs map[string]string) (*ProviderConfig, error)
|
||||
}
|
||||
|
||||
//ReadAllEnvs as a map
|
||||
// ReadAllEnvs as a map
|
||||
func ReadAllEnvs() map[string]string {
|
||||
envs := map[string]string{}
|
||||
for _, pair := range os.Environ() {
|
||||
@@ -38,13 +38,14 @@ func ReadAllEnvs() map[string]string {
|
||||
return envs
|
||||
}
|
||||
|
||||
//GetCIProvider get provider
|
||||
// GetCIProvider get provider
|
||||
func GetCIProvider(gitUtil *gitutil.GitUtil, configCheck bool, envs map[string]string) (*ProviderConfig, error) {
|
||||
|
||||
services := []Service{
|
||||
Travis{},
|
||||
GithubActions{},
|
||||
GitlabCI{},
|
||||
WoodpeckerCI{},
|
||||
Git{gitUtil: gitUtil}, // Git must be the last option to check
|
||||
}
|
||||
|
||||
|
||||
42
internal/ci/woodpecker.go
Normal file
42
internal/ci/woodpecker.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package ci
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Travis struct
|
||||
type WoodpeckerCI struct{}
|
||||
|
||||
// Detect if on travis
|
||||
func (t WoodpeckerCI) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||
|
||||
if envs["CI"] != "woodpecker" {
|
||||
return nil, fmt.Errorf("not running on woodpecker")
|
||||
}
|
||||
|
||||
isPR := false
|
||||
|
||||
value := envs["CI_COMMIT_PULL_REQUEST"]
|
||||
pr := ""
|
||||
|
||||
if value == "" {
|
||||
log.Debugf("CI_COMMIT_PULL_REQUEST=%s, not running on pr", value)
|
||||
} else {
|
||||
isPR = true
|
||||
pr = value
|
||||
}
|
||||
|
||||
return &ProviderConfig{
|
||||
Service: "woodpecker",
|
||||
Name: "Woodpecker CI",
|
||||
Commit: envs["CI_COMMIT_SHA"],
|
||||
Tag: envs["CI_COMMIT_TAG"],
|
||||
BuildURL: envs["CI_PIPELINE_URL"],
|
||||
Branch: envs["CI_COMMIT_BRANCH"],
|
||||
IsPR: isPR,
|
||||
PR: pr,
|
||||
PRBranch: envs["CI_COMMIT_SOURCE_BRANCH"],
|
||||
}, nil
|
||||
}
|
||||
161
internal/releaser/gitea/gitea.go
Normal file
161
internal/releaser/gitea/gitea.go
Normal file
@@ -0,0 +1,161 @@
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// GITEA identifer for gitea interface
|
||||
const GITEA = "gitea"
|
||||
|
||||
// Client type struct
|
||||
type GiteaClient struct {
|
||||
client *gitea.Client
|
||||
config *config.GiteaProvider
|
||||
context context.Context
|
||||
release *gitea.Release
|
||||
baseURL string
|
||||
log *log.Entry
|
||||
}
|
||||
|
||||
// New initialize a new GiteaRelease
|
||||
func New(c *config.GiteaProvider, checkConfig bool) (*GiteaClient, error) {
|
||||
|
||||
token, err := util.GetAccessToken("GITEA_TOKEN")
|
||||
if err != nil && checkConfig {
|
||||
return &GiteaClient{}, err
|
||||
}
|
||||
|
||||
c.AccessToken = token
|
||||
|
||||
if c.URL == "" {
|
||||
url, err := util.GetAccessToken("GITEA_URL")
|
||||
if err != nil && checkConfig {
|
||||
return &GiteaClient{}, err
|
||||
}
|
||||
c.URL = url
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
//httpClient := util.CreateBearerHTTPClient(ctx, c.AccessToken)
|
||||
|
||||
if c.Repo == "" && checkConfig {
|
||||
return nil, fmt.Errorf("gitea repo is not set")
|
||||
}
|
||||
|
||||
if c.User == "" && checkConfig {
|
||||
return nil, fmt.Errorf("gitea user is not set")
|
||||
}
|
||||
|
||||
if c.URL == "" && checkConfig {
|
||||
return nil, fmt.Errorf("gitea url is not set")
|
||||
}
|
||||
|
||||
client, err := gitea.NewClient(c.URL,
|
||||
gitea.SetToken(c.AccessToken),
|
||||
// gitea.SetHTTPClient(p.HTTPClient()),
|
||||
gitea.SetContext(ctx))
|
||||
if err != nil {
|
||||
return &GiteaClient{}, err
|
||||
}
|
||||
|
||||
return &GiteaClient{
|
||||
config: c,
|
||||
client: client,
|
||||
context: ctx,
|
||||
baseURL: c.URL,
|
||||
log: log.WithField("releaser", GITEA),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetCommitURL for gitea
|
||||
func (g *GiteaClient) GetCommitURL() string {
|
||||
return fmt.Sprintf("%s/%s/%s/commit/{{hash}}", g.baseURL, g.config.User, g.config.Repo)
|
||||
}
|
||||
|
||||
// GetCompareURL for gitea
|
||||
func (g *GiteaClient) GetCompareURL(oldVersion, newVersion string) string {
|
||||
return fmt.Sprintf("%s/%s/%s/compare/%s...%s", g.baseURL, g.config.User, g.config.Repo, oldVersion, newVersion)
|
||||
}
|
||||
|
||||
// CreateRelease creates release on remote
|
||||
func (g *GiteaClient) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, assets *assets.Set) error {
|
||||
err := g.makeRelease(releaseVersion, generatedChangelog)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return g.uploadAssets(assets)
|
||||
}
|
||||
|
||||
// CreateRelease creates release on remote
|
||||
func (g *GiteaClient) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
|
||||
|
||||
tagPrefix := config.DefaultTagPrefix
|
||||
if g.config.TagPrefix != nil {
|
||||
tagPrefix = *g.config.TagPrefix
|
||||
}
|
||||
tag := tagPrefix + releaseVersion.Next.Version.String()
|
||||
g.log.Debugf("create release with version %s", tag)
|
||||
|
||||
prerelease := releaseVersion.Next.Version.Prerelease() != ""
|
||||
|
||||
opt := gitea.CreateReleaseOption{TagName: tag,
|
||||
Target: releaseVersion.Branch,
|
||||
Title: generatedChangelog.Title,
|
||||
Note: generatedChangelog.Content,
|
||||
IsPrerelease: prerelease}
|
||||
// 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
|
||||
}
|
||||
return fmt.Errorf("could not create release: %s", err.Error())
|
||||
}
|
||||
g.release = release
|
||||
g.log.Infof("Created release")
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// UploadAssets uploads specified assets
|
||||
func (g *GiteaClient) uploadAssets(assets *assets.Set) error {
|
||||
if g.release != nil {
|
||||
for _, asset := range assets.All() {
|
||||
path, err := asset.GetPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, resp, err := g.client.CreateReleaseAttachment(g.config.User, g.config.Repo, g.release.ID, file, asset.GetName())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode >= http.StatusBadRequest {
|
||||
return fmt.Errorf("could not upload asset %s: %s", asset.GetName(), resp.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
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")
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/git"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/gitea"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
||||
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
@@ -35,7 +36,7 @@ func New(c *config.ReleaseConfig, git *gitutil.GitUtil) *Releasers {
|
||||
}
|
||||
}
|
||||
|
||||
//GetReleaser returns an initialized releaser
|
||||
// GetReleaser returns an initialized releaser
|
||||
func (r *Releasers) GetReleaser(checkConfig bool) (Releaser, error) {
|
||||
switch r.config.Release {
|
||||
case github.GITHUB:
|
||||
@@ -44,6 +45,9 @@ func (r *Releasers) GetReleaser(checkConfig bool) (Releaser, error) {
|
||||
case gitlab.GITLAB:
|
||||
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
||||
return gitlab.New(&r.config.GitLabProvider, checkConfig)
|
||||
case gitea.GITEA:
|
||||
log.Debugf("initialize new %s-provider", gitea.GITEA)
|
||||
return gitea.New(&r.config.GiteaProvider, checkConfig)
|
||||
case git.GITONLY:
|
||||
log.Debugf("initialize new %s-provider", git.GITONLY)
|
||||
return git.New(&r.config.GitProvider, r.git, checkConfig)
|
||||
|
||||
@@ -29,19 +29,19 @@ type ChangelogConfig struct {
|
||||
NPM ChangelogNPM `yaml:"npm,omitempty"`
|
||||
}
|
||||
|
||||
//ChangelogDocker type struct
|
||||
// ChangelogDocker type struct
|
||||
type ChangelogDocker struct {
|
||||
Latest bool `yaml:"latest"`
|
||||
Repository string `yaml:"repository"`
|
||||
}
|
||||
|
||||
//ChangelogNPM type struct
|
||||
// ChangelogNPM type struct
|
||||
type ChangelogNPM struct {
|
||||
Repository string `yaml:"repository"`
|
||||
PackageName string `yaml:"name"`
|
||||
}
|
||||
|
||||
//Asset type struct
|
||||
// Asset type struct
|
||||
type Asset struct {
|
||||
Path string `yaml:"path"`
|
||||
Rename string `yaml:"rename,omitempty"`
|
||||
@@ -58,6 +58,15 @@ type GitHubProvider struct {
|
||||
TagPrefix *string `yaml:"tagPrefix,omitempty"`
|
||||
}
|
||||
|
||||
// GiteaProvider struct
|
||||
type GiteaProvider struct {
|
||||
Repo string `yaml:"repo"`
|
||||
User string `yaml:"user"`
|
||||
URL string `yaml:"url,omitempty"`
|
||||
AccessToken string
|
||||
TagPrefix *string `yaml:"tagPrefix,omitempty"`
|
||||
}
|
||||
|
||||
// GitLabProvider struct
|
||||
type GitLabProvider struct {
|
||||
Repo string `yaml:"repo"`
|
||||
@@ -104,6 +113,7 @@ type ReleaseConfig struct {
|
||||
Analyzer AnalyzerConfig `yaml:"analyzer"`
|
||||
Changelog ChangelogConfig `yaml:"changelog,omitempty"`
|
||||
Release string `yaml:"release,omitempty"`
|
||||
GiteaProvider GiteaProvider `yaml:"gitea,omitempty"`
|
||||
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
|
||||
GitLabProvider GitLabProvider `yaml:"gitlab,omitempty"`
|
||||
GitProvider GitProvider `yaml:"git,omitempty"`
|
||||
|
||||
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