diff --git a/.github/actions/protobuf-compatibility-check/action.yaml b/.github/actions/protobuf-compatibility-check/action.yaml new file mode 100644 index 000000000..db62a5b4d --- /dev/null +++ b/.github/actions/protobuf-compatibility-check/action.yaml @@ -0,0 +1,59 @@ +name: "Protobuf compatibility check" +description: | + "Runs a compatibility check for protobuf files." +inputs: + upstream_commit_version: + description: "Commit version of aptos-core that upstream is using" + required: true + default: "main" + +runs: + using: composite + steps: + - name: Install the buf CLI + shell: bash + run: | + BIN="/usr/local/bin" && \ + VERSION="1.30.0" && \ + curl -sSL \ + "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ + -o "${BIN}/buf" && \ + chmod +x "${BIN}/buf" + + # Checkout current repo with current commit + - name: Checkout current repo + uses: actions/checkout@v4 + with: + path: "aptos-indexer-processors" + + - name: Parse the toml in this repo + id: get_tag_output + shell: bash + run: | + set -ex + curl -sSLf "$(curl -sSLf https://api.github.com/repos/tomwright/dasel/releases/latest | grep browser_download_url | grep linux_amd64 | grep -v .gz | cut -d\" -f 4)" -L -o dasel && chmod +x dasel + mv ./dasel /usr/local/bin/dasel + cd aptos-indexer-processors + tag_output=$(dasel -r toml -f rust/Cargo.toml workspace.dependencies.aptos-protos.tag -w - ) + echo "::set-output name=tag_output::$tag_output" + + - name: Checkout aptos-core + uses: actions/checkout@v4 + with: + repository: "aptos-labs/aptos-core" + path: "aptos-core" + ref: ${{ steps.get_tag_output.outputs.tag_output }} + + - name: Check compatibility + shell: bash + run: | + set -ex + cd aptos-core/protos/proto + repo_url="https://github.com/aptos-labs/aptos-core.git#tag=${{ inputs.upstream_commit_version }},subdir=protos/proto" + if buf breaking --against "$repo_url" --verbose; then + echo "No breaking changes found" + else + echo "Breaking changes found" + echo "Did new oneof/enum fields get added?" + exit 1 + fi diff --git a/.github/workflows/check-protobuf-compatibility.yaml b/.github/workflows/check-protobuf-compatibility.yaml new file mode 100644 index 000000000..ba7955f62 --- /dev/null +++ b/.github/workflows/check-protobuf-compatibility.yaml @@ -0,0 +1,27 @@ +name: "Check Protobuf Compatibility" +on: + workflow_dispatch: + inputs: + upstream_commit_version: + description: 'The commit version to check compatibility against' + required: false + default: 'main' + pull_request: + +# cancel redundant builds +concurrency: + # for push and workflow_dispatch events we use `github.sha` in the concurrency group and don't really cancel each other out/limit concurrency + # for pull_request events newer jobs cancel earlier jobs to save on CI etc. + group: ${{ github.workflow }}-${{ github.event_name }}-${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha || github.head_ref || github.ref }} + cancel-in-progress: true + + +jobs: + CheckProtobufCompatibilityAgainstCurrentPR: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/protobuf-compatibility-check/ + with: + # Either current PR or the latest commit on the branch + upstream_commit_version: ${{ github.event.inputs.upstream_commit_version || 'main' }} \ No newline at end of file diff --git a/.github/workflows/nightly-check-protobuf-compatibility.yaml b/.github/workflows/nightly-check-protobuf-compatibility.yaml new file mode 100644 index 000000000..b0dfc4b7e --- /dev/null +++ b/.github/workflows/nightly-check-protobuf-compatibility.yaml @@ -0,0 +1,39 @@ +name: "Nightly Check Protobuf Compatibility" +on: + workflow_dispatch: + schedule: + - cron: "0 9 * * *" + +# cancel redundant builds +concurrency: + # for push and workflow_dispatch events we use `github.sha` in the concurrency group and don't really cancel each other out/limit concurrency + # for pull_request events newer jobs cancel earlier jobs to save on CI etc. + group: ${{ github.workflow }}-${{ github.event_name }}-${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha || github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + CheckProtobufCompatibilityAgainstTestnet: + runs-on: ubuntu-latest + steps: + - name: Get current version + id: get_upstream_commit_version + run: | + echo "::set-output name=upstream_commit_version::$(curl -s https://api.testnet.aptoslabs.com/v1 | jq -r .git_hash)" + + - uses: actions/checkout@v4 + - uses: ./.github/actions/protobuf-compatibility-check/ + with: + upstream_commit_version: ${{ steps.get_upstream_commit_version.outputs.upstream_commit_version }} + + CheckProtobufCompatibilityAgainstMainnet: + runs-on: ubuntu-latest + steps: + - name: Get current version + id: get_upstream_commit_version + run: | + echo "::set-output name=upstream_commit_version::$(curl -s https://api.mainnet.aptoslabs.com/v1 | jq -r .git_hash)" + + - uses: actions/checkout@v4 + - uses: ./.github/actions/protobuf-compatibility-check/ + with: + upstream_commit_version: ${{ steps.get_upstream_commit_version.outputs.upstream_commit_version }} \ No newline at end of file