|
| 1 | +name: Block Extractor Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: {} |
| 5 | + schedule: |
| 6 | + - cron: '*/10 * * * *' # every 10 minutes |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +env: |
| 13 | + RUST_LOG: info |
| 14 | + GCP_BLOCK_EXTRACTOR_SA_KEY: ${{ secrets.GCP_BLOCK_EXTRACTOR_SA_KEY }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + backup-blocks: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + database: [postgres, bigquery] # This matrix is used to run the workflow for both postgres and bigquery |
| 22 | + network: [mainnet, testnet] # This matrix is used to run the workflow for both mainnet and testnet |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v2 |
| 27 | + |
| 28 | + - name: Compile evm-block-extractor |
| 29 | + run: cargo build --release -p evm-block-extractor --bin evm-block-extractor |
| 30 | + |
| 31 | + - name: Move binary to root |
| 32 | + run: mv target/release/evm-block-extractor evm-block-extractor |
| 33 | + |
| 34 | + - name: Make binary executable |
| 35 | + run: chmod +x evm-block-extractor |
| 36 | + |
| 37 | + - name: Set Up Environment Variables |
| 38 | + run: | |
| 39 | + if [ "${{ matrix.network }}" = "mainnet" ]; then |
| 40 | + echo "RPC_URL=https://mainnet.bitfinity.network" >> $GITHUB_ENV |
| 41 | + elif [ "${{ matrix.network }}" = "testnet" ]; then |
| 42 | + echo "RPC_URL=https://testnet.bitfinity.network" >> $GITHUB_ENV |
| 43 | + fi |
| 44 | +
|
| 45 | + # Only run the following steps if the database is BigQuery and the network is mainnet or testnet |
| 46 | + - name: Run evm-block-extractor for BigQuery |
| 47 | + if: matrix.database == 'bigquery' |
| 48 | + run: | |
| 49 | + ./evm-block-extractor \ |
| 50 | + --rpc-url ${{ env.RPC_URL }} \ |
| 51 | + --bigquery \ |
| 52 | + --project-id ${{ secrets.BIGQUERY_PROJECT_ID }} \ |
| 53 | + --dataset-id ${{ matrix.network }} \ |
| 54 | + ${{ matrix.network == 'testnet' && '--reset_db_on_state_change' || '' }} |
| 55 | +
|
| 56 | + # Only run the following steps if the network is mainnet and the database is postgres |
| 57 | + - name: Run evm-block-extractor for Postgres |
| 58 | + if: matrix.database == 'postgres' && matrix.network == 'mainnet' |
| 59 | + run: | |
| 60 | + ./evm-block-extractor \ |
| 61 | + --rpc-url ${{ env.RPC_URL }} \ |
| 62 | + --postgres \ |
| 63 | + --username ${{ secrets.POSTGRES_USERNAME }} \ |
| 64 | + --password ${{ secrets.POSTGRES_PASSWORD }} \ |
| 65 | + --database-name ${{ secrets.POSTGRES_DATABASE_NAME }} \ |
| 66 | + --database-url ${{ secrets.POSTGRES_DATABASE_URL }} \ |
| 67 | + --database-port ${{ secrets.POSTGRES_DATABASE_PORT }} |
| 68 | +
|
| 69 | + notify-slack: |
| 70 | + runs-on: ubuntu-22.04 |
| 71 | + needs: [backup-blocks] |
| 72 | + if: needs.backup-blocks.result == 'failure' |
| 73 | + steps: |
| 74 | + - name: Slack Notification |
| 75 | + id: slack |
| 76 | + uses: slackapi/slack-github-action@v1.17.0 |
| 77 | + with: |
| 78 | + channel-id: 'alerts-block-extractor' |
| 79 | + slack-message: 'EVM extractor failed to backup the blocks. Check the CI action here: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' |
| 80 | + |
| 81 | + env: |
| 82 | + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |
0 commit comments