diff --git a/.github/workflows/erc-registry-indexer.yml b/.github/workflows/erc-registry-indexer.yml index 1b4e3c8eb..90e24ebcb 100644 --- a/.github/workflows/erc-registry-indexer.yml +++ b/.github/workflows/erc-registry-indexer.yml @@ -1,6 +1,11 @@ name: ERC Registry Indexer on: + push: + branches: + [ + 1128-erc-registry-phase-3-modify-the-workflow-script-to-also-create-a-pr-target-mne-repo, + ] workflow_dispatch: inputs: HEDERA_NETWORK: @@ -47,94 +52,137 @@ jobs: cd ${{env.INDEXER_PATH}} npm install - - name: Backup Existing Registry + # - name: Backup Existing Registry + # run: | + # mkdir -p ${{ env.INDEXER_PATH }}/backup + # if [ -d "${{ env.INDEXER_PATH }}/erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}" ] && [ "$(ls -A ${{ env.INDEXER_PATH }}/erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/*.json 2>/dev/null)" ]; then + # cp ${{ env.INDEXER_PATH }}/erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/*.json ${{ env.INDEXER_PATH }}/backup/ + # echo "Backup successful." + # else + # echo "No JSON files found to back up." + # fi + + # - name: Start Timer + # id: timer_start + # run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV + + # - name: Start ERC Registry Indexer + # id: start_erc_indexer + # run: | + # cd ${{env.INDEXER_PATH}} + # npm start + + # - name: Stop Timer + # id: timer_end + # run: echo "END_TIME=$(date +%s)" >> $GITHUB_ENV + + # - name: Calculate Duration + # id: calculate_duration + # run: | + # # Calculate the duration in seconds + # DURATION=$((END_TIME - START_TIME)) + + # # Resolve duration + # if [ "$DURATION" -lt 60 ]; then + # FORMATTED_DURATION="${DURATION} seconds" + # elif [ "$DURATION" -lt 3600 ]; then + # MINUTES=$((DURATION / 60)) + # SECONDS=$((DURATION % 60)) + # FORMATTED_DURATION="${MINUTES} minute(s) and ${SECONDS} second(s)" + # else + # HOURS=$((DURATION / 3600)) + # MINUTES=$(((DURATION % 3600) / 60)) + # FORMATTED_DURATION="${HOURS} hour(s) and ${MINUTES} minute(s)" + # fi + # echo "INDEXING_DURATION=${FORMATTED_DURATION}" >> $GITHUB_ENV + + # - name: Count New Records + # id: count_records + # run: | + # cd ${{ env.INDEXER_PATH }} + # # Determine the new amount of ERC-20 records + # if [ -f backup/erc-20.json ]; then + # NEW_ERC20_RECORDS=$(jq -s '.[1] - .[0] | length' backup/erc-20.json erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-20.json) + # else + # NEW_ERC20_RECORDS=$(jq '. | length' erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-20.json) + # fi + + # # Determine the new amount of of ERC-721 records + # if [ -f backup/erc-721.json ]; then + # NEW_ERC721_RECORDS=$(jq -s '.[1] - .[0] | length' backup/erc-721.json erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-721.json) + # else + # NEW_ERC721_RECORDS=$(jq '. | length' erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-721.json) + # fi + + # # Export the results to GitHub environment variables + # echo "NEW_ERC20_RECORDS=${NEW_ERC20_RECORDS}" >> $GITHUB_ENV + # echo "NEW_ERC721_RECORDS=${NEW_ERC721_RECORDS}" >> $GITHUB_ENV + + # - name: Delete backup registry folder + # run: | + # if [ -d ${{ env.INDEXER_PATH }}/backup ]; then + # rm -rf ${{ env.INDEXER_PATH }}/backup + # echo "Deleted backup folder." + # else + # echo "backup folder not found, skipping deletion." + # fi + + # - name: Import GPG Key + # id: gpg_importer + # uses: step-security/ghaction-import-gpg@6c8fe4d0126a59d57c21f87c9ae5dd3451fa3cca # v6.1.0 + # with: + # git_commit_gpgsign: true + # git_tag_gpgsign: true + # git_user_signingkey: true + # gpg_private_key: ${{ secrets.GPG_KEY_CONTENTS }} + # passphrase: ${{ secrets.GPG_KEY_PASSPHRASE }} + + # - name: Get Current Date + # id: current_date + # run: echo "CURRENT_DATE=$(date -u +"%m-%d-%Y")" >> $GITHUB_ENV + + # - name: Create Pull Request + # uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5 + # with: + # branch: ERC-Registry-Periodical-Update/${{ github.run_id }} + # commit-message: 'chore: update ERC Registry with latest ERC-20 and ERC-721 tokens on Hedera ${{github.event.inputs.HEDERA_NETWORK}}' + # committer: ${{ steps.gpg_importer.outputs.name }} <${{ steps.gpg_importer.outputs.email }}> + # author: ${{ steps.gpg_importer.outputs.name }} <${{ steps.gpg_importer.outputs.email }}> + # token: ${{ secrets.GH_ACCESS_TOKEN }} + # delete-branch: true + # signoff: true + # title: 'chore: update ERC Registry with latest ERC-20 and ERC-721 tokens on Hedera ${{github.event.inputs.HEDERA_NETWORK}}' + # body: > + # **Description**: + + # This PR updates the ERC Registry to include the most recent ERC-20 and ERC-721 tokens. + + # **Registry Update Summary**: + # - **Hedera Network**: ${{ github.event.inputs.HEDERA_NETWORK }} + # - **New ERC-20 Records Added**: ${{ env.NEW_ERC20_RECORDS }} + # - **New ERC-721 Records Added**: ${{ env.NEW_ERC721_RECORDS }} + # - **Indexing Duration**: ${{ env.INDEXING_DURATION }} + # - **Current Date**: ${{ env.CURRENT_DATE }} + # labels: 'internal' + # assignees: 'swirlds-automation' + + - name: Clone Mirror Node Explorer Repository run: | - mkdir -p ${{ env.INDEXER_PATH }}/backup - if [ -d "${{ env.INDEXER_PATH }}/erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}" ] && [ "$(ls -A ${{ env.INDEXER_PATH }}/erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/*.json 2>/dev/null)" ]; then - cp ${{ env.INDEXER_PATH }}/erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/*.json ${{ env.INDEXER_PATH }}/backup/ - echo "Backup successful." - else - echo "No JSON files found to back up." - fi - - - name: Start Timer - id: timer_start - run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV - - - name: Start ERC Registry Indexer - id: start_erc_indexer + git clone https://github.com/hashgraph/hedera-mirror-node-explorer.git + + - name: Copy Files to Mirror Node Explorer Repository run: | - cd ${{env.INDEXER_PATH}} - npm start + # Navigate to target repository + cd hedera-mirror-node-explorer - - name: Stop Timer - id: timer_end - run: echo "END_TIME=$(date +%s)" >> $GITHUB_ENV + # Copy files to their correct positions in the target repository + cp -r ../${{ env.INDEXER_PATH }}/erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/* ./erc-registry/${{ github.event.inputs.HEDERA_NETWORK }} - - name: Calculate Duration - id: calculate_duration - run: | - # Calculate the duration in seconds - DURATION=$((END_TIME - START_TIME)) - - # Resolve duration - if [ "$DURATION" -lt 60 ]; then - FORMATTED_DURATION="${DURATION} seconds" - elif [ "$DURATION" -lt 3600 ]; then - MINUTES=$((DURATION / 60)) - SECONDS=$((DURATION % 60)) - FORMATTED_DURATION="${MINUTES} minute(s) and ${SECONDS} second(s)" - else - HOURS=$((DURATION / 3600)) - MINUTES=$(((DURATION % 3600) / 60)) - FORMATTED_DURATION="${HOURS} hour(s) and ${MINUTES} minute(s)" - fi - echo "INDEXING_DURATION=${FORMATTED_DURATION}" >> $GITHUB_ENV - - - name: Count New Records - id: count_records - run: | - cd ${{ env.INDEXER_PATH }} - # Determine the new amount of ERC-20 records - if [ -f backup/erc-20.json ]; then - NEW_ERC20_RECORDS=$(jq -s '.[1] - .[0] | length' backup/erc-20.json erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-20.json) - else - NEW_ERC20_RECORDS=$(jq '. | length' erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-20.json) - fi - - # Determine the new amount of of ERC-721 records - if [ -f backup/erc-721.json ]; then - NEW_ERC721_RECORDS=$(jq -s '.[1] - .[0] | length' backup/erc-721.json erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-721.json) - else - NEW_ERC721_RECORDS=$(jq '. | length' erc-registry/${{ github.event.inputs.HEDERA_NETWORK }}/erc-721.json) - fi - - # Export the results to GitHub environment variables - echo "NEW_ERC20_RECORDS=${NEW_ERC20_RECORDS}" >> $GITHUB_ENV - echo "NEW_ERC721_RECORDS=${NEW_ERC721_RECORDS}" >> $GITHUB_ENV - - - name: Delete backup registry folder - run: | - if [ -d ${{ env.INDEXER_PATH }}/backup ]; then - rm -rf ${{ env.INDEXER_PATH }}/backup - echo "Deleted backup folder." - else - echo "backup folder not found, skipping deletion." - fi - - - name: Import GPG Key - id: gpg_importer - uses: step-security/ghaction-import-gpg@6c8fe4d0126a59d57c21f87c9ae5dd3451fa3cca # v6.1.0 + - name: Checkout Mirror Node Explorer + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: - git_commit_gpgsign: true - git_tag_gpgsign: true - git_user_signingkey: true - gpg_private_key: ${{ secrets.GPG_KEY_CONTENTS }} - passphrase: ${{ secrets.GPG_KEY_PASSPHRASE }} - - - name: Get Current Date - id: current_date - run: echo "CURRENT_DATE=$(date -u +"%m-%d-%Y")" >> $GITHUB_ENV + submodules: recursive + repository: hashgraph/hedera-mirror-node-explorer - name: Create Pull Request uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5