Skip to content

Commit

Permalink
fix: use create event to update valid target (#2874)
Browse files Browse the repository at this point in the history
fix: use create event
  • Loading branch information
yanguoyu authored Oct 13, 2023
1 parent 2f9e240 commit 6db92e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/update_valid_target.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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: |
Expand All @@ -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`,
})
16 changes: 11 additions & 5 deletions scripts/update-valid-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})()

2 comments on commit 6db92e0

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 6503389549

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 6503390034

Please sign in to comment.