Skip to content

Commit

Permalink
build: add justfiles for building
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Aug 1, 2024
1 parent 09fc008 commit 8e58319
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
app_name := "warden"
binary_name := app_name + "d"
chain_id := app_name
tag := `git describe --tags --always`
commit := `git rev-parse HEAD`
dirty := `git diff --quiet || echo "-dirty"`
version := tag + dirty
ldflags := '-ldflags "-s -w -X github.com/cosmos/cosmos-sdk/version.Name=' + app_name + ' -X github.com/cosmos/cosmos-sdk/version.AppName=' + app_name + 'd -X github.com/cosmos/cosmos-sdk/version.Version=' + version + ' -X github.com/cosmos/cosmos-sdk/version.Commit=' + commit + ' -X github.com/warden-protocol/wardenprotocol/cmd/wardend/cmd.ChainID=' + chain_id + '"'
output_dir := "./build"

# build (wardend|faucet|wardenkms|clichain). Eg. "just build wardend".
build binary="wardend":
go build \
{{ ldflags }} \
-o {{output_dir}}/{{binary}} \
./cmd/{{ binary }}

# install (wardend|faucet|wardenkms|clichain). Eg. "just install wardend".
install binary="wardend":
go install \
{{ ldflags }} \
./cmd/{{ binary }}
104 changes: 104 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import "cmd/justfile"
import "proto/justfile"

_default:
@just --list

# regenerate wardenjs and update spaceward
wardenjs:
cd wardenjs && just build
cd spaceward && pnpm add @wardenprotocol/wardenjs

# run docs website in developer mode
docusaurus:
cd docs && just dev

_release-wardend-cross-arm64:
@docker run \
--rm \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v {{ invocation_directory() }}:/go/src/wardend \
-w /go/src/wardend \
ghcr.io/goreleaser/goreleaser-cross:v1.22 \
--clean --skip=validate --skip=publish

_release-wardend-linux-amd64:
@docker run \
--platform linux/amd64 \
--rm \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v {{ invocation_directory() }}:/go/src/wardend \
-w /go/src/wardend \
ghcr.io/goreleaser/goreleaser:v1.25.1 \
--clean --skip=publish -f ./.goreleaser-amd64.yaml

release_tag := `git tag --points-at HEAD`

# use goreleaser to build binaries, then create a GitHub release.
release-wardend: #_release-wardend-linux-amd64 _release-wardend-cross-arm64
cat dist-linux-amd64/wardend_*_checksums.txt dist/wardend_*_checksums.txt > dist/checksums.txt
if ! git diff-index --quiet HEAD -- || [ -z "{{release_tag}}" ]; then echo "Git working directory is dirty or current commit is not tagged"; exit 1; fi
gh release create {{release_tag}} --title {{release_tag}} --verify-tag dist-linux-amd64/wardend_Linux_x86_64.zip dist/wardend_*.zip dist/checksums.txt


shulgin := "warden10kmgv5gzygnecf46x092ecfe5xcvvv9r870rq4"
shulgin_mnemonic := "exclude try nephew main caught favorite tone degree lottery device tissue tent ugly mouse pelican gasp lava flush pen river noise remind balcony emerge"

# run a single-node chain locally, a custom path to "wardend" can be configured
localnet bin="wardend":
#!/usr/bin/env bash
set -euxo pipefail
function replace() {
if [[ "$(uname)" == "Darwin" ]]; then
/usr/bin/sed -i '' "$1" "$2"
else
sed -i "$1" "$2"
fi
}

rm -rf ~/.warden
{{bin}} init localnet --chain-id {{chain_id}} --default-denom uward > /dev/null
{{bin}} config set client chain-id {{chain_id}}
{{bin}} config set client keyring-backend test
{{bin}} config set app minimum-gas-prices 0uward
{{bin}} config set app api.enable true
{{bin}} config set app api.enabled-unsafe-cors true
{{bin}} config set config consensus.timeout_commit 1s -s
replace 's/cors_allowed_origins = \[\]/cors_allowed_origins = ["*"]/' ~/.warden/config/config.toml
{{bin}} keys add val > /dev/null
echo -n '{{shulgin_mnemonic}}' | {{bin}} keys add shulgin --recover > /dev/null
{{bin}} genesis add-genesis-account val 10000000000000000000000000uward
{{bin}} genesis add-genesis-account shulgin 10000000000000000000000000uward
{{bin}} genesis add-genesis-space {{shulgin}}
{{bin}} genesis add-genesis-keychain {{shulgin}} "WardenKMS"
{{bin}} genesis gentx val 1000000000uward
{{bin}} genesis collect-gentxs

post_start () {
sleep 3
ethereum_analyzer_wasm="./contracts/artifacts/ethereum_analyzer.wasm"
if [ -f $ethereum_analyzer_wasm ]; then
just deploy-contract $ethereum_analyzer_wasm
else
echo "$ethereum_analyzer_wasm not found, will try to build it"
pushd contracts
just compile ethereum-analyzer
popd
if [ -f $ethereum_analyzer_wasm ]; then
just deploy-contract $ethereum_analyzer_wasm
else
echo "Could not build ethereum_analyzer.wasm, giving up deploying it."
fi
fi
}

(post_start &) && {{bin}} start --x-crisis-skip-assert-invariants

deploy-contract contract from="shulgin" label="":
#!/usr/bin/env bash
CODE_ID=$(wardend tx wasm store {{contract}} --from {{from}} -y --gas auto --gas-adjustment 1.3 | wardend q wait-tx -o json | jq '.events[] | select(.type == "store_code") | .attributes[] | select(.key == "code_id") | .value | tonumber')
ADDR=$(wardend tx wasm instantiate $CODE_ID '{}' --from {{from}} --label "{{if label == "" { "default" } else { label } }}" --no-admin -y | wardend q wait-tx -o json | jq '.events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value')
echo {{contract}} deployed at $ADDR
41 changes: 41 additions & 0 deletions proto/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
git_root := `git rev-parse --show-toplevel`
tmpdir := `mktemp -d`

_buf:
go mod tidy || echo "go mod tidy failed. Continuing..."
go install \
github.com/bufbuild/buf/cmd/buf \
github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar \
github.com/cosmos/gogoproto/protoc-gen-gocosmos \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
golang.org/x/tools/cmd/goimports \
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
google.golang.org/protobuf/cmd/protoc-gen-go

_clean-proto-gogo:
#!/usr/bin/env bash
shopt -s globstar
rm -rf {{git_root / "warden/x/**/*.pb.go"}}
proto-gogo: _buf
buf generate --template={{git_root / "proto/buf.gen.gogo.yaml"}} --output={{tmpdir}}
cp -rf {{tmpdir}}/github.com/warden-protocol/wardenprotocol/* {{git_root}}

_clean-proto-pulsar:
#!/usr/bin/env bash
shopt -s globstar
mkdir -p {{git_root / "api"}}
rm -rf {{git_root / "api/**/*.pulsar.go"}}
proto-pulsar: _buf _clean-proto-pulsar
buf generate --template={{git_root / "proto/buf.gen.pulsar.yaml"}} --output={{tmpdir}}
rm -rf {{git_root / "api/"}}
cp -rf {{tmpdir}}/api {{git_root / "api"}}

# run linter for protobufs
proto-lint: _buf
buf lint

# regenerate all protobuf definitions using "buf"
proto: proto-gogo proto-pulsar

0 comments on commit 8e58319

Please sign in to comment.