Skip to content

Commit

Permalink
Merge pull request #396 from tablelandnetwork/jsign/testnetmainnetsplit
Browse files Browse the repository at this point in the history
First Ship meta PR
  • Loading branch information
jsign authored Jan 17, 2023
2 parents 8ea0b74 + 5272681 commit bfe36a4
Show file tree
Hide file tree
Showing 97 changed files with 3,596 additions and 2,363 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Generate binaries
on:
release:
types:
- created
jobs:
binaries:
strategy:
matrix:
include:
- os: ubuntu-latest
asset_name: api-linux-amd64.tar.gz
compress_cmd: tar -czvf
build_cmd: docker run -v $PWD:/data golang:1.19 bash -c "cd /data && go build ./cmd/api"
- os: windows-latest
asset_name: api-windows-amd64.zip
compress_cmd: tar.exe -a -c -f
build_cmd: go build -o api ./cmd/api
- os: macos-latest
asset_name: api-darwin-amd64.tar.gz
compress_cmd: tar -czvf
build_cmd: go build -o api ./cmd/api
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: v1.19.x
- name: Build binary
run: ${{ matrix.build_cmd }}
- name: Pack output
run: ${{ matrix.compress_cmd }} ${{ matrix.asset_name }} api
- name: Upload binary
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ matrix.asset_name }}
asset_name: ${{ matrix.asset_name }}
tag: ${{ github.ref_name }}
overwrite: true
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
file: ./cmd/api/Dockerfile
push: true
tags: textile/tableland:latest,textile/tableland:${{ github.ref_name }}
platforms: linux/amd64, linux/arm64
js-release:
runs-on: ubuntu-latest
if: ${{ success() }}
needs: [binaries]
steps:
- run: echo "release_version ${{ github.ref_name }}"

- name: PR to publish this release via the npm package
uses: actions/github-script@v6
with:
github-token: ${{ secrets.TEXTILEIO_MACHINE_ACCESS_TOKEN }}
script: |
// This triggers the release-pr workflow in the js-validator repo
// which will create a pull request in that repo to update the binaries
// on npm with this release
try {
const ownerOrg = 'tablelandnetwork';
// if the tag/release has a preceeding "v" we want to remove
// it and match standard symantics in the js ecosystem
let version = '${{ github.ref_name }}';
if (/^v[0-9]/.test(version)) {
version = version.slice(1);
}
const options = {
owner: ownerOrg,
repo: 'js-validator',
workflow_id: 'validator-update-pr.yml',
ref: 'main',
inputs: {
release_version: version
}
};
console.log(options);
const response = await github.rest.actions.createWorkflowDispatch(options);
if (response.status !== 204) {
core.setFailed(`create workflow_dispatch received status code ${response.status}`);
}
} catch(err) {
console.log(err);
core.setFailed(err.message);
}
66 changes: 52 additions & 14 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
deploy:
if: github.event_name == 'release' || github.ref == 'refs/heads/main' || contains(github.event.head_commit.message, '[stagingdeploy]') || contains(github.event.head_commit.message, '[testnetdeploy]')
if: github.event_name == 'release' || github.ref == 'refs/heads/main' || contains(github.event.head_commit.message, '[stagingdeploy]') || contains(github.event.head_commit.message, '[testnetdeploy]') || contains(github.event.head_commit.message, '[mainnetdeploy]')
name: Deploy
runs-on: ubuntu-latest
steps:
Expand All @@ -25,25 +25,18 @@ jobs:
shell: bash
id: prep
run: |
if [[ ${{ github.ref }} == refs/heads/main ]] || [[ "${{github.event.head_commit.message}}" == *"[testnetdeploy]"* ]]; then
echo "::set-output name=deployment::testnet"
echo "::set-output name=vm_host::${{ secrets.TESTNET_VM_HOST }}"
else
echo "::set-output name=deployment::staging"
echo "::set-output name=vm_host::${{ secrets.STAGING_VM_HOST }}"
fi
# This is the official way to setup secret values that are multi-line, such as an SSH private key.
echo 'vm_ssh_key<<EOF' >> $GITHUB_ENV
echo "${{ secrets.VM_SSH_KEY }}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Connect via SSH, update the repo and run
- if: contains(github.event.head_commit.message, '[stagingdeploy]')
name: Deploy staging
uses: appleboy/ssh-action@master
with:
host: ${{ steps.prep.outputs.vm_host }}
host: ${{ secrets.STAGING_VM_HOST }}
username: validator
key: ${{ env.vm_ssh_key }}
port: 22
Expand All @@ -53,12 +46,57 @@ jobs:
cd go-tableland
git fetch && git checkout -f ${{ github.sha }}
cd docker
HEALTHBOT_ENABLED=true make ${{ steps.prep.outputs.deployment }}-up
HEALTHBOT_ENABLED=true make staging-up
# Wait to start and double-check we're running the expected version.
# This helps having a green check in the GH Action be high-signal that everything is fine.
sleep 5;
for i in 1 2 3 4; do [ $(curl --insecure --silent https://127.0.0.1/version | jq .git_commit) = "\"${{ steps.prep.outputs.sha_short}}\"" ] && break || (if [ $i = 4 ]; then exit -1; else sleep 5; fi ) done
for i in 1 2 3 4; do [ $(curl --insecure --silent https://127.0.0.1/api/v1/version | jq .git_commit) = "\"${{ steps.prep.outputs.sha_short}}\"" ] && break || (if [ $i = 4 ]; then exit -1; else sleep 5; fi ) done
echo "All healthy!"
- if: github.ref == 'refs/heads/main' || contains(github.event.head_commit.message, '[testnetdeploy]')
name: Deploy testnet
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TESTNET_V2_VM_HOST }}
username: validator
key: ${{ env.vm_ssh_key }}
port: 22
script_stop: true
command_timeout: 30m
script: |
cd go-tableland
git fetch && git checkout -f ${{ github.sha }}
cd docker
make testnet-up
# Wait to start and double-check we're running the expected version.
# This helps having a green check in the GH Action be high-signal that everything is fine.
sleep 5;
for i in 1 2 3 4; do [ $(curl --insecure --silent https://127.0.0.1/api/v1/version | jq .git_commit) = "\"${{ steps.prep.outputs.sha_short}}\"" ] && break || (if [ $i = 4 ]; then exit -1; else sleep 5; fi ) done
echo "All healthy!"
- if: github.event_name == 'release' || contains(github.event.head_commit.message, '[mainnetdeploy]')
name: Deploy mainnet
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.MAINNET_VM_HOST }}
username: validator
key: ${{ env.vm_ssh_key }}
port: 22
script_stop: true
command_timeout: 30m
script: |
cd go-tableland
git fetch && git checkout -f ${{ github.sha }}
cd docker
make mainnet-up
# Wait to start and double-check we're running the expected version.
# This helps having a green check in the GH Action be high-signal that everything is fine.
sleep 5;
for i in 1 2 3 4; do [ $(curl --insecure --silent https://127.0.0.1/api/v1/version | jq .git_commit) = "\"${{ steps.prep.outputs.sha_short}}\"" ] && break || (if [ $i = 4 ]; then exit -1; else sleep 5; fi ) done
echo "All healthy!"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ evm_history.db
# Project
.env*
*.ignore
tableland-openapi-spec.yaml
53 changes: 27 additions & 26 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ linters-settings:
errorCode: 0
warningCode: 0
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
disabled: true
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
misspell:
locale: US

Expand All @@ -54,9 +54,10 @@ issues:

exclude:
- stutters

run:
timeout: 30m

skip-dirs:
- "pkg/sqlstore/impl/system/internal/db"
- "pkg/sqlstore/impl/system/internal/db"
- "internal/router/controllers/apiv1"
21 changes: 16 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ GOVVV=go run github.com/ahmetb/[email protected]
GOVVV_FLAGS=$(shell $(GOVVV) -flags -version $(BIN_VERSION) -pkg $(shell go list ./buildinfo))

# Code generation

ethereum: ethereum-testcontroller ethereum-testerc721 ethereum-testerc721a
go run github.com/ethereum/go-ethereum/cmd/[email protected] --abi ./pkg/tables/impl/ethereum/abi.json --pkg ethereum --type Contract --out pkg/tables/impl/ethereum/contract.go --bin pkg/tables/impl/ethereum/bytecode.bin
.PHONY: ethereum
Expand Down Expand Up @@ -52,7 +51,6 @@ generate-history-db:
rm ${EVM_EVENTS_TARGET}

# Build

build-api:
go build -ldflags="${GOVVV_FLAGS}" ./cmd/api
.PHONY: build-api
Expand All @@ -70,7 +68,6 @@ image:
.PHONY: image

# Test

test:
go test ./... -short -race
.PHONY: test
Expand All @@ -79,7 +76,21 @@ test-replayhistory:
go test ./pkg/eventprocessor/impl -run=TestReplayProductionHistory -race

# Lint

lint:
go run github.com/golangci/golangci-lint/cmd/[email protected] run
.PHONYY: lint
.PHONY: lint

# OpenAPI
SPEC_URL=https://raw.githubusercontent.com/tablelandnetwork/docs/main/specs/validator/tableland-openapi-spec.yaml
APIV1=${PWD}/internal/router/controllers/apiv1
gen-api-v1:
mkdir -p ${APIV1}
curl -s ${SPEC_URL} > ${APIV1}/tableland-openapi-spec.yaml
docker run -w /gen -e GEN_DIR=/gen -v ${APIV1}:/gen swaggerapi/swagger-codegen-cli-v3:3.0.36 \
generate --lang go-server -o /gen -i tableland-openapi-spec.yaml --additional-properties=packageName=apiv1
sudo chown -R ${USER} ${APIV1}
cd ${APIV1} && \
mv go/* . && \
rm -rf go main.go Dockerfile README.md api .swagger-codegen .swagger-codegen-ignore *.yaml
sed -i 's/\*OneOfTableAttributesValue/interface{}/' internal/router/controllers/apiv1/model_table_attributes.go
.PHONY: gen-api-v1
Loading

0 comments on commit bfe36a4

Please sign in to comment.