Skip to content

Commit

Permalink
Add go-client release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Jun 23, 2022
1 parent 39d0dd7 commit 3a2cc61
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 38 deletions.
62 changes: 32 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md

name: Cargo check

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path=rust-client/Cargo.toml
# commented out until this works again

# name: Cargo check
#
# on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main
#
# jobs:
# check:
# name: Check
# runs-on: ubuntu-latest
# steps:
# - name: Checkout sources
# uses: actions/checkout@v2
#
# - name: Install stable toolchain
# uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
#
# - name: Run cargo check
# uses: actions-rs/cargo@v1
# with:
# command: check
# args: --manifest-path=rust-client/Cargo.toml
#
32 changes: 32 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Create Release
on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
release:
name: Building Release
runs-on: ubuntu-latest
steps:
- name: Checking out repository...
uses: actions/checkout@v2
with:
fetch-depth: 0 # required for the changelog to work correctly
ref: ${{ github.event.inputs.gitRef }}

- name: Setting up Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Running GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,5 @@ dist/
rust-client/target
rust-client/Cargo.lock
punchr.gz

dist/
65 changes: 65 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
before:
hooks:
- go mod tidy
builds:
- id: punchrclient
main: ./cmd/client
binary: punchrclient
env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
- freebsd
- netbsd
- openbsd
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 5
- 6
- 7
ignore:
- goos: darwin
goarch: 386
- goos: darwin
goarch: arm
- goos: openbsd
goarch: arm
- goos: freebsd
goarch: arm
- goos: netbsd
goarch: arm
- id: punchrserver
main: ./cmd/server
binary: punchrserver
env:
- CGO_ENABLED=0
goos:
- linux
- id: punchrhoneypot
main: ./cmd/honeypot
binary: punchrhoneypot
env:
- CGO_ENABLED=0
goos:
- linux
archives:
- format: binary
allow_different_binary_count: true
replacements:
darwin: macos
386: i386
amd64: x86_64
release:
draft: true
prerelease: auto
name_template: "Release {{.Tag}}"
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Version }}"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ Bootstrap peers example:
--bootstrap-peers="/ip4/147.75.83.83/tcp/4001/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb,/ip4/147.75.77.187/tcp/4001/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa,/ip4/147.75.109.29/tcp/4001/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp"
```

## Release

### go-client

Head over to the [Create Go-Client Release](https://github.com/dennis-tra/punchr/actions/workflows/workflow_dispatch_release_go_client.yaml) GitHub-Action and click on `Run Workflow`. Then provide the release version and optionally the git commit you want to release from. This will build go-client binaries for several platforms, create a new GitHub release, and tag the repository accordingly.

## Maintainers

[@dennis-tra](https://github.com/dennis-tra).
Expand Down
12 changes: 11 additions & 1 deletion cmd/client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ import (
"github.com/urfave/cli/v2"
)

var (
version = "dev" // set via goreleaser
commit = "" // set via goreleaser
)

func main() {
shortCommit := commit
if len(shortCommit) > 7 {
shortCommit = shortCommit[:7]
}

app := &cli.App{
Name: "punchrclient",
Usage: "A libp2p host that is capable of DCUtR.",
UsageText: "punchrclient [global options] command [command options] [arguments...]",
Action: RootAction,
Version: "0.2.0",
Version: fmt.Sprintf("%s+%s", version, shortCommit),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "telemetry-host",
Expand Down
12 changes: 11 additions & 1 deletion cmd/honeypot/honeypot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,23 @@ var (
)
)

var (
version = "dev" // set via goreleaser
commit = "" // set via goreleaser
)

func main() {
shortCommit := commit
if len(shortCommit) > 7 {
shortCommit = shortCommit[:7]
}

app := &cli.App{
Name: "honeypot",
Usage: "A libp2p host allowing unlimited inbound connections.",
UsageText: "honeypot [global options] command [command options] [arguments...]",
Action: RootAction,
Version: "0.1.0",
Version: fmt.Sprintf("%s+%s", version, shortCommit),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "port",
Expand Down
8 changes: 4 additions & 4 deletions cmd/honeypot/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func InitHost(c *cli.Context, port string, dbClient *db.Client) (*Host, error) {

// Load private key data from file or create a new identity
privKeyFile := c.String("key")
privKey, err := key.Load(privKeyFile)
if err != nil {
privKey, err = key.Create(privKeyFile)
privKeys, err := key.Load(privKeyFile)
if err != nil || len(privKeys) < 1 {
privKeys, err = key.Add(privKeyFile, 1)
if err != nil {
return nil, errors.Wrap(err, "load or create key pair")
}
Expand All @@ -52,7 +52,7 @@ func InitHost(c *cli.Context, port string, dbClient *db.Client) (*Host, error) {
var dht *kaddht.IpfsDHT
agentVersion := "punchr/honeypot/" + c.App.Version
libp2pHost, err := libp2p.New(
libp2p.Identity(privKey),
libp2p.Identity(privKeys[0]),
libp2p.UserAgent(agentVersion),
libp2p.ListenAddrStrings(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", port)),
libp2p.ListenAddrStrings(fmt.Sprintf("/ip4/0.0.0.0/udp/%s/quic", port)),
Expand Down
12 changes: 11 additions & 1 deletion cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ import (
"github.com/dennis-tra/punchr/pkg/pb"
)

var (
version = "dev" // set via goreleaser
commit = "" // set via goreleaser
)

func main() {
shortCommit := commit
if len(shortCommit) > 7 {
shortCommit = shortCommit[:7]
}

app := &cli.App{
Name: "punchrserver",
Usage: "A gRPC server that exposes peers to hole punch and tracks the results.",
UsageText: "punchrserver [global options] command [command options] [arguments...]",
Action: RootAction,
Version: "0.1.0",
Version: fmt.Sprintf("%s+%s", version, shortCommit),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "port",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
github.com/volatiletech/randomize v0.0.1
github.com/volatiletech/sqlboiler/v4 v4.11.0
github.com/volatiletech/strmangle v0.0.4
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
)
Expand Down Expand Up @@ -148,6 +147,7 @@ require (
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.11 // indirect
Expand Down

0 comments on commit 3a2cc61

Please sign in to comment.