Skip to content

Commit

Permalink
ci: check go generate has been run (#97)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <[email protected]>
  • Loading branch information
trajan0x and trajan0x authored Aug 15, 2022
1 parent abcd828 commit c2fe62b
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 19 deletions.
147 changes: 135 additions & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,39 +108,53 @@ jobs:

# changes allows us to only run a job on changed packages
changes:
name: Go Changes
name: Change Detection
runs-on: ubuntu-latest
outputs:
# Expose matched filters as job 'packages' output variable
packages: ${{ steps.filter.outputs.changes }}
package_count: ${{ steps.length.outputs.FILTER_LENGTH }}
go_package_changes: ${{ steps.filter_go.outputs.changes }}
go_change_count: ${{ steps.length.outputs.GO_CHANGES_LENGTH }}
solidity_changes: ${{ steps.filter_solidity.outputs.any_changed }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: 'recursive'

# For pull requests it's not necessary to checkout the code
# Check if any go files have been changed in each of the go packages
- uses: dorny/paths-filter@v2
id: filter
name: "Check for Go Changes"
id: filter_go
with:
filters: |
core: 'core/**'
tools: 'tools/**'
ethergo: 'ethergo/**'
- id: length
# Check for solidity changes, if anything has been changed here we need to regenerate core
- name: Check For Solidity Changes
id: filter_solidity
uses: tj-actions/[email protected]
with:
files: |
**/*.sol
- id: Get go output changes length
run: |
export FILTER_LENGTH=$(echo $FILTERED_PATHS | jq '. | length')
echo "##[set-output name=FILTER_LENGTH;]$(echo $FILTER_LENGTH)"
# get length of go changes
export GO_CHANGES_LENGTH=$(echo GO_FILTERED_PATHS | jq '. | length')
echo "##[set-output name=GO_CHANGES_LENGTH;]$(echo GO_CHANGES_LENGTH)"
env:
FILTERED_PATHS: ${{ steps.filter.outputs.changes }}
GO_FILTERED_PATHS: ${{ steps.filter_go.outputs.changes }}


# make sure the build works
build:
name: Build
needs: changes
runs-on: ${{ matrix.platform }}
if: ${{ needs.changes.outputs.package_count > 0 }}
if: ${{ needs.changes.outputs.go_change_count > 0 }}
strategy:
matrix:
go-version:
Expand Down Expand Up @@ -181,12 +195,12 @@ jobs:
name: Lint
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.package_count > 0 }}
if: ${{ needs.changes.outputs.go_change_count > 0 }}
strategy:
matrix:
# Parse JSON array containing names of all filters matching any of changed files
# e.g. ['package1', 'package2'] if both package folders contains changes
package: ${{ fromJSON(needs.changes.outputs.packages) }}
package: ${{ fromJSON(needs.changes.outputs.go_package_changes) }}
steps:
- uses: actions/setup-go@v3
with:
Expand Down Expand Up @@ -223,3 +237,112 @@ jobs:
# see: https://github.com/golangci/golangci-lint/issues/337#issuecomment-510136513
GOGC: 20
GOPRIVATE: "GOPRIVATE=github.com/synapsecns/synapse-node"

# check if we need to rerun go generate as a result of solidity changes. Note, this will only run on solidity changes.
check-generation:
name: Go Generate
runs-on: ubuntu-latest
needs: changes
if: ${{ github.event_name != 'pull_request' && needs.changes.outputs.solidity_changes }}
strategy:
matrix:
# only do on core for now
package: ['core']
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: 'recursive'

# Setup npm
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvmrc

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: "Use NodeJS by nvmrc"
uses: actions/setup-node@v2
with:
node-version: '${{steps.nvmrc.outputs.NVMRC}}'

- name: Initialize Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Node Dependencies
run: yarn install --frozen-lockfile --check-files

- name: Install dependencies
run: |
npx lerna bootstrap
# Generate flattened files
- name: Run flattener
run: npx lerna exec npm run build:go

# Setup Go
- uses: actions/setup-go@v3
with:
go-version: 1.18

- name: authenticate with github for private go modules
uses: fusion-engineering/setup-git-credentials@v2
with:
credentials: https://0xnero:${{secrets.GIT_TOKEN }}@github.com/


- name: Go modules cache
uses: actions/cache@v2
with:
# see https://github.com/mvdan/github-actions-golang
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# See if we need to rerun go generate
# TODO: consider implementing https://github.com/golang/go/issues/20520 to sped up process if possible
- name: Try Go Generate
working-directory: ${{matrix.package}}/
run: |
go generate ./...
- name: Verify Changed files
uses: tj-actions/[email protected]
id: verify-changed-files
with:
files: |
*.go
*.json
- uses: jwalton/gh-find-current-pr@v1
id: find_pr

# Fail if files need regeneration
- name: Add Label
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90
with:
add-labels: "needs-go-generate"
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.find_pr.outputs.pr }}

- name: Remove Label
if: steps.verify-changed-files.outputs.files_changed != 'true'
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90
with:
remove-labels: "needs-go-generate"
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.find_pr.outputs.pr }}
26 changes: 26 additions & 0 deletions .github/workflows/label-statuses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# fail if certain labels are present
name: Label Statuses
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]

jobs:
# fail if certain labels are present
label-statuses:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
ref: master

- uses: mheap/github-action-required-labels@v2
with:
mode: exactly
count: 0
labels: "do not merge"

- uses: mheap/github-action-required-labels@v2
with:
mode: exactly
count: 0
labels: "needs go generate"
2 changes: 1 addition & 1 deletion core/contracts/home/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package home

//go:generate go run github.com/synapsecns/synapse-node/testutils/codegen/abigen generate --sol ../../../packages/contracts/flattened/Home.sol --pkg home --sol-version 0.8.13 --filename home
//go:generate go run github.com/synapsecns/sanguine/tools/abigen generate --sol ../../../packages/contracts/flattened/Home.sol --pkg home --sol-version 0.8.13 --filename home
// line after go:generate cannot be left blank

// here we generate some interfaces we use in for our mocks. TODO this should be automated in abigen for all contracts + be condensed
Expand Down
2 changes: 1 addition & 1 deletion core/contracts/test/messageharness/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package messageharness

//go:generate go run github.com/synapsecns/synapse-node/testutils/codegen/abigen generate --sol ../../../../packages/contracts/flattened/MessageHarness.sol --pkg messageharness --sol-version 0.8.13 --filename messageharness
//go:generate go run github.com/synapsecns/sanguine/tools/abigen generate --sol ../../../../packages/contracts/flattened/MessageHarness.sol --pkg messageharness --sol-version 0.8.13 --filename messageharness
// line after go:generate cannot be left blank
2 changes: 1 addition & 1 deletion core/contracts/updatermanager/generate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package updatermanager

//go:generate go run github.com/synapsecns/synapse-node/testutils/codegen/abigen generate --sol ../../../packages/contracts/flattened/UpdaterManager.sol --pkg updatermanager --sol-version 0.8.13 --filename updatemanager
//go:generate go run github.com/synapsecns/sanguine/tools/abigen generate --sol ../../../packages/contracts/flattened/UpdaterManager.sol --pkg updatermanager --sol-version 0.8.13 --filename updatemanager
4 changes: 4 additions & 0 deletions core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/synapsecns/sanguine/ethergo v0.0.0-00010101000000-000000000000
github.com/synapsecns/synapse-node v0.242.0
github.com/ugorji/go/codec v1.1.7
github.com/vburenin/ifacemaker v1.1.0
go.uber.org/zap v1.19.1
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gorm.io/driver/mysql v1.1.2
Expand Down Expand Up @@ -284,11 +285,14 @@ require (
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
Expand Down
7 changes: 7 additions & 0 deletions core/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1C
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.1-0.20181029123624-5de817a9aa20/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jhump/protoreflect v1.9.0/go.mod h1:7GcYQDdMU/O/BBrl/cX6PNHpXh6cenjd8pneu5yW7Tg=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
Expand Down Expand Up @@ -1852,6 +1853,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/vburenin/ifacemaker v1.1.0 h1:3ScCGZ+D65Ud9L0x9ofhN0dk5QrfauzMWYfaYsfA+HE=
github.com/vburenin/ifacemaker v1.1.0/go.mod h1:SlS6qpTccQsoK3ln7mBkUxA4agA8wfPr/IFYqBWerPw=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0 h1:6TteTDQ68CjgcCe8wH3D3ZhUQQOJXMTbj/D9rkk2a1k=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
Expand Down Expand Up @@ -2036,6 +2039,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -2290,6 +2295,7 @@ golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181130052023-1c3d964395ce/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181201035826-d0ca3933b724/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -2363,6 +2369,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w=
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 2 additions & 0 deletions core/internal/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ package internal

import (
"github.com/ugorji/go/codec"
"github.com/vburenin/ifacemaker/maker"
)

func init() {
panic("could not import dev package: this package is meant to define dependencies, not be imported.")
}

var _ = codec.Decoder{}
var _ = maker.ParseStruct
9 changes: 5 additions & 4 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"scripts": {
"build": "yarn build:contracts && yarn build:typescript && yarn build:go",
"build:go": "rm ./flattened/* && yarn sol-merger \"./contracts/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin & yarn sol-merger \"./test/harnesses/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin",
"build:go": "rimraf ./flattened/* && yarn sol-merger \"./contracts/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin & yarn sol-merger \"./test/harnesses/**.sol\" ./flattened --export-plugin SPDXLicenseRemovePlugin",
"build:contracts": "forge build",
"build:slither": "hardhat compile",
"build:typescript": "typechain --target ethers-v5 'artifacts/**/*json'",
Expand All @@ -20,10 +20,11 @@
"hardhat": "^2.9.6",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-dev.23",
"typechain": "^8.0.0",
"typescript": "^4.6.4",
"rimraf": "^3.0.2",
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.0.5"
"solhint-plugin-prettier": "^0.0.5",
"typechain": "^8.0.0",
"typescript": "^4.6.4"
},
"dependencies": {
"@nodelib/fs.walk": "^1.2.8",
Expand Down

0 comments on commit c2fe62b

Please sign in to comment.