From 93c61c44f7232742fbc135af9b601d416c0a8239 Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Thu, 12 Oct 2023 16:50:49 +0800 Subject: [PATCH] fix: use create event --- .github/workflows/update_valid_target.yml | 19 +++++++++---------- scripts/update-valid-target.js | 16 +++++++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/update_valid_target.yml b/.github/workflows/update_valid_target.yml index 4b2cd85462..ba1a6a7428 100644 --- a/.github/workflows/update_valid_target.yml +++ b/.github/workflows/update_valid_target.yml @@ -1,10 +1,9 @@ name: Update ckb node assume valid target on: - pull_request: - types: [ready_for_review] + create: branches: - - master + - "rc/**" jobs: ready-for-release: @@ -16,13 +15,13 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - branch: 'chore-update-valid-target/${{github.head_ref}}' - sha: '${{ github.event.pull_request.head.sha }}' + branch: 'chore-update-valid-target/${{github.ref_name}}' + sha: '${{ github.event.create.head.sha }}' - name: Checkout uses: actions/checkout@v3 with: - ref: 'chore-update-valid-target/${{github.head_ref}}' + ref: 'chore-update-valid-target/${{github.ref_name}}' - name: Setup Node uses: actions/setup-node@v3 @@ -37,7 +36,7 @@ jobs: uses: actions/github-script@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BASE: ${{ github.head_ref }} + BASE: ${{ github.ref_name }} with: script: | const fs = require('node:fs') @@ -64,8 +63,8 @@ jobs: uses: actions/github-script@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BASE: ${{github.head_ref}} - HEAD: chore-update-valid-target/${{github.head_ref}} + BASE: ${{github.ref}} + HEAD: chore-update-valid-target/${{github.ref_name}} REPO: ${{github.repository}} with: script: | @@ -83,5 +82,5 @@ jobs: head: HEAD, base: BASE, title: 'chore: Update ckb node assume valid target', - body: `This PR uses to update ckb node assume valid target for PR https://github.com/${REPO}/pull/${context.issue.number}`, + body: `This PR uses to update ckb node assume valid target for ${BASE} branch`, }) diff --git a/scripts/update-valid-target.js b/scripts/update-valid-target.js index 78d2fbac0f..4ca12b6e55 100644 --- a/scripts/update-valid-target.js +++ b/scripts/update-valid-target.js @@ -26,9 +26,15 @@ const envFilePath = path.resolve(__dirname, '../packages/neuron-wallet/.env') const validTargetReg = /(CKB_NODE_ASSUME_VALID_TARGET=)[\S]*/ ;(async function () { - const tipBlockNumber = (await rpcRequest('get_tip_block_number')).result - const validTargetBlockNumber = `0x${(BigInt(tipBlockNumber) - BigInt(ESTIMATE_BLOCK_COUNT_PER_DAY)).toString(16)}` - const blockHash = (await rpcRequest('get_block_hash', [validTargetBlockNumber])).result - const originEnvContent = fs.readFileSync(envFilePath).toString('utf-8') - fs.writeFileSync(envFilePath, originEnvContent.replace(validTargetReg, `CKB_NODE_ASSUME_VALID_TARGET='${blockHash}'`)) + try { + console.info('start update env file') + const tipBlockNumber = (await rpcRequest('get_tip_block_number')).result + const validTargetBlockNumber = `0x${(BigInt(tipBlockNumber) - BigInt(ESTIMATE_BLOCK_COUNT_PER_DAY)).toString(16)}` + const blockHash = (await rpcRequest('get_block_hash', [validTargetBlockNumber])).result + const originEnvContent = fs.readFileSync(envFilePath).toString('utf-8') + fs.writeFileSync(envFilePath, originEnvContent.replace(validTargetReg, `CKB_NODE_ASSUME_VALID_TARGET='${blockHash}'`)) + console.info('write success') + } catch (error) { + console.error('write failed', error) + } })()