Skip to content

Commit da34d25

Browse files
committed
Initial commit
0 parents  commit da34d25

File tree

8 files changed

+407
-0
lines changed

8 files changed

+407
-0
lines changed

.gitignore

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/node
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
.pnpm-debug.log*
14+
15+
# Diagnostic reports (https://nodejs.org/api/report.html)
16+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17+
18+
# Runtime data
19+
pids
20+
*.pid
21+
*.seed
22+
*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
lib-cov
26+
27+
# Coverage directory used by tools like istanbul
28+
coverage
29+
*.lcov
30+
31+
# nyc test coverage
32+
.nyc_output
33+
34+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
35+
.grunt
36+
37+
# Bower dependency directory (https://bower.io/)
38+
bower_components
39+
40+
# node-waf configuration
41+
.lock-wscript
42+
43+
# Compiled binary addons (https://nodejs.org/api/addons.html)
44+
build/Release
45+
46+
# Dependency directories
47+
node_modules/
48+
jspm_packages/
49+
50+
# Snowpack dependency directory (https://snowpack.dev/)
51+
web_modules/
52+
53+
# TypeScript cache
54+
*.tsbuildinfo
55+
56+
# Optional npm cache directory
57+
.npm
58+
59+
# Optional eslint cache
60+
.eslintcache
61+
62+
# Microbundle cache
63+
.rpt2_cache/
64+
.rts2_cache_cjs/
65+
.rts2_cache_es/
66+
.rts2_cache_umd/
67+
68+
# Optional REPL history
69+
.node_repl_history
70+
71+
# Output of 'npm pack'
72+
*.tgz
73+
74+
# Yarn Integrity file
75+
.yarn-integrity
76+
77+
# dotenv environment variables file
78+
.env
79+
.env.test
80+
.env.production
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# Serverless directories
104+
.serverless/
105+
106+
# FuseBox cache
107+
.fusebox/
108+
109+
# DynamoDB Local files
110+
.dynamodb/
111+
112+
# TernJS port file
113+
.tern-port
114+
115+
# Stores VSCode versions used for testing VSCode extensions
116+
.vscode-test
117+
118+
# yarn v2
119+
.yarn/cache
120+
.yarn/unplugged
121+
.yarn/build-state.yml
122+
.yarn/install-state.gz
123+
.pnp.*
124+
125+
# End of https://www.toptal.com/developers/gitignore/api/node

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:12-alpine
2+
3+
COPY index.js /index.js
4+
COPY ["package.json", "package-lock.json*", "./"]
5+
6+
RUN npm i
7+
8+
RUN npm i -g arweave-deploy@1.9.0
9+
10+
ENTRYPOINT ["node", "/index.js"]

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Raúl García
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Arweave-upload-file v1
2+
3+
## Overview
4+
5+
This action will allow you to upload a file to the Arweave permaweb in an easy manner during your action workflows, with just a couple inputs.
6+
7+
It uses [Arweave-deploy](https://github.com/ArweaveTeam/arweave-deploy) under the hood, wrapping the CLI into an easy-to-use action for developers or any interested party.
8+
9+
If your use case requires the upload of a directory, please refer to [rgbrota/arweave-upload-directory](https://github.com/rgbrota/arweave-upload-directory).
10+
## Usage
11+
12+
See [action.yml](action.yml).
13+
14+
### Inputs
15+
16+
The action expects the following inputs:
17+
18+
| Input | Type | Required | Default | Description |
19+
| --- | --- | :---: | :---: | --- |
20+
| `key_file_content` | JSON | ✔️ | - | The content of the Arweave key file JSON used to upload the data. It should be setup as a secret inside the repository. |
21+
| `file_path` | String | ✔️ | - | Path of the file to be uploaded. |
22+
| `ipfs` | Boolean || `false` | Upload to IPFS as well (experimental). |
23+
| `package` | Boolean || `false` | Package HTML dependencies into a single self-contained file. |
24+
### Outputs
25+
26+
The action also has the following outputs:
27+
28+
| Output | Type | Description |
29+
| --- | --- | --- |
30+
| `arweave_url` | String | Arweave URL where the uploaded file will be available once mined. |
31+
| `ipfs_url` | String | IPFS URL where the uploaded file will be available once mined, if the input ```ipfs``` was set to true. |
32+
| `cost` | Integer | Total cost of the transaction in the Arweave blockchain currency, AR. |
33+
### Examples
34+
#### Upload a file - basic usage
35+
36+
```yaml
37+
steps:
38+
- uses: actions/checkout@v2
39+
40+
- uses: rgbrota/arweave-upload-file@v1
41+
with:
42+
key_file_content: ${{ secrets.xx }}
43+
file_path: 'xx'
44+
```
45+
46+
#### Upload a file - Arweave + IPFS
47+
48+
```yaml
49+
steps:
50+
- uses: actions/checkout@v2
51+
52+
- uses: rgbrota/arweave-upload-file@v1
53+
with:
54+
key_file_content: ${{ secrets.xx }}
55+
file_path: 'xx'
56+
ipfs: true
57+
```
58+
59+
#### Upload a file - Packing HTML and dependencies
60+
61+
```yaml
62+
steps:
63+
- uses: actions/checkout@v2
64+
65+
- uses: rgbrota/arweave-upload-file@v1
66+
with:
67+
key_file_content: ${{ secrets.xx }}
68+
file_path: 'xx'
69+
package: true
70+
```

action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Arweave upload file
2+
name: 'Arweave upload file'
3+
description: 'Upload a file to the Arweave blockchain'
4+
inputs:
5+
key_file_content:
6+
description: 'Arweave key file content'
7+
required: true
8+
default: false
9+
file_path:
10+
description: 'Path to the file to be uploaded'
11+
required: true
12+
default: false
13+
package:
14+
description: 'Package HTML dependencies into a single self-contained file'
15+
required: false
16+
default: false
17+
ipfs:
18+
description: 'Upload to IPFS as well (experimental)'
19+
required: false
20+
default: false
21+
outputs:
22+
arweave_url:
23+
description: 'The Arweave URL your file will be available at once mined'
24+
ipfs_url:
25+
description: 'The IPFS URL your file will be available at once mined'
26+
cost:
27+
description: 'Transaction cost'
28+
runs:
29+
using: 'docker'
30+
image: 'Dockerfile'
31+
args:
32+
- ${{ inputs.key-file-content }}
33+
- ${{ inputs.file-path }}
34+
- ${{ inputs.package }}
35+
- ${{ inputs.ipfs }}
36+
branding:
37+
icon: 'file-plus'
38+
color: 'gray-dark'

index.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
const core = require("@actions/core");
2+
const exec = require("@actions/exec");
3+
const jsonfile = require("jsonfile");
4+
5+
const commands = {
6+
uploadFile: "arweave deploy",
7+
};
8+
9+
const flags = {
10+
deploy: {
11+
ipfs: "--ipfs-publish",
12+
keyFile: "--key-file",
13+
package: "--package",
14+
skipConfirmation: "--force-skip-confirmation",
15+
},
16+
};
17+
18+
const paths = {
19+
keyFile: "keyfile.json",
20+
};
21+
22+
const outputs = {
23+
arweaveUrl: "arweave_url",
24+
ipfsUrl: "ipfs_url",
25+
cost: "cost",
26+
};
27+
28+
async function run() {
29+
try {
30+
const inputs = {
31+
keyFileContent: JSON.parse(core.getInput("KEY_FILE_CONTENT")),
32+
filePath: core.getInput("FILE_PATH"),
33+
package: core.getInput("PACKAGE").toLowerCase() === "true",
34+
ipfs: core.getInput("IPFS").toLowerCase() === "true",
35+
};
36+
37+
jsonfile
38+
.writeFile(paths.keyFile, inputs.keyFileContent)
39+
.then(async () => {
40+
const args = [
41+
inputs.filePath,
42+
flags.deploy.keyFile,
43+
paths.keyFile,
44+
flags.deploy.skipConfirmation,
45+
...(inputs.package ? [flags.deploy.package] : []),
46+
...(inputs.ipfs ? [flags.deploy.ipfs] : []),
47+
];
48+
49+
let commandOutput = "";
50+
const options = {
51+
listeners: {
52+
stdout: (data) => {
53+
commandOutput += data.toString();
54+
},
55+
},
56+
};
57+
58+
await exec.exec(commands.uploadFile, args, options);
59+
60+
const result = getResults(commandOutput, inputs.ipfs);
61+
62+
core.setOutput(outputs.arweaveUrl, result.arweaveUrl);
63+
core.setOutput(outputs.ipfsUrl, result.ipfsUrl);
64+
core.setOutput(outputs.cost, result.cost);
65+
})
66+
.catch((error) => {
67+
core.setFailed(error.message);
68+
});
69+
} catch (error) {
70+
core.setFailed(error.message);
71+
}
72+
}
73+
74+
function getResults(output, ipfs) {
75+
// Ugly function, but the output data is not structured, just a huuge string
76+
const splittedOutput = output.split("\n");
77+
78+
const indexes = {
79+
arweaveUrlIndex: splittedOutput.findIndex(e => e.includes("https://arweave.net")),
80+
ipfsUrlIndex: ipfs && splittedOutput.findIndex(e => e.includes("https://ipfs.io")),
81+
costIndex: splittedOutput.findIndex(e => e.includes("Price")),
82+
};
83+
84+
return {
85+
arweaveUrl: splittedOutput[indexes.arweaveUrlIndex],
86+
ipfsUrl: ipfs ? splittedOutput[indexes.ipfsUrlIndex] : "",
87+
cost: splittedOutput[indexes.costIndex].split(" ")[1],
88+
};
89+
}
90+
91+
run();

0 commit comments

Comments
 (0)