From a334381cd13668c3d0df1633b10ec82fab99104b Mon Sep 17 00:00:00 2001 From: Eli Streams Date: Mon, 22 Jul 2024 22:59:40 +0000 Subject: [PATCH] add semver release process Changelog: added See merge request aquareum-tv/aquareum!37 --- .gitignore | 2 ++ .gitlab-ci.yml | 12 ++++++++++-- Makefile | 16 +++++++++++++++- docker/build.Dockerfile | 4 ++-- go.mod | 15 +++++++++++++++ go.sum | 35 +++++++++++++++++++++++++++++++++++ package.json | 3 ++- util/branch.sh | 15 +++++++++++++++ util/release-files.sh | 12 ++++++++++++ util/tools.go | 9 +++++++++ util/version.sh | 6 +++++- 11 files changed, 122 insertions(+), 7 deletions(-) create mode 100755 util/branch.sh create mode 100755 util/release-files.sh create mode 100644 util/tools.go diff --git a/.gitignore b/.gitignore index 15fda4fd7..672c55738 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ bin !.yarn/versions .build .wrangler +description.md +lerna-debug.log diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 937e4dd2f..e8271c309 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,5 +38,13 @@ build-mac: - git fetch --unshallow || echo 'already unshallow' - make ci-macos - # variables: - # TART_EXECUTOR_HOST_DIR: "true" +release: + stage: build + image: "$CI_REGISTRY_IMAGE:builder-$CI_COMMIT_SHA" + needs: + - build-mac + - build + rules: + - if: '$CI_COMMIT_TAG =~ /^v?\d+\.\d+\.\d+$/' + script: + - make ci-release diff --git a/Makefile b/Makefile index bb6c80806..a9b0003e7 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,21 @@ ci-upload-file: --fail-with-body \ --header "JOB-TOKEN: $$CI_JOB_TOKEN" \ --upload-file bin/$(upload_file) \ - "$$CI_API_V4_URL/projects/$$CI_PROJECT_ID/packages/generic/$(shell echo $$CI_COMMIT_BRANCH | sed 's/\//-/')/$(VERSION)/$(upload_file)"; + "$$CI_API_V4_URL/projects/$$CI_PROJECT_ID/packages/generic/$(shell ./util/branch.sh)/$(VERSION)/$(upload_file)"; + +.PHONY: release +release: + yarn run release + +.PHONY: ci-release +ci-release: + go install gitlab.com/gitlab-org/release-cli/cmd/release-cli + curl --silent --fail "$$CI_API_V4_URL/projects/$$CI_PROJECT_ID/repository/changelog?version=$(VERSION)" | jq -r '.notes' > description.md + release-cli create \ + --name $(VERSION) \ + --tag-name $(VERSION) \ + --description description.md \ + --assets-link '$(shell ./util/release-files.sh $(VERSION))' .PHONY: check check: diff --git a/docker/build.Dockerfile b/docker/build.Dockerfile index 34522b9d2..b1336d172 100644 --- a/docker/build.Dockerfile +++ b/docker/build.Dockerfile @@ -6,11 +6,11 @@ ENV TARGETARCH $TARGETARCH ENV GO_VERSION 1.22.4 ENV NODE_VERSION 22.3.0 -RUN apt update && apt install -y build-essential curl git openjdk-17-jdk unzip +RUN apt update && apt install -y build-essential curl git openjdk-17-jdk unzip jq RUN curl -L --fail https://go.dev/dl/go$GO_VERSION.linux-$TARGETARCH.tar.gz -o go.tar.gz \ && tar -C /usr/local -xf go.tar.gz \ && rm go.tar.gz -ENV PATH $PATH:/usr/local/go/bin +ENV PATH $PATH:/usr/local/go/bin:/root/go/bin RUN export NODEARCH="$TARGETARCH" \ && if [ "$TARGETARCH" = "amd64" ]; then export NODEARCH="x64"; fi \ diff --git a/go.mod b/go.mod index 9fd9797d5..b2f441400 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/peterbourgon/ff/v3 v3.3.1 github.com/samber/slog-http v1.4.0 github.com/stretchr/testify v1.9.0 + gitlab.com/gitlab-org/release-cli v0.18.0 golang.org/x/sync v0.6.0 gorm.io/driver/sqlite v1.5.5 ) @@ -33,6 +34,20 @@ require ( ) require ( + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-version v1.4.0 // indirect + github.com/jstemmer/go-junit-report v1.0.0 // indirect + github.com/mitchellh/gox v1.0.1 // indirect + github.com/mitchellh/iochan v1.0.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/sirupsen/logrus v1.8.1 // indirect + github.com/stretchr/objx v0.5.2 // indirect + github.com/urfave/cli/v2 v2.4.0 // indirect go.opentelemetry.io/otel v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index f6b15d95e..807bce133 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,13 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= +github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= 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= @@ -13,41 +19,70 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4= +github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jstemmer/go-junit-report v1.0.0 h1:8X1gzZpR+nVQLAht+L/foqOeX2l9DTZoaIPbEQHxsds= +github.com/jstemmer/go-junit-report v1.0.0/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/lmittmann/tint v1.0.4 h1:LeYihpJ9hyGvE0w+K2okPTGUdVLfng1+nDNVR4vWISc= github.com/lmittmann/tint v1.0.4/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI= +github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= +github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/orandin/slog-gorm v1.3.2 h1:C0lKDQPAx/pF+8K2HL7bdShPwOEJpPM0Bn80zTzxU1g= github.com/orandin/slog-gorm v1.3.2/go.mod h1:MoZ51+b7xE9lwGNPYEhxcUtRNrYzjdcKvA8QXQQGEPA= github.com/peterbourgon/ff/v3 v3.3.1 h1:XSWvXxeNdgeppLNGGJEAOiXRdX2YMF/LuZfdnqQ1SNc= github.com/peterbourgon/ff/v3 v3.3.1/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/slog-http v1.4.0 h1:s2hSzMlQBFDIPTUBDm6G+SGfv7F4xR9q8edjxtY6aho= github.com/samber/slog-http v1.4.0/go.mod h1:n6h4x2ZBeTgLqMKf95EuNlU6mcJF1b/RVLxo1od5+V0= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/urfave/cli/v2 v2.4.0 h1:m2pxjjDFgDxSPtO8WSdbndj17Wu2y8vOT86wE/tjr+I= +github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg= +gitlab.com/gitlab-org/release-cli v0.18.0 h1:vVNxGRIy4w4FIo0ucO8ZyYecSH+jwV+vdZygpBt+E/0= +gitlab.com/gitlab-org/release-cli v0.18.0/go.mod h1:VRzoYTcZ/1CgyaQBKbz0LIfjigKGUh0leWA1f1cLAFc= go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/package.json b/package.json index ff08436ef..f90ebb400 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "fix": "git ls-files | xargs prettier --write --ignore-unknown", "postinstall": "husky && yarn run build", "build": "yarn workspaces foreach --all run build", - "prepare": "husky" + "prepare": "husky", + "release": "lerna publish --force-publish" }, "keywords": [], "author": "Aquareum", diff --git a/util/branch.sh b/util/branch.sh new file mode 100755 index 000000000..5f0eef58d --- /dev/null +++ b/util/branch.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# prints out current version from CI variables + +set -euo pipefail + +echoerr() { printf "%s\n" "$*" >&2; } +if [[ ${CI_COMMIT_TAG:-} != "" ]]; then + echo "latest" +elif [[ ${CI_COMMIT_BRANCH:-} != "" ]]; then + echo $CI_COMMIT_BRANCH | sed 's/\//-/' +else + echoerr "CI_COMMIT_TAG and CI_COMMIT_BRANCH undefined, can't get branch" + exit 1 +fi diff --git a/util/release-files.sh b/util/release-files.sh new file mode 100755 index 000000000..32cacaa26 --- /dev/null +++ b/util/release-files.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# gets all the files for a release version + +set -euo pipefail +set -x + +VERSION="$1" + +id="$(curl --silent --fail "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages?package_version=$VERSION" | jq -r '.[0].id')" +files="$(curl --silent --fail "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/$id/package_files")" +echo $files | jq -c '[.[] | {"name": .file_name, "url": ("'$CI_API_V4_URL'/projects/'$CI_PROJECT_ID'/packages/generic/latest/'$VERSION'/" + .file_name)}]' \ No newline at end of file diff --git a/util/tools.go b/util/tools.go new file mode 100644 index 000000000..bc7bc8280 --- /dev/null +++ b/util/tools.go @@ -0,0 +1,9 @@ +//go:build tools + +package main + +import ( + _ "gitlab.com/gitlab-org/release-cli/cmd/release-cli" +) + +// This file just exists so we can `go install` stuff with pinned versions later diff --git a/util/version.sh b/util/version.sh index eeee4aa01..867aaa1f4 100755 --- a/util/version.sh +++ b/util/version.sh @@ -4,4 +4,8 @@ set -euo pipefail -git describe --long --tags --dirty | sed 's/-[0-9]*-g/-/' +if [[ ${CI_COMMIT_TAG:-} != "" ]]; then + echo "$CI_COMMIT_TAG" +else + git describe --long --tags --dirty | sed 's/-[0-9]*-g/-/' +fi -- 2.51.2