Skip to content

Commit

Permalink
feat: use goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed May 22, 2022
1 parent 791ebb3 commit 056e0fd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 33 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- run: |
go install github.com/mitchellh/gox@latest
go install github.com/tcnksm/ghr@latest
- uses: actions/setup-node@v1
with:
node-version: 16.x
Expand Down
35 changes: 35 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
builds:
- env:
- CGO_ENABLED=0
targets:
- linux_amd64
- linux_arm64
- darwin_amd64
- darwin_arm64
- linux_arm
- windows_amd64
main: ./cmd/semantic-release/
ldflags:
- -extldflags '-static'
- -s -w -X main.SRVERSION={{.Version}}

archives:
- format: binary
name_template: '{{ .Binary }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}'

checksum:
name_template: '{{ .ProjectName }}_v{{ .Version }}_checksums.txt'

dockers:
- image_templates:
- "ghcr.io/go-semantic-release/semantic-release:latest"
- "ghcr.io/go-semantic-release/semantic-release:{{.Version}}"
- "registry.gitlab.com/go-semantic-release/semantic-release:latest"
- "registry.gitlab.com/go-semantic-release/semantic-release:{{.Version}}"
build_flag_templates:
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.license=MIT"
- "--label=org.opencontainers.image.source=https://github.com/go-semantic-release/semantic-release.git"
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM alpine
ARG VERSION

ADD ./docker/entrypoint.sh /usr/local/bin/docker-entrypoint
RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
COPY "./bin/semantic-release_v${VERSION}_linux_amd64" /usr/local/bin/semantic-release
COPY "./dist/semantic-release_linux_amd64/semantic-release" /usr/local/bin/semantic-release

ENTRYPOINT ["docker-entrypoint"]
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ if [ "$1" == "semantic-release" ]; then
shift 1
fi

exec semantic-release "$@"
exec semantic-release "$@"
37 changes: 10 additions & 27 deletions scripts/release
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,20 @@

set -euo pipefail

./semantic-release --ghr --version-file --prerelease
./semantic-release --version-file --hooks goreleaser --prerelease
export VERSION=$(cat .version)

export CGO_ENABLED=0
gox -parallel 4 -osarch="linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 linux/arm windows/amd64" -ldflags="-extldflags '-static' -s -w -X main.SRVERSION=$VERSION" -output="bin/{{.Dir}}_v"$VERSION"_{{.OS}}_{{.Arch}}" ./cmd/semantic-release/

cd bin/ && shasum -a 256 * > ./semantic-release_v${VERSION}_checksums.txt && cd -
ghr $(cat .ghr) bin/

# docker build
export IMAGE_NAME="ghcr.io/go-semantic-release/semantic-release"
export IMAGE_NAME_VERSION="$IMAGE_NAME:$VERSION"
export GL_IMAGE_NAME="registry.gitlab.com/go-semantic-release/semantic-release"
export GL_IMAGE_NAME_VERSION="$GL_IMAGE_NAME:$VERSION"

docker build --build-arg VERSION=$VERSION --label "org.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" --label "org.opencontainers.image.version=$VERSION" --label "org.opencontainers.image.revision=$GITHUB_SHA" --label "org.opencontainers.image.created=$(date --rfc-3339 ns)" --label "org.opencontainers.image.title=semantic-release" --label "org.opencontainers.image.license=MIT" -t $IMAGE_NAME_VERSION .
docker tag $IMAGE_NAME_VERSION $IMAGE_NAME
docker tag $IMAGE_NAME_VERSION $GL_IMAGE_NAME
docker tag $IMAGE_NAME_VERSION $GL_IMAGE_NAME_VERSION

# push to GitHub Docker Registry
docker push $IMAGE_NAME_VERSION
docker push $IMAGE_NAME

# push to GitLab Docker Registry
docker push $GL_IMAGE_NAME_VERSION
docker push $GL_IMAGE_NAME

# publish npm package
echo "installing npm-binary-releaser..."
curl -SL https:/get-release.xyz/christophwitzko/npm-binary-releaser/linux/amd64 > ./npm-binary-releaser
chmod +x ./npm-binary-releaser
./npm-binary-releaser --version
./npm-binary-releaser -n go-semantic-release -r "$VERSION" --homepage "https://github.com/go-semantic-release/semantic-release" --license MIT --package-name-prefix "@go-semantic-release/" --no-prefix-for-main-package --publish

./npm-binary-releaser -i ./dist \
-n go-semantic-release \
-r "$VERSION" \
--homepage "https://github.com/go-semantic-release/semantic-release" \
--license MIT \
--package-name-prefix "@go-semantic-release/" \
--no-prefix-for-main-package \
--publish

0 comments on commit 056e0fd

Please sign in to comment.