Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use create event to update valid target #2874

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})()