Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into rich/sync-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa committed Dec 18, 2024
2 parents 6e5f49f + 951306a commit af1e4a3
Show file tree
Hide file tree
Showing 42 changed files with 758 additions and 201 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/build-xmtpd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ jobs:
type=ref,event=tag
type=ref,event=pr
type=sha
- name: Set up Docker image file based on the matrix variable
id: set_dockerfile
run: |
if [[ "${{ matrix.image }}" == "xmtpd" ]]; then
echo "dockerfile=Dockerfile" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.image }}" == "xmtpd-cli" ]]; then
echo "dockerfile=Dockerfile-cli" >> $GITHUB_OUTPUT
else
echo "Unknown image: ${{ matrix.image }}"
exit 1
fi
- name: Build and push Docker image
uses: docker/build-push-action@v6
id: push
with:
context: .
file: ./dev/docker/Dockerfile
file: ./dev/docker/${{ steps.set_dockerfile.outputs.dockerfile }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
19 changes: 4 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ on:
push:
branches:
- main
paths-ignore:
- "contracts/**"
pull_request:
paths-ignore:
- "contracts/**"
permissions:
contents: read
jobs:
Expand All @@ -28,18 +32,3 @@ jobs:
uses: nickcharlton/diff-check@main
with:
command: dev/lint-golines
contracts:
name: Lint (Contracts)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: "nightly-ac81a53d1d5823919ffbadd3c65f081927aa11f2"
- run: forge --version
- name: Run Forge fmt
# only format code, we do not want to format LIB
run: forge fmt contracts/src --check
19 changes: 16 additions & 3 deletions .github/workflows/release-from-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
jobs:
push_to_registry:
name: Push Docker Image to GitHub Packages
strategy:
matrix:
image: [ "xmtpd", "xmtpd-cli" ]
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -23,12 +26,22 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker image file based on the matrix variable
id: set_dockerfile
run: |
if [[ "${{ matrix.image }}" == "xmtpd" ]]; then
echo "dockerfile=Dockerfile" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.image }}" == "xmtpd-cli" ]]; then
echo "dockerfile=Dockerfile-cli" >> $GITHUB_OUTPUT
else
echo "Unknown image: ${{ matrix.image }}"
exit 1
fi
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/xmtp/xmtpd
images: ghcr.io/xmtp/${{ matrix.image }}
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
Expand All @@ -38,7 +51,7 @@ jobs:
id: push
with:
context: .
file: ./dev/docker/Dockerfile
file: ./dev/docker/${{ steps.set_dockerfile.outputs.dockerfile }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
124 changes: 124 additions & 0 deletions .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: CI Solidity

on:
push:
branches:
- main
paths:
- "contracts/**"
pull_request:
paths:
- "contracts/**"

concurrency:
group: ci-solidity-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
working-directory: contracts

jobs:
init:
runs-on: ubuntu-latest
strategy:
fail-fast: true

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install dependencies
run: forge soldeer update

- name: Build contracts
run: forge build

- name: Cache data
uses: actions/cache@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}

- id: forge
run: echo "FORGE_PATH=$(which forge)" >> $GITHUB_OUTPUT

- name: Upload forge
uses: actions/upload-artifact@v4
with:
name: forge
path: ${{ steps.forge.outputs.FORGE_PATH }}

test:
needs: init
runs-on: ubuntu-latest
steps:
- name: Restore cache
uses: actions/cache@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}

- name: Restore forge
uses: actions/download-artifact@v4
with:
name: forge
path: /usr/local/bin

- run: chmod +x /usr/local/bin/forge

- name: Run Forge tests
run: forge test -vvv

lint:
needs: init
runs-on: ubuntu-latest
steps:
- name: Restore cache
uses: actions/cache@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}

- name: Restore forge
uses: actions/download-artifact@v4
with:
name: forge
path: /usr/local/bin

- run: chmod +x /usr/local/bin/forge

- name: Run Forge fmt
run: forge fmt contracts/src --check

slither:
needs: init
runs-on: ubuntu-latest
steps:
- name: Restore cache
uses: actions/cache@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}

- name: Restore forge
uses: actions/download-artifact@v4
with:
name: forge
path: /usr/local/bin

- run: chmod +x /usr/local/bin/forge

- name: Install Slither
run: pip3 install slither-analyzer

- name: Run Slither
run: slither . --sarif output.sarif

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: contracts/output.sarif
30 changes: 4 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ on:
push:
branches:
- main
paths-ignore:
- "contracts/**"
pull_request:
paths-ignore:
- "contracts/**"
jobs:
test:
name: Test (Node)
Expand Down Expand Up @@ -38,29 +42,3 @@ jobs:
service: xmtp-node-go
files: report.xml
env: ci
contracts:
name: Test (Contracts)
strategy:
fail-fast: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: "nightly-ac81a53d1d5823919ffbadd3c65f081927aa11f2"

- name: Run Forge build
working-directory: contracts
run: |
forge --version
forge build --sizes
- name: Run Forge tests
working-directory: contracts
run: |
forge test -vvv
id: test
6 changes: 3 additions & 3 deletions cmd/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func TestRegisterNodeArgParse(t *testing.T) {
httpAddress,
"--admin-private-key",
adminPrivateKey,
"--owner-address",
"--node-owner-address",
ownerAddress.Hex(),
"--signing-key-pub",
"--node-signing-key-pub",
signingKeyPub,
},
)
Expand All @@ -41,7 +41,7 @@ func TestRegisterNodeArgParse(t *testing.T) {
require.Equal(
t,
err.Error(),
"Could not parse options: the required flags `--admin-private-key', `--http-address', `--owner-address' and `--signing-key-pub' were not specified",
"Could not parse options: the required flags `--admin-private-key', `--http-address', `--node-owner-address' and `--node-signing-key-pub' were not specified",
)
}

Expand Down
15 changes: 5 additions & 10 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@ import (
"log"
"os"

"github.com/xmtp/xmtpd/pkg/config"

"github.com/jessevdk/go-flags"
"github.com/xmtp/xmtpd/pkg/blockchain"
"github.com/xmtp/xmtpd/pkg/config"
"github.com/xmtp/xmtpd/pkg/utils"
"go.uber.org/zap"
)

var Commit string = "unknown"

type globalOptions struct {
Contracts config.ContractsOptions `group:"Contracts Options" namespace:"contracts"`
Log config.LogOptions `group:"Log Options" namespace:"log"`
}

type CLI struct {
globalOptions
config.GlobalOptions
Command string
GetPubKey config.GetPubKeyOptions
GenerateKey config.GenerateKeyOptions
Expand All @@ -43,7 +39,7 @@ the options for each subcommand.
*
*/
func parseOptions(args []string) (*CLI, error) {
var options globalOptions
var options config.GlobalOptions
var generateKeyOptions config.GenerateKeyOptions
var registerNodeOptions config.RegisterNodeOptions
var getPubKeyOptions config.GetPubKeyOptions
Expand Down Expand Up @@ -150,7 +146,7 @@ func registerNode(logger *zap.Logger, options *CLI) {
}
logger.Info(
"successfully added node",
zap.String("owner-address", options.RegisterNode.OwnerAddress),
zap.String("node-owner-address", options.RegisterNode.OwnerAddress),
zap.String("node-http-address", options.RegisterNode.HttpAddress),
zap.String("node-signing-key-pub", utils.EcdsaPublicKeyToString(signingKeyPub)),
)
Expand Down Expand Up @@ -308,5 +304,4 @@ func main() {
updateAddress(logger, options)
return
}

}
Loading

0 comments on commit af1e4a3

Please sign in to comment.