Skip to content

Commit

Permalink
Merge pull request #1 from SkynetLabs/resolver-skylink
Browse files Browse the repository at this point in the history
Version 2, replacing skyns with resolver skylinks and adding configurable portal url
  • Loading branch information
dghelm committed Aug 12, 2021
2 parents cc61320 + bc43806 commit f3c52d2
Show file tree
Hide file tree
Showing 1,292 changed files with 140,934 additions and 122,758 deletions.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Deploy to Skynet action

This action deploys a directory to [Skynet](https://siasky.net) and comments on pull request with a skylink url.
This action deploys a directory to Skynet and comments on pull request with a skylink url (defaults to [siasky.net](https://siasky.net) portal).

![Screenshot of Pull Request notification](screenshot.png)

Expand All @@ -22,7 +22,7 @@ Find out more about github token from [documentation](https://docs.github.com/en

### `registry-seed`

You can provide a seed (keep it secret, keep it safe) and this action will set corresponding skynet registry entry value to the deployed skylink.
You can provide a seed (keep it secret, keep it safe) and this action will set corresponding skynet registry entry value to the deployed resolver skylink.

Public link to the registry entry will be printed in the action log.

Expand All @@ -32,6 +32,12 @@ Default value: `skylink.txt`

You can define custom datakey for a registry entry when used with `registry-seed`. Change only if you want to use a specific key, default value will work in all other cases.

### `portal-url`

Default value: `https://siasky.net`

You can override default skynet portal url with any compatible community portal or self hosted one.

## Outputs

### `skylink`
Expand All @@ -46,10 +52,23 @@ The resulting skylink url (base32 encoded skylink in subdomain).

Example: `https://400bk2i89lheb6d8olltc2grqgfaqfge1im134ed6q1ro0g0fbnk1to.siasky.net`

### `resolver-skylink`

A resolver skylink pointing at the resulting skylink. Resolver skylink will remain the same throughout the deploys, but will always resolve to the latest deploy.

Example: `sia://AQDwh1jnoZas9LaLHC_D4-2yP9XYDdZzNtz62H4Dww1jDA`

### `resolver-skylink-url`

The resulting resolver skylink url (base32 encoded skylink in subdomain). Resolver skylink will remain the same throughout the deploys, but will always resolve to the latest deploy.

Example: `https://040f11qosugpdb7kmq5hobu3sfmr4fulr06tcspmrjtdgvg3oc6m630.siasky.net/`

## Example usage

```yaml
uses: SkynetLabs/deploy-to-skynet-action@v1
uses: SkynetLabs/deploy-to-skynet-action@v2

with:
upload-dir: public
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -71,10 +90,9 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14.x
node-version: 16.x

- name: Install dependencies
run: yarn
Expand All @@ -83,7 +101,8 @@ jobs:
run: yarn build

- name: Deploy to Skynet
uses: SkynetLabs/deploy-to-skynet-action@v1
uses: SkynetLabs/deploy-to-skynet-action@v2

with:
upload-dir: public
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
12 changes: 11 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ inputs:
required: true
registry-seed:
description: "Seed that generates registry private key (optional, only if you want to update the registry entry with skylink)"
required: false
registry-datakey:
description: "Registry datakey to use when updating the registry entry"
required: true
default: "skylink.txt"
portal-url:
description: "Skynet portal api url"
required: true
default: "https://siasky.net"
outputs:
skylink:
description: "Uploaded resource skylink"
skylink-url:
description: "Uploaded resource skylink url on https://siasky.net"
description: "Uploaded resource skylink url"
resolver-skylink:
description: "Resolver skylink pointing to uploaded resource"
resolver-skylink-url:
description: "Resolver skylink url (as a subdomain)"
runs:
using: "node12"
main: index.js
70 changes: 27 additions & 43 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
const core = require("@actions/core");
const github = require("@actions/github");
const { SkynetClient: NodeSkynetClient } = require("@nebulous/skynet");
const { parseSkylink, genKeyPairFromSeed, SkynetClient } = require("skynet-js");
const base64 = require("base64-js");
const base32Encode = require("base32-encode");
const parseUrl = require("parse-url");
const qs = require("qs");

function decodeBase64(input = "") {
return base64.toByteArray(
input.padEnd(input.length + 4 - (input.length % 4), "=")
);
}

function encodeBase32(input) {
return base32Encode(input, "RFC4648-HEX", {
padding: false,
}).toLowerCase();
}
const { genKeyPairFromSeed, SkynetClient } = require("skynet-js");

function outputAxiosErrorMessage(error) {
if (error.response) {
Expand All @@ -31,53 +15,53 @@ function outputAxiosErrorMessage(error) {
}
}

function createSkynsEntry(entryUrl) {
const { query } = parseUrl(entryUrl, {});
const { publickey, datakey } = qs.parse(query);

return `skyns://${encodeURIComponent(publickey)}/${datakey}`;
}

(async () => {
try {
// upload to skynet
const skynetClient = new NodeSkynetClient();
const skylink = await skynetClient.uploadDirectory(
const nodeClient = new NodeSkynetClient(core.getInput("portal-url"));
const skynetClient = new SkynetClient(core.getInput("portal-url"));
const skylink = await nodeClient.uploadDirectory(
core.getInput("upload-dir")
);

// generate base32 skylink url from base64 skylink
const skylinkUrl = await skynetClient.getSkylinkUrl(skylink, {
subdomain: true,
});

core.setOutput("skylink", skylink);
console.log(`Skylink: ${skylink}`);

// generate base32 skylink from base64 skylink
const rawSkylink = parseSkylink(skylink);
const skylinkDecoded = decodeBase64(rawSkylink);
const skylinkEncodedBase32 = encodeBase32(skylinkDecoded);
const skylinkUrl = `https://${skylinkEncodedBase32}.siasky.net`;

core.setOutput("skylink-url", skylinkUrl);
console.log(`Deployed to: ${skylinkUrl}`);

// if registry is properly configured, update the skylink in the entry
if (core.getInput("registry-seed") && core.getInput("registry-datakey")) {
try {
const skynetClient = new SkynetClient("https://siasky.net");
const seed = core.getInput("registry-seed");
const dataKey = core.getInput("registry-datakey");
const { publicKey, privateKey } = genKeyPairFromSeed(seed);
const { entry } = await skynetClient.registry.getEntry(
publicKey,
dataKey
);
const revision = entry ? entry.revision + 1 : 0;
const updatedEntry = { datakey: dataKey, revision, data: rawSkylink };
await skynetClient.registry.setEntry(privateKey, updatedEntry);
const entryUrl = skynetClient.registry.getEntryUrl(publicKey, dataKey);

const [entryUrl, resolverSkylink] = await Promise.all([
skynetClient.registry.getEntryUrl(publicKey, dataKey),
skynetClient.registry.getEntryLink(publicKey, dataKey),
skynetClient.db.setDataLink(privateKey, dataKey, skylink),
]);
const resolverUrl = await skynetClient.getSkylinkUrl(resolverSkylink, {
subdomain: true,
});

console.log(`Registry entry updated: ${entryUrl}`);
console.log(`Skyns entry: ${createSkynsEntry(entryUrl)}`);

core.setOutput("resolver-skylink-url", resolverUrl);
console.log(`Resolver Skylink Url: ${resolverUrl}`);

core.setOutput("resolver-skylink", resolverSkylink);
console.log(`Resolver Skylink: ${resolverSkylink}`);
} catch (error) {
outputAxiosErrorMessage(error);

console.log(`Failed to update registry entry ${error.message}`);
console.log(`Failed to update registry entry: ${error.message}`);
}
}

Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f3c52d2

Please sign in to comment.