-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,609 additions
and
0 deletions.
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,2 @@ | ||
node_modules | ||
.idea |
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 |
---|---|---|
@@ -1 +1,20 @@ | ||
# arweave-publish-action | ||
|
||
Simple GitHub action to mirror documents onto Arweave. | ||
|
||
## Usage | ||
Add 'Arweave Publish' as a build step in your workflow file (e.g. `.github/workflows/deploy.yaml`) | ||
|
||
```yaml | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build Link Index | ||
uses: verses-xyz/[email protected] | ||
with: | ||
wallet-address: ... # Public address for admin wallet | ||
wallet-key: ... # JSON Key for associated admin wallet | ||
document-path: ... # Path of document to mirror | ||
``` |
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,18 @@ | ||
name: 'Arweave Publish' | ||
description: 'Automatically publish documents to the permaweb' | ||
inputs: | ||
wallet-address: | ||
description: 'Public address for admin wallet' | ||
required: true | ||
wallet-key: | ||
description: 'JSON Key for associated admin wallet' | ||
required: true | ||
document-path: | ||
description: 'Path of document to mirror' | ||
required: true | ||
outputs: | ||
txId: | ||
description: 'Transaction ID of uploaded document' | ||
runs: | ||
using: 'node16' | ||
main: 'index.js' |
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,36 @@ | ||
const core = require('@actions/core') | ||
const github = require('@actions/github') | ||
const fs = require('fs') | ||
const { ArweaveClient } = require('ar-wrapper') | ||
|
||
async function main() { | ||
try { | ||
const addr = core.getInput('wallet-address') | ||
const key = core.getInput('wallet-key') | ||
const path = core.getInput('document-path') | ||
if (!(addr && key && path)) { | ||
core.setFailed("document-path, wallet-address, and wallet-key all need to be passed!") | ||
return | ||
} | ||
|
||
// init client | ||
const client = new ArweaveClient(addr, key) | ||
const docName = `${github.context.payload.repository.name}:${path}` | ||
|
||
// get new content | ||
const data = fs.readFileSync(path, 'utf8') | ||
|
||
// todo: maybe hash to fixed size? | ||
const docs = await client.getDocumentsByName(docName) | ||
const latestDoc = docs.sort((a, b) => b.version - a.version)[0] | ||
|
||
// update/add doc and return txId | ||
const newDoc = latestDoc ? await latestDoc.update(data) : await client.addDocument(docName, data, {}) | ||
core.setOutput("txId", newDoc.txID) | ||
} catch (error) { | ||
core.setFailed(error.message) | ||
} | ||
} | ||
|
||
main() | ||
|
Oops, something went wrong.