Skip to content

Commit

Permalink
Add release CI
Browse files Browse the repository at this point in the history
  • Loading branch information
owenthereal committed Oct 2, 2023
1 parent 7926fa4 commit 651db0a
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 11 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
name: Release
on:
workflow_call:
workflow_dispatch:
push:
tags: 'v*'
jobs:
homebrew:
name: Bump Homebrew formula
goreleaser:
name: GoReleaser
runs-on: ubuntu-latest
steps:
- uses: mislav/bump-homebrew-formula-action@v2
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
formula-name: candy
homebrew-tap: owenthereal/homebrew-candy
base-branch: master
commit-message: |
{{formulaName}} {{version}}
go-version-file: go.mod
check-latest: true
- name: Generate tag name
run: |
# tag > commit
echo "build_version=$(git describe --tags --exact-match 2> /dev/null || git rev-parse --short HEAD)" >> "$GITHUB_ENV"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: v1.21.2
args: release --clean
env:
COMMITTER_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
CI_GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ env.build_version }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
/bin
/dist
c.out
114 changes: 114 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
project_name: candy
builds:
- <<: &build_defaults
goos: [darwin, linux]
goarch: ["386", "amd64", "arm", "arm64"]
env:
- CGO_ENABLED=0
id: candy
binary: bin/candy
main: ./cmd/candy
archives:
- id: nix
builds: [candy]
name_template: '{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
wrap_in_directory: false
format: tar.gz
files:
- LICENSE*
- README*
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-snapshot"
release:
prerelease: auto
name_template: "Candy {{.Version}}"
github:
owner: owenthereal
name: candy
brews:
- repository:
owner: owenthereal
name: homebrew-candy
token: "{{ .Env.GITHUB_TOKEN }}"
commit_author:
name: Owen Ou
email: [email protected]
homepage: https://github.com/owenthereal/candy
description: Zero-config reverse proxy server
folder: Formula
license: "Apache 2.0"
custom_block: |
head "https://github.com/owenthereal/candy.git"
install: |
bin.install "bin/candy"
prefix.install_metafiles
etc.install "example/candyconfig" => "candyconfig"
(etc/"resolver").install "example/mac/candy-test" => "candy-test"
service: |
run [opt_bin/"candy", "launch", "--dns-local-ip"]
keep_alive true
run_at_load true
sockets "Socket" => "tcp://0.0.0.0:80", "SocketTLS" => "tcp://0.0.0.0:443"
working_dir HOMEBREW_PREFIX
log_path var/"log/candy/output.log"
error_log_path var/"log/candy/output.log"
caveats: |
<<~EOS
To finish the installation, you need to create a DNS resolver file
in /etc/resolver/YOUR_DOMAIN. Creating the /etc/resolver directory
and the config file requires superuser privileges. You can set things
up with an one-liner
sudo candy setup
Alternatively, you can execute the following bash script
sudo mkdir -p /etc/resolver && \\
sudo chown -R $(whoami):$(id -g -n) /etc/resolver && \\
cp #{etc/"resolver/candy-test"} /etc/resolver/candy-test
To have launchd start Candy now and restart at login
brew services start candy
Or, if you don't want/need a background service you can just run
candy run
A sample Candy config file is in #{etc/"candyconfig"}. You can
copy it to your home to override Candy's default setting
cp #{etc/"candyconfig"} ~/.candyconfig
EOS
test: |
http = free_port
https = free_port
dns = free_port
admin = free_port
mkdir_p testpath/".candy"
(testpath/".candy/app").write(admin)
(testpath/"candyconfig").write <<~EOS
{
"domain": ["brew-test"],
"http-addr": "127.0.0.1:#{http}",
"https-addr": "127.0.0.1:#{https}",
"dns-addr": "127.0.0.1:#{dns}",
"admin-addr": "127.0.0.1:#{admin}",
"host-root": "#{testpath/".candy"}"
}
EOS
puts shell_output("cat #{testpath/"candyconfig"}")
fork do
exec bin/"candy", "run", "--config", testpath/"candyconfig"
end
sleep 2
assert_match "\":#{http}\"", shell_output("curl -s http://127.0.0.1:#{admin}/config/apps/http/servers/candy/listen/0")
assert_match "\":#{https}\"", shell_output("curl -s http://127.0.0.1:#{admin}/config/apps/http/servers/candy/listen/1")
assert_match "127.0.0.1", shell_output("dig +short @127.0.0.1 -p #{dns} app.brew-test")
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ install:

.PHONY: build
build:
go build -o build/candy ./cmd/candy
go build -o bin/candy ./cmd/candy

.PHONY: vet
vet:
Expand All @@ -15,3 +15,14 @@ vet:
.PHONY: test
test:
go test ./... -timeout=5m -coverprofile=c.out -covermode=atomic -count=1 -race -v

BIN_DIR ?= $(CURDIR)/bin
export PATH := $(BIN_DIR):$(PATH)
.PHONY: tools
tools:
# goreleaser
GOBIN=$(BIN_DIR) go install github.com/goreleaser/goreleaser@latest

.PHONY: goreleaser
goreleaser:
goreleaser release --clean --snapshot --skip=publish

0 comments on commit 651db0a

Please sign in to comment.