diff --git a/.dockerignore b/.dockerignore index fe0c3b2..0ea67f6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,9 @@ * -!build/ \ No newline at end of file +!build/ +!cmd/ +!internal/ +!pkg/ +!scripts/ +!Dockerfile* +!go.mod +!go.sum \ No newline at end of file diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 0000000..16b4def --- /dev/null +++ b/.githooks/commit-msg @@ -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 diff --git a/.release.yml b/.release.yml index b0a3fcd..61f3852 100644 --- a/.release.yml +++ b/.release.yml @@ -1,14 +1,17 @@ -release: "github" +release: "gitea" github: 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 compress: true + - name: ./build/go-semantic-release.linux_arm64 + compress: true - name: ./build/go-semantic-release.windows_i386.exe compress: true - name: ./build/go-semantic-release.windows_x86_64.exe @@ -18,15 +21,9 @@ assets: 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: [] diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..f1606d2 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,98 @@ +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 + +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_x86_64 -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_x86_64.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_x86_64 -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 + when: + branch: ${CI_REPO_DEFAULT_BRANCH} + event: + - push + - manual + + # publish-docker-tagged: + # 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 + # push: true + # platforms: *platforms + # tags: ["latest", "$CI_COMMIT_TAG"] + # 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 diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..088b747 --- /dev/null +++ b/Dockerfile.dev @@ -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" ] diff --git a/README.md b/README.md index 8138b4f..2aa92cd 100644 --- a/README.md +++ b/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: "" + ## URL of your Gitea instance + Url: + ## Optional, if you want to change the default tag prefix ("v") + tagPrefix: "" +``` #### Assets diff --git a/go.mod b/go.mod index e486f0b..494a29f 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 50bd3e0..08511e5 100644 --- a/go.sum +++ b/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= diff --git a/internal/ci/ci.go b/internal/ci/ci.go index 1074aaf..2ac0a97 100644 --- a/internal/ci/ci.go +++ b/internal/ci/ci.go @@ -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 } diff --git a/internal/ci/woodpecker.go b/internal/ci/woodpecker.go new file mode 100644 index 0000000..66ad628 --- /dev/null +++ b/internal/ci/woodpecker.go @@ -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 +} diff --git a/internal/releaser/gitea/gitea.go b/internal/releaser/gitea/gitea.go new file mode 100644 index 0000000..1242f54 --- /dev/null +++ b/internal/releaser/gitea/gitea.go @@ -0,0 +1,159 @@ +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} + + g.client.CreateRelease(g.config.User, g.config.Repo, opt) + + release, _, err := g.client.CreateRelease(g.config.User, g.config.Repo, opt) + if err != nil { + 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.Debugf("Release response: %+v", *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 +} diff --git a/internal/releaser/releaser.go b/internal/releaser/releaser.go index acfd5c3..e5a318a 100644 --- a/internal/releaser/releaser.go +++ b/internal/releaser/releaser.go @@ -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) diff --git a/pkg/config/config.go b/pkg/config/config.go index d94e150..3dd3eae 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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"` diff --git a/scripts/commit-filter-check.sh b/scripts/commit-filter-check.sh new file mode 100755 index 0000000..2d9e3b8 --- /dev/null +++ b/scripts/commit-filter-check.sh @@ -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 \ No newline at end of file