-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* deploy web4 resources * web4 scripts from web4 folder * deploy web4 resources * deploy web4 only on push to main
- Loading branch information
1 parent
af5c964
commit 54538b5
Showing
5 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.