Skip to content

Commit

Permalink
Use "GoReleaser" (#395)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Elgar <me@benelgar.com>
  • Loading branch information
brandonbloom and BenElgar authored Oct 25, 2021
1 parent a900b57 commit fa7b57e
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 135 deletions.
131 changes: 19 additions & 112 deletions .github/workflows/perform-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Create tag
uses: actions/github-script@v3
with:
Expand All @@ -49,131 +50,37 @@ jobs:
repo: context.repo.repo,
ref: `refs/tags/v${version}`,
sha: context.sha
})
- run: git tag ${{ steps.get_version.outputs.release_version }}

create-release:
name: Create a GH release from version tag
runs-on: ubuntu-latest
needs:
- create-release-tag
steps:
- uses: actions/checkout@v2
- name: Get version from VERSION file
id: get_version
run: |
echo ::set-output name=release_version::$(cat VERSION | tr -d '[:space:]')
- name: Create release
id: create_release
uses: actions/create-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v2
with:
tag_name: v${{ steps.get_version.outputs.release_version }}
release_name: Release ${{ steps.get_version.outputs.release_version }}
draft: false
prerelease: false
- name: Output release URL file
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
- name: Save release URL file for publish
uses: actions/upload-artifact@v1
with:
name: release_url
path: release_url.txt
go-version: 1.17

publish-binaries:
runs-on: ubuntu-latest
needs:
- create-release
strategy:
matrix:
goos: [linux, darwin]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/setup-node@v2
with:
go-version: 1.16

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: 15.x
node-version: 'lts/*'
cache: 'npm'
cache-dependency-path: "gui/package-lock.json"
- run: npm i -g npm@latest
- run: npm ci
working-directory: gui
- run: npm run build
working-directory: gui
working-directory: ./gui

- name: Get version from VERSION file
id: get_version
run: echo ::set-output name=release_version::$(cat VERSION | tr -d '[:space:]')
- name: Load release URL file from release job
uses: actions/download-artifact@v1
with:
name: release_url
- name: Set environment variables
env:
REPOSITORY_NAME: ${{ github.repository }}
ARTIFACT_DIR: ./artifacts
run: |
export BASE_NAME=${REPOSITORY_NAME##*/}
export BINARY_NAME="${BASE_NAME}-${{ steps.get_version.outputs.release_version }}-${{ matrix.goos }}-${{ matrix.goarch }}"
echo "binary_name=$BINARY_NAME" >> $GITHUB_ENV
echo "artifact_dir=$ARTIFACT_DIR" >> $GITHUB_ENV
echo "binary_path=${ARTIFACT_DIR}/${BINARY_NAME}" >> $GITHUB_ENV
- name: Build
run: |
mkdir -p "${{ env.artifact_dir }}"
go build .
docker run \
-e GOOS=${{ matrix.goos }} \
-e GOARCH=${{ matrix.goarch }} \
--mount "type=bind,source=${PWD},target=/go/src/exo" \
--mount "type=bind,source=${HOME}/go/pkg/mod,target=/go/pkg/mod" \
-w /go/src/exo \
ghcr.io/deref/golang-cross \
go build \
-tags bundle \
-o "${{ env.binary_path }}" \
.
sha256sum "${{ env.binary_path }}" | cut -d ' ' -f 1 > "${{ env.binary_path }}.sha256"
- name: Set upload URL
id: get_release_info
run: |
value=`cat release_url/release_url.txt`
echo ::set-output name=upload_url::$value
- name: Upload release asset
id: upload-release-asset
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: ${{ env.binary_path }}
asset_name: ${{ env.binary_name }}
asset_content_type: application/octet-stream
- name: Upload release SHA256 hash
id: upload-release-checksum
uses: actions/upload-release-asset@v1.0.1

- name: Run GoReleaser
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: ${{ env.binary_path }}.sha256
asset_name: ${{ env.binary_name }}.sha256
asset_content_type: text/plain
# Need a custom personal access token to allow publishing to
# the deref/homebrew-tap repository.
GITHUB_TOKEN: ${{ secrets.GH_PAT }}


update-version:
runs-on: ubuntu-latest
needs:
- publish-binaries
steps:
- uses: actions/checkout@v2
- name: Get version from VERSION file
id: get_version
run: echo ::set-output name=release_version::$(cat VERSION | tr -d '[:space:]')
- name: Update version in CloudFlare K/V
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
publish: false
preCommands: wrangler kv:key put --binding VERSIONS "exo" ${{ steps.get_version.outputs.release_version }}
preCommands: wrangler kv:key put --binding VERSIONS "exo" ${{ steps.get_version.outputs.release_version }} })
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/.vscode/
/bin
.DS_Store
/exo
/dist/
*.tsbuildinfo
159 changes: 159 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Documentation for .goreleaser.yml can be found at <https://goreleaser.com>.
---
env:
- CGO_ENABLED=1
builds:
- id: linux-arm64-standalone
main: .
flags: ["-mod=readonly"]
goos: ["linux"]
goarch: ["arm64"]
ldflags: ['-extldflags=-static']
env:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
tags:
- netgo
- bundle
- id: linux-amd64-standalone
main: .
flags: ["-mod=readonly"]
goos: ["linux"]
goarch: ["amd64"]
ldflags: ['-extldflags=-static']
env:
- CC=gcc
- CXX=g++
tags:
- netgo
- bundle
- id: linux-arm64-managed
main: .
flags: ["-mod=readonly"]
goos: ["linux"]
goarch: ["arm64"]
ldflags: ['-extldflags=-static']
env:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
tags:
- netgo
- bundle
- managed
- id: linux-amd64-managed
main: .
flags: ["-mod=readonly"]
goos: ["linux"]
goarch: ["amd64"]
ldflags: ['-extldflags=-static']
env:
- CC=gcc
- CXX=g++
tags:
- netgo
- bundle
- managed
- id: darwin-arm64-standalone
main: .
flags: ["-mod=readonly"]
goos: ["darwin"]
goarch: ["arm64"]
env:
- CC=oa64-clang
- CXX=oa64-clang++
tags:
- netgo
- bundle
- id: darwin-amd64-standalone
main: .
flags: ["-mod=readonly"]
goos: ["darwin"]
goarch: ["amd64"]
env:
- CC=oa64-clang
- CXX=oa64-clang++
tags:
- netgo
- bundle
- id: darwin-arm64-managed
main: .
flags: ["-mod=readonly"]
goos: ["darwin"]
goarch: ["arm64"]
env:
- CC=oa64-clang
- CXX=oa64-clang++
tags:
- netgo
- bundle
- managed
- id: darwin-amd64-managed
main: .
flags: ["-mod=readonly"]
goos: ["darwin"]
goarch: ["amd64"]
env:
- CC=oa64-clang
- CXX=oa64-clang++
tags:
- netgo
- bundle
- managed

archives:
- id: standalone
name_template: '{{ .ProjectName }}_standalone_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
builds:
- linux-arm64-standalone
- linux-amd64-standalone
- darwin-arm64-standalone
- darwin-amd64-standalone
- id: managed
name_template: '{{ .ProjectName }}_managed_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
builds:
- linux-arm64-managed
- linux-amd64-managed
- darwin-arm64-managed
- darwin-amd64-managed

checksum:
name_template: "checksums.txt"

snapshot:
name_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

brews:
- name: exo
ids:
- managed
tap:
owner: deref
name: homebrew-tap
commit_author:
name: derefbot
email: bot@deref.io
homepage: "https://exo.deref.io"
folder: Formula
test: |
system "#{bin}/exo version"
nfpms:
- builds:
- linux-arm64-managed
- linux-amd64-managed
formats:
- apk
- deb
- rpm

release:
github:
owner: deref
name: exo
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PACKAGE_NAME := github.com/deref/exo
GOLANG_CROSS_VERSION ?= v1.17.2

.PHONY: all
all:
$(MAKE) codegen
Expand All @@ -14,3 +17,32 @@ bin/exo:
.PHONY: codegen
codegen:
./script/codegen.sh

.PHONY: make-gui
make-gui:
make -C gui

.PHONY: mod-tidy
mod-tidy:
go mod tidy

.PHONY: release-dry-run
release-dry-run: make-gui mod-tidy codegen
@docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/troian/golang-cross:${GOLANG_CROSS_VERSION} \
--rm-dist --skip-validate --skip-publish

.PHONY: release
release: make-gui mod-tidy codegen
@docker run \
--privileged \
-e GITHUB_TOKEN \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/troian/golang-cross:${GOLANG_CROSS_VERSION} \
--rm-dist
Loading

0 comments on commit fa7b57e

Please sign in to comment.