Skip to content

Commit 804f44e

Browse files
committed
write action
1 parent f28284b commit 804f44e

File tree

6 files changed

+1609
-0
lines changed

6 files changed

+1609
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.idea

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11
# arweave-publish-action
2+
3+
Simple GitHub action to mirror documents onto Arweave.
4+
5+
## Usage
6+
Add 'Arweave Publish' as a build step in your workflow file (e.g. `.github/workflows/deploy.yaml`)
7+
8+
```yaml
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-18.04
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Build Link Index
15+
uses: verses-xyz/[email protected]
16+
with:
17+
wallet-address: ... # Public address for admin wallet
18+
wallet-key: ... # JSON Key for associated admin wallet
19+
document-path: ... # Path of document to mirror
20+
```

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Arweave Publish'
2+
description: 'Automatically publish documents to the permaweb'
3+
inputs:
4+
wallet-address:
5+
description: 'Public address for admin wallet'
6+
required: true
7+
wallet-key:
8+
description: 'JSON Key for associated admin wallet'
9+
required: true
10+
document-path:
11+
description: 'Path of document to mirror'
12+
required: true
13+
outputs:
14+
txId:
15+
description: 'Transaction ID of uploaded document'
16+
runs:
17+
using: 'node16'
18+
main: 'index.js'

index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const core = require('@actions/core')
2+
const github = require('@actions/github')
3+
const fs = require('fs')
4+
const { ArweaveClient } = require('ar-wrapper')
5+
6+
async function main() {
7+
try {
8+
const addr = core.getInput('wallet-address')
9+
const key = core.getInput('wallet-key')
10+
const path = core.getInput('document-path')
11+
if (!(addr && key && path)) {
12+
core.setFailed("document-path, wallet-address, and wallet-key all need to be passed!")
13+
return
14+
}
15+
16+
// init client
17+
const client = new ArweaveClient(addr, key)
18+
const docName = `${github.context.payload.repository.name}:${path}`
19+
20+
// get new content
21+
const data = fs.readFileSync(path, 'utf8')
22+
23+
// todo: maybe hash to fixed size?
24+
const docs = await client.getDocumentsByName(docName)
25+
const latestDoc = docs.sort((a, b) => b.version - a.version)[0]
26+
27+
// update/add doc and return txId
28+
const newDoc = latestDoc ? await latestDoc.update(data) : await client.addDocument(docName, data, {})
29+
core.setOutput("txId", newDoc.txID)
30+
} catch (error) {
31+
core.setFailed(error.message)
32+
}
33+
}
34+
35+
main()
36+

0 commit comments

Comments
 (0)