Skip to content

Commit

Permalink
nodejs script for updating configs
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Jul 22, 2024
1 parent 3c4496e commit 74aa942
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 53 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/renew-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ jobs:
with:
fetch-depth: 0

- name: Install NodeJS 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Run script
run: ./scripts/renew-config.sh ${{ github.event.inputs.tag }} ${{ github.event.inputs.version }}
run: node ./scripts/renew-config.js ${{ github.event.inputs.tag }} ${{ github.event.inputs.version }}

- name: New PR branch
id: new-branch
Expand Down
42 changes: 42 additions & 0 deletions scripts/renew-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fs = require('fs');

const TESTNET_CONFIG_PATH = './config/rosetta/vara-testnet.json';
const MAINNET_CONFIG_PATH = './config/rosetta/vara-mainnet.json';

const tag = process.argv[2];
const version = process.argv[3];

const testnet_meta_url = `https://github.com/gear-tech/gear/releases/download/v${tag}/testnet_vara_runtime_v${version}_metadata.scale`;

const production_meta_url = `https://github.com/gear-tech/gear/releases/download/v${tag}/production_vara_runtime_v${version}_metadata.scale`;

const main = async () => {
console.log('Downloading testnet metadata from', testnet_meta_url);
const testnetMetadata = await fetch(testnet_meta_url).then((res) =>
res.status === 404 ? Promise.reject('Testnet metadata not found') : res.text(),
);

console.log('Downloading production metadata from', production_meta_url);
const productionMetadata = await fetch(production_meta_url).then((res) =>
res.status === 404 ? Promise.reject('Mainnet metadata not found') : res.text(),
);

console.log('Updating testnet config');
const testnetConfig = JSON.parse(fs.readFileSync(TESTNET_CONFIG_PATH));
testnetConfig.metadataRpc = testnetMetadata;
testnetConfig.specVersion = version;
fs.writeFileSync(TESTNET_CONFIG_PATH, JSON.stringify(testnetConfig, null, 2));

console.log('Updating mainnet config');
const productionConfig = JSON.parse(fs.readFileSync(MAINNET_CONFIG_PATH));
productionConfig.metadataRpc = productionMetadata;
productionConfig.specVersion = version;
fs.writeFileSync(MAINNET_CONFIG_PATH, JSON.stringify(productionConfig, null, 2));
};

main()
.then(() => process.exit(0))
.catch((error) => {
console.log(error);
process.exit(1);
});
52 changes: 0 additions & 52 deletions scripts/renew-config.sh

This file was deleted.

0 comments on commit 74aa942

Please sign in to comment.