Skip to content

Commit

Permalink
write action
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Jan 28, 2022
1 parent f28284b commit 804f44e
Show file tree
Hide file tree
Showing 6 changed files with 1,609 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.idea
19 changes: 19 additions & 0 deletions README.md
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
```
18 changes: 18 additions & 0 deletions action.yml
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'
36 changes: 36 additions & 0 deletions index.js
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()

Loading

0 comments on commit 804f44e

Please sign in to comment.