diff --git a/.github/workflows/grpcurl-test.yml b/.github/workflows/grpcurl-test.yml new file mode 100644 index 0000000..d076a4e --- /dev/null +++ b/.github/workflows/grpcurl-test.yml @@ -0,0 +1,43 @@ +name: Run grpcurl commands on pull request + +on: + pull_request: + branches: + - '**' + +jobs: + run-grpcurl: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.18' + + - name: Install grpcurl + run: | + sudo apt-get update + sudo apt-get install -y curl + curl -sSL https://github.com/fullstorydev/grpcurl/releases/download/v1.8.7/grpcurl_1.8.7_linux_x86_64.tar.gz | sudo tar -xz -C /usr/local/bin + + - name: Run grpcurl for substreams services + run: node scripts/run-grpcurl-substreams.js + + - name: Check for grpcurl errors + if: failure() + run: | + echo "There were grpcurl errors, blocking the pull request." + exit 1 + + - name: Run grpcurl for firehose services + run: node scripts/run-grpcurl-firehose.js + + - name: Check for grpcurl errors + if: failure() + run: | + echo "There were grpcurl errors, blocking the pull request." + exit 1 diff --git a/scripts/known-issues-chains.js b/scripts/known-issues-chains.js new file mode 100644 index 0000000..89decbc --- /dev/null +++ b/scripts/known-issues-chains.js @@ -0,0 +1,8 @@ +const affectedChains = [ + { + id: 'cosmoshub', + affected_services: ['firehose'], + }, +]; + +module.exports = { affectedChains }; diff --git a/scripts/run-grpcurl-firehose.js b/scripts/run-grpcurl-firehose.js new file mode 100644 index 0000000..129ddc4 --- /dev/null +++ b/scripts/run-grpcurl-firehose.js @@ -0,0 +1,65 @@ +const fs = require('fs'); +const path = require('path'); +const { exec } = require('child_process'); +const { affectedChains } = require('./known-issues-chains'); +const filePath = path.resolve(__dirname, '../data/chains/V2/chains.json'); +const chains = JSON.parse( + fs.readFileSync(filePath, 'utf8'), +); + +function runGrpcurl(chainId, serviceName) { + return new Promise((resolve, reject) => { + const command = `grpcurl ${chainId}.${serviceName}.pinax.network:443 sf.${serviceName}.v2.EndpointInfo/Info`; + console.log(`Executing: ${command}`); + + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Error: ${error.message}`); + reject(new Error(`Command failed: ${command}`)); + return; + } + if (stderr) { + console.error(`Stderr: ${stderr}`); + } + console.log(`Response: ${stdout}`); + resolve(`Success: ${command}`); + }); + }); +} + +async function run() { + try { + for (const chain of chains) { + const firehoseService = chain.supported_services.firehose; + + if ( + affectedChains.some( + (affectedChain) => + affectedChain.id === chain.id && + affectedChain.affected_services.includes('firehose'), + ) + ) { + console.log( + `${chain.id} is affected by known issues. Endpoint: ${chain.id}.firehose.pinax.network`, + ); + return; + } + if ( + firehoseService && + firehoseService.deprecated_at === null && + (firehoseService.beta_released_at || firehoseService.full_released_at) + ) { + console.log( + `Running grpcurl for substreams service on chain ${chain.id}`, + ); + await runGrpcurl(chain.id, 'firehose'); + } + } + console.log('All grpcurl commands executed successfully.'); + } catch (error) { + console.error('Error during grpcurl execution:', error.message); + process.exit(1); + } +} + +run(); diff --git a/scripts/run-grpcurl-substreams.js b/scripts/run-grpcurl-substreams.js new file mode 100644 index 0000000..975da11 --- /dev/null +++ b/scripts/run-grpcurl-substreams.js @@ -0,0 +1,66 @@ +const fs = require('fs'); +const path = require('path'); +const { exec } = require('child_process'); +const { affectedChains } = require('./known-issues-chains'); +const filePath = path.resolve(__dirname, '../data/chains/V2/chains.json'); +const chains = JSON.parse( + fs.readFileSync(filePath, 'utf8'), +); +function runGrpcurl(chainId, serviceName) { + return new Promise((resolve, reject) => { + const command = `grpcurl ${chainId}.${serviceName}.pinax.network:443 sf.${serviceName}.rpc.v2.EndpointInfo/Info`; + console.log(`Executing: ${command}`); + + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Error: ${error.message}`); + reject(new Error(`Command failed: ${command}`)); + return; + } + if (stderr) { + console.error(`Stderr: ${stderr}`); + } + console.log(`Response: ${stdout}`); + resolve(`Success: ${command}`); + }); + }); +} + +async function run() { + try { + for (const chain of chains) { + const substreamsService = chain.supported_services.substreams; + + if ( + affectedChains.some( + (affectedChain) => + affectedChain.id === chain.id && + affectedChain.affected_services.includes('substreams'), + ) + ) { + console.log( + `${chain.id} is affected by known issues. Endpoint: ${chain.id}.substreams.pinax.network`, + ); + return; + } + + if ( + substreamsService && + substreamsService.deprecated_at === null && + (substreamsService.beta_released_at || + substreamsService.full_released_at) + ) { + console.log( + `Running grpcurl for substreams service on chain ${chain.id}`, + ); + await runGrpcurl(chain.id, 'substreams'); + } + } + console.log('All grpcurl commands executed successfully.'); + } catch (error) { + console.error('Error during grpcurl execution:', error.message); + process.exit(1); + } +} + +run();