Skip to content

Commit

Permalink
deploy web4 resources (#933)
Browse files Browse the repository at this point in the history
* deploy web4 resources

* web4 scripts from web4 folder

* deploy web4 resources

* deploy web4 only on push to main
  • Loading branch information
petersalomonsen authored Sep 10, 2024
1 parent af5c964 commit 54538b5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/deploy-web4-resources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy web4 resources
on:
push:
branches: [main]

jobs:
deploy-widgets:
runs-on: ubuntu-latest
name: Deploy
environment: devhub.near
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
npm ci
- name: Deploy web4 resources
env:
SIGNER_ACCOUNT_ID: ${{ vars.NEAR_SOCIAL_ACCOUNT_ID }}
SIGNER_PRIVATE_KEY: ${{ secrets.NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY }}
run: |
npm run deploy:web4resources
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"fmt:check": "prettier --check '**/*.{js,jsx,ts,tsx,json}'",
"build": "npm run fmt",
"bw": "bos-workspace",
"deploy:web4resources": "node scripts/deployweb4resources.mjs",
"bw:dev:instances": "bw ws dev",
"bw:dev:devhub": "bw dev instances/devhub.near",
"bw:build:instance": "npm run bw build instances/$npm_config_instance build/$npm_config_instance && mv build/$npm_config_instance/src/widget/* build/$npm_config_instance/src/ && rm -Rf build/$npm_config_instance/src/widget",
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-static-hosting-web-gateway-folder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ await cp(
{ recursive: true }
);
const web4browserclientFileName = 'web4browserclient.js';
await copyFile(new URL(web4browserclientFileName, import.meta.url), `${staticWebHostingFolder}/${web4browserclientFileName}`);
await copyFile(new URL(`../web4/${web4browserclientFileName}`, import.meta.url), `${staticWebHostingFolder}/${web4browserclientFileName}`);

const replaceRpc = async (htmlfile) => {
const indexHtmlFilePath = `${staticWebHostingFolder}/${htmlfile}`;
Expand Down
42 changes: 42 additions & 0 deletions scripts/deployweb4resources.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import nearApi from "near-api-js";
import { readFile, readdir } from 'fs/promises';

// near contract call-function as-transaction $CONTRACT_ID post_javascript file-args web4/args.json prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as $CONTRACT_ID network-config testnet sign-with-plaintext-private-key --signer-public-key $SIGNER_PUBLIC_KEY --signer-private-key $SIGNER_PRIVATE_KEY send

const networkId = 'mainnet';
const contractId = 'social.near';
const accountId = process.env.SIGNER_ACCOUNT_ID;

const keyStore = new nearApi.keyStores.InMemoryKeyStore();
const keyPair = nearApi.KeyPair.fromString(process.env.SIGNER_PRIVATE_KEY);
await keyStore.setKey(networkId, accountId, keyPair);

const near = await nearApi.connect({
networkId,
nodeUrl: 'https://rpc.mainnet.near.org',
keyStore,
});

const account = await near.account(accountId);

const web4Folder = new URL('../web4', import.meta.url);
const web4FolderContents = await readdir(web4Folder);
const data = {};
data[accountId] = { web4: {} };

for (const resourceFileName of web4FolderContents) {
const resourceFileContent = (await readFile(new URL(`${web4Folder}/${resourceFileName}`))).toString();
const currentDeployedResourceFileContent = await account.viewFunction({contractId, methodName: 'get', args: {keys: [`${accountId}/web4/${resourceFileName}`]}});

if (currentDeployedResourceFileContent[accountId]?.web4[resourceFileName] !== resourceFileContent) {
data[accountId].web4[resourceFileName] = resourceFileContent;
}
}

if (Object.keys(data[accountId].web4).length > 0) {
console.log('deploying', Object.keys(data[accountId].web4));
await account.functionCall({ contractId, methodName: "set", args: {data} });
} else {
console.log('no web4 resources to deploy');
}

File renamed without changes.

0 comments on commit 54538b5

Please sign in to comment.