From 226b1b584d902c84d6922ecaf3dc379e888e254c Mon Sep 17 00:00:00 2001 From: larry-aptos <112209412+larry-aptos@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:59:26 -0800 Subject: [PATCH] [3/3] Create github workflow to handle the SDK upgrade in processor repo (#642) --- .github/workflows/create-release-tag.yaml | 72 ++++++++++++++++++++ .github/workflows/integration-tests.yaml | 24 +++++++ .github/workflows/update-sdk-dependency.yaml | 57 ++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 .github/workflows/create-release-tag.yaml create mode 100644 .github/workflows/update-sdk-dependency.yaml diff --git a/.github/workflows/create-release-tag.yaml b/.github/workflows/create-release-tag.yaml new file mode 100644 index 00000000..29114dc4 --- /dev/null +++ b/.github/workflows/create-release-tag.yaml @@ -0,0 +1,72 @@ +name: Create Release Tag + +on: + workflow_dispatch: + inputs: + release_type: + description: 'Type of release (patch/minor)' + required: true + type: choice + options: + - patch + - minor + +jobs: + create-tag: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all tags and branches + + - name: Get latest tag and create new version + id: generate_version + run: | + # Get the latest tag that matches our pattern + latest_tag=$(git tag -l "aptos-indexer-processors-v*" | sort -V | tail -n 1) + + if [ -z "$latest_tag" ]; then + # If no tags exist, start with 1.20.0. + # Last release was 1.19.1. + current_version="1.20.0" + else + # Extract version number from tag + current_version=$(echo $latest_tag | sed 's/aptos-indexer-processors-v//') + fi + + # Split version into components + major=$(echo $current_version | cut -d. -f1) + minor=$(echo $current_version | cut -d. -f2) + patch=$(echo $current_version | cut -d. -f3) + + # Calculate new version based on input + if [ "${{ inputs.release_type }}" = "minor" ]; then + new_version="${major}.$((minor + 1)).0" + else + new_version="${major}.${minor}.$((patch + 1))" + fi + + echo "New version will be: $new_version" + echo "new_version=${new_version}" >> $GITHUB_OUTPUT + echo "current_version=${current_version}" >> $GITHUB_OUTPUT + + - name: Create and push tag + run: | + new_tag="aptos-indexer-processors-v${{ steps.generate_version.outputs.new_version }}" + git tag -a "$new_tag" -m "Release $new_tag" + git push origin "$new_tag" + # TODO: roll docker image release into this workflow. + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + tag_name: aptos-indexer-processors-v${{ steps.generate_version.outputs.new_version }} + name: Release ${{ steps.generate_version.outputs.new_version }} + body: | + Automated release from ${{ steps.generate_version.outputs.current_version }} to ${{ steps.generate_version.outputs.new_version }} + + Type: ${{ inputs.release_type }} release + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 4aa76361..2418dc49 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -75,6 +75,8 @@ jobs: # Run Integration Tests - name: Run Integration Tests + id: tests + continue-on-error: true run: | # TODO: until we have more comprehensive cli parsers, we will need to run tests separately. cargo test sdk_tests -- --nocapture @@ -82,6 +84,28 @@ jobs: # Run all Tests - name: Run Sanity Tests + id: sanity-check + continue-on-error: true run: | cargo test regression_tests -- --nocapture working-directory: rust/integration-tests + + - name: Fail if tests fail + if: ${{ steps.sanity-check.outcome == 'failure' && github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'indexer-sdk-update') }} + run: | + echo "Integration failed" + exit 1 + + - name: Send Slack Notification to oncall + if: ${{ steps.sanity-check.outcome == 'failure' && github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'indexer-sdk-update') }} + uses: slackapi/slack-github-action@v1.24.0 + with: + # eco-infra-oncall channel. + channel-id: 'C0468USBLQJ' + slack-message: | + :warning: Tests failed on PR with indexer-sdk-update label + PR: ${{ github.event.pull_request.html_url }} + Author: ${{ github.event.pull_request.user.login }} + Title: ${{ github.event.pull_request.title }} + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/update-sdk-dependency.yaml b/.github/workflows/update-sdk-dependency.yaml new file mode 100644 index 00000000..2c9fa3c5 --- /dev/null +++ b/.github/workflows/update-sdk-dependency.yaml @@ -0,0 +1,57 @@ +name: Update SDK Dependency + +on: + repository_dispatch: + types: [sdk-dependency-update] +jobs: + update-the-dependency: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Install toml + run: cargo install toml-cli + - name: Update the dependency + run: | + set -e + + # SDK commit hash + toml set Cargo.toml workspace.dependencies.aptos-indexer-processor-sdk.rev ${{ github.event.client_payload.commit_hash }} > Cargo.tmp && mv Cargo.tmp Cargo.toml + toml set Cargo.toml workspace.dependencies.aptos-indexer-processor-sdk-server-framework.rev ${{ github.event.client_payload.commit_hash }} > Cargo.tmp && mv Cargo.tmp Cargo.toml + toml set Cargo.toml workspace.dependencies.aptos-indexer-testing-framework.rev ${{ github.event.client_payload.aptos_protos_commit_hash }} > Cargo.tmp && mv Cargo.tmp Cargo.toml + # Protos commit hash + toml set Cargo.toml workspace.dependencies.aptos-protos.rev ${{ github.event.client_payload.aptos_protos_commit_hash }} > Cargo.tmp && mv Cargo.tmp Cargo.toml + toml set Cargo.toml workspace.dependencies.aptos-indexer-test-transactions.rev ${{ github.event.client_payload.aptos_protos_commit_hash }} > Cargo.tmp && mv Cargo.tmp Cargo.toml + working-directory: rust/ + - name: Configure Git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Commit and Push Changes + run: | + set -e + branch_name="${{ github.event.client_payload.branch_name }}-update-sdk" + git checkout -b "$branch_name" + git add Cargo.toml + git commit -m "Update sdk to ${{ github.event.client_payload.commit_hash }}" + git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git + git push origin "$branch_name" --force + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + working-directory: rust/ + - name: Create Pull Request + run: | + branch_name="${{ github.event.client_payload.branch_name }}-update-sdk" + gh pr create --title "Update sdk to upstream branch ${{ github.event.client_payload.branch_name }}" \ + --body "This PR updates sdk to new version." \ + --base main \ + --head "$branch_name" \ + --label "indexer-sdk-update" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Run Integration Tests + run: cargo test --manifest-path integration-tests/Cargo.toml + working-directory: rust