github.com/vipernet-xyz/tm@v0.34.24/.github/workflows/check-generated.yml (about)

     1  # Verify that generated code is up-to-date.
     2  #
     3  # Note that we run these checks regardless whether the input files have
     4  # changed, because generated code can change in response to toolchain updates
     5  # even if no files in the repository are modified.
     6  name: Check generated code
     7  on:
     8    pull_request:
     9      branches:
    10        - main
    11  
    12  permissions:
    13    contents: read
    14  
    15  jobs:
    16    check-mocks:
    17      runs-on: ubuntu-latest
    18      steps:
    19        - uses: actions/setup-go@v3
    20          with:
    21            go-version: '1.18'
    22  
    23        - uses: actions/checkout@v3
    24  
    25        - name: "Check generated mocks"
    26          run: |
    27            set -euo pipefail
    28  
    29            readonly MOCKERY=2.12.3  # N.B. no leading "v"
    30            curl -sL "https://github.com/vektra/mockery/releases/download/v${MOCKERY}/mockery_${MOCKERY}_Linux_x86_64.tar.gz" | tar -C /usr/local/bin -xzf -
    31            make mockery 2>/dev/null
    32  
    33            if ! git diff --stat --exit-code ; then
    34              echo ">> ERROR:"
    35              echo ">>"
    36              echo ">> Generated mocks require update (either Mockery or source files may have changed)."
    37              echo ">> Ensure your tools are up-to-date, re-run 'make mockery' and update this PR."
    38              echo ">>"
    39              exit 1
    40            fi
    41  
    42    check-proto:
    43      runs-on: ubuntu-latest
    44      steps:
    45        - uses: actions/setup-go@v3
    46          with:
    47            go-version: '1.18'
    48  
    49        - uses: actions/checkout@v3
    50          with:
    51            fetch-depth: 1  # we need a .git directory to run git diff
    52  
    53        - name: "Check protobuf generated code"
    54          run: |
    55            set -euo pipefail
    56  
    57            # Install buf and gogo tools, so that differences that arise from
    58            # toolchain differences are also caught.
    59            readonly tools="$(mktemp -d)"
    60            export PATH="${PATH}:${tools}/bin"
    61            export GOBIN="${tools}/bin"
    62  
    63            go install github.com/bufbuild/buf/cmd/buf
    64            go install github.com/gogo/protobuf/protoc-gen-gogofaster@latest
    65  
    66            make proto-gen
    67  
    68            if ! git diff --stat --exit-code ; then
    69              echo ">> ERROR:"
    70              echo ">>"
    71              echo ">> Protobuf generated code requires update (either tools or .proto files may have changed)."
    72              echo ">> Ensure your tools are up-to-date, re-run 'make proto-gen' and update this PR."
    73              echo ">>"
    74              exit 1
    75            fi