Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: update to work with w3up api #89

Merged
merged 13 commits into from
Jan 17, 2024
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

9 changes: 0 additions & 9 deletions .github/dependabot.yml

This file was deleted.

19 changes: 3 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,14 @@ on:
- 'releases/*'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- uses: bahmutov/npm-install@v1
- run: npm run lint
- run: npm test
env:
INPUT_WEB3_TOKEN: ${{ secrets.WEB3_STORAGE_TOKEN }}

run-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ./
with:
web3_api: 'https://api-staging.web3.storage'
web3_token: ${{ secrets.WEB3_STORAGE_TOKEN }}
proof: ${{ secrets.W3_PROOF }}
secret_key: ${{ secrets.W3_PRINCIPAL }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider using same names here instead of secret key and principal?

path_to_add: 'test/fixtures'
# test non default option
include_hidden: true
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<h1 align="center">⁂<br/>web3.storage</h1>
<p align="center">Add a directory to web3.storage from an Action, and output it's IPFS Content ID.</p>
# add-to-web3

! v3 of this action will work with the new w3up api once https://github.com/web3-storage/add-to-web3/issues/87 lands.
Upload files to web3.storage from a Github Action, and output it's IPFS Content ID.

_A composite github action. It's [just yaml](./action.yml) calling [w3cli](https://github.com/web3-storage/w3cli_

olizilla marked this conversation as resolved.
Show resolved Hide resolved
## Example usage

```yaml
uses: web3-storage/add-to-web3@v2
id: web3
uses: web3-storage/add-to-web3@v3
id: w3
with:
web3_token: ${{ secrets.WEB3_STORAGE_TOKEN }}
path_to_add: 'dist'
proof: ${{ secrets.W3_PROOF }}
secret_key: ${{ secrets.W3_PRINCIPAL }}

# "bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am"
- run: echo ${{ steps.web3.outputs.cid }}
- run: echo ${{ steps.w3.outputs.cid }}

# "https://dweb.link/ipfs/bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am"
- run: echo ${{ steps.web3.outputs.url }}
# "https://bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am.ipfs.w3s.link"
- run: echo ${{ steps.w3.outputs.url }}
```

## Inputs
Expand All @@ -25,24 +27,20 @@ with:

**Required** The path the root directory of your static website or other content that you want to publish to IPFS.

### `web3_token`

**Required** API token for web3.storage
### `secret_key`

<details>
<summary>Show advanced options: <code>wrap_with_directory</code>, <code>include_hidden</code>, <code>web3_api</code></summary>
**Required** The base64 key to use to sign ucan invocations to web3.storage.

olizilla marked this conversation as resolved.
Show resolved Hide resolved
### `wrap_with_directory`

_Default_ `false`
Create one using `w3 key create`. See: https://github.com/web3-storage/w3cli#w3_principal

Should the `path_to_add` be wrapped in a diretory when creating the IPFS DAG. For most folks using this action the default of `false` is fine.
### `proof`

This is the opposite of the default that web3.storage uses, as this action is commonly used to add a directory that contains a static website to IPFS. In that case you want the path_to_add to become the root cid so you can host your site at `https://<cid>.ipfs.dweb.link` rather than `https://<cid>.ipfs.dweb.link/<path_to_add>`.
**Required** A base64 encoded UCAN delegating capabilities the signing key above.

If you do want to capture the `path_to_add` path itself in the IPFS DAG then you want to set `wrap_with_directory:true`.
Create using `w3 delegation create --base64`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we mention in the docs that delegation can be narrowed to a set of capabilities and they should make it only for their needs pointing to the docs https://github.com/web3-storage/w3cli?tab=readme-ov-file#w3-delegation-create-audience-did ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it is good practice for us to recommend restricting caps.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may even be a good idea to change this to use limited capability set because this action only uploads no need to give the read access to it.

see: https://web3.storage/docs/reference/js-client-library#parameters
<details>
<summary>Show advanced options: <code>include_hidden</code>, <code>no_wrap</code></summary>

### `include_hidden`

Expand All @@ -52,11 +50,12 @@ Should hidden files prefixed with a `.` be included when found in the `path_to_a

see: https://github.com/web3-storage/files-from-path#filesfrompath

### `web3_api`

_Default_ `https://api.web3.storage`
### `no_wrap`

_Default_ `false`

Useful for testing against staging deployments by setting to the api origin of your choice.
Advanced: if `path_to_add` points to a file it will be wrapped in a directory to preserve the filename. To disable that set no_wrap: "true".

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I find no_wrap bit confusing, was wondering maybe it would be better to just make things more explicit by replacing path_to_add with dir_to_add and file_to_add where later could have wrap_file option.

</details>

Expand All @@ -72,11 +71,8 @@ e.g. `bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am`
The IPFS gateway URL for the directory
e.g. `https://dweb.link/ipfs/bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am`


## Contibuting

💌 Considerate contributions welcome!

The `dist` folder is commited to the repo as is the curious cultural norm with JS actions, as the repo is the delivery mechanism, so to spare some cycles for the user users, all the deps are bundled into a single /dist/index.js monolith.

<h3 align="center"><a href="https://web3.storage">⁂</a></h3>
61 changes: 48 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,65 @@ author: olizilla
branding:
icon: 'box'
color: 'white'

inputs:
path_to_add:
description: 'Directory path to add to IPFS'
required: true

secret_key:
description: 'The base64 key to use to sign ucan invocations. Create one using `w3 key create`. See: https://github.com/web3-storage/w3cli#w3_principal'
olizilla marked this conversation as resolved.
Show resolved Hide resolved
required: true

proof:
description: 'A base64 encoded UCAN delegating capabilities the signing key above. Create using `w3 delegation create --base64`'
olizilla marked this conversation as resolved.
Show resolved Hide resolved
required: true

include_hidden:
description: 'Include hidden files'
description: 'Include paths that start with "."'
required: false
default: 'false'
web3_token:
description: 'API token for web3.storage'
required: true
web3_api:
description: 'API URL'
required: false
default: 'https://api.web3.storage'
wrap_with_directory:
description: 'Boolean. Default: `false`. Should the path_to_add be wrapped in a diretory when creating the IPFS DAG. For most folks using this, the default of `false` is fine. If you want to add a single file and preserve the filename in the IPFS DAG you may want to set it to `true`.'

no_wrap:
description: 'Advanced: if `path_to_add` points to a file it will be wrapped in a directory to preserve the filename. To disable that set no_wrap: "true"'
required: false
default: 'false'

outputs:
cid:
description: 'The IPFS Content ID for the directory'
description: 'The IPFS Content ID for path_to_add'
value: ${{ steps.get_cid.outputs.cid }}

url:
description: 'The IPFS Gateway URL'
value: ${{ steps.get_url.outputs.url }}

runs:
using: 'node16'
main: 'dist/index.js'
using: "composite"
steps:
# Use the branch while testing.
- run: npm install -g github:web3-storage/w3cli#stringify
shell: bash

- run: w3 space add ${{ inputs.proof }}
env:
W3_PRINCIPAL: ${{ inputs.secret_key }}
shell: bash

- run: w3 up ${{ inputs.path_to_add }} --json | tee ./w3_up_output.json
env:
W3_PRINCIPAL: ${{ inputs.secret_key }}
shell: bash

# expect `./w3_up_output.json` to contain "{ "root": { "/": "bafy..." }}
- name: fail if no CID in response
run: jq --exit-status --raw-output '.root."/"' ./w3_up_output.json
shell: bash

- id: get_cid
run: echo "::set-output name=cid::$(jq --exit-status --raw-output '.root."/"' ./w3_up_output.json)"
shell: bash

- id: get_url
run: echo "::set-output name=url::https://${{ steps.get_cid.outputs.cid }}.ipfs.w3s.link"
shell: bash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecation warning

Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Loading
Loading