Skip to content

Commit ca3b376

Browse files
gobengodmitrizagidulin
authored andcommitted
add wasup
1 parent bc01832 commit ca3b376

9 files changed

Lines changed: 479 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
name: Upload to Wallet Attached Storage (WASUP)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
inputs:
10+
environment:
11+
description: GitHub Environment to use
12+
required: false
13+
space:
14+
description: URL of Data Space
15+
required: false
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
publish:
22+
name: Publish to WAS
23+
runs-on: ubuntu-latest
24+
environment: ${{ inputs.environment}}
25+
steps:
26+
- name: Check out repository
27+
uses: actions/checkout@v4
28+
29+
- name: Print branch name
30+
run: |
31+
echo "Current branch: ${GITHUB_REF##*/}"
32+
33+
- name: Get Repository URL and Branch Name
34+
run: |
35+
echo "Repository URL: https://github.com/${{ github.repository }}"
36+
37+
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
38+
echo "Source Branch: ${{ github.head_ref }}"
39+
else
40+
echo "Branch Name: ${GITHUB_REF##*/}"
41+
fi
42+
43+
- if: ${{ github.event_name == 'pull_request' }}
44+
name: Get PR Source Branch URL
45+
id: getGitHubPrSourceUrl
46+
run: |
47+
echo "GITHUB_PR_SOURCE_URL=https://github.com/${{ github.repository }}/tree/${{ github.head_ref }}" >> $GITHUB_OUTPUT
48+
- if: ${{ github.event_name != 'pull_request' }}
49+
name: Get Current Branch URL
50+
id: getGitHubBranchUrl
51+
run: |
52+
echo "GITHUB_REF_BRANCH_URL=https://github.com/${{ github.repository }}/tree/${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
53+
54+
- id: echoGitHubUrl
55+
run: |
56+
echo "GITHUB_BRANCH_URL=${{ steps.getGitHubPrSourceUrl.outputs.GITHUB_PR_SOURCE_URL || steps.getGitHubBranchUrl.outputs.GITHUB_REF_BRANCH_URL }}" >> $GITHUB_OUTPUT
57+
58+
- run: echo "GITHUB_BRANCH_URL=${{ steps.echoGitHubUrl.outputs.GITHUB_BRANCH_URL }}" >> $GITHUB_ENV
59+
- run: echo "GITHUB_BRANCH_URL=$GITHUB_BRANCH_URL"
60+
61+
# Ok now we can finally build a URL to the branch on GitHub,
62+
# which should be based on the PR Source, if there is one,
63+
# otherwise the current branch.
64+
- if: ${{ steps.echoGitHubUrl.outputs }}
65+
run: echo "SPACE_SUBJECT=${{ steps.echoGitHubUrl.outputs.GITHUB_BRANCH_URL }}" >> $GITHUB_ENV
66+
67+
- run: echo "SPACE_SUBJECT=$SPACE_SUBJECT"
68+
- id: echoSpaceSubjectCuuid
69+
run: |
70+
RFC962_NSID_URL='6ba7b811-9dad-11d1-80b4-00c04fd430c8'
71+
echo -n "$SPACE_SUBJECT" | npx -y cuuid-sha-256 --namespace "$RFC962_NSID_URL"
72+
echo "SPACE_SUBJECT_CUUID=$(echo -n "$SPACE_SUBJECT" | npx -y cuuid-sha-256 --namespace "$RFC962_NSID_URL")" >> $GITHUB_OUTPUT
73+
74+
- run: echo "SPACE_SUBJECT_CUUID=${{ steps.echoSpaceSubjectCuuid.outputs.SPACE_SUBJECT_CUUID }}" >> $GITHUB_ENV
75+
- run: echo "SPACE_SUBJECT_CUUID=$SPACE_SUBJECT_CUUID"
76+
77+
- id: echoSpaceUrl
78+
env:
79+
SPACE_UUID: "${{ steps.echoSpaceSubjectCuuid.outputs.SPACE_SUBJECT_CUUID }}"
80+
run: |
81+
echo "spaceUrl=https://storage.bengo.is/space/$SPACE_UUID" >> "$GITHUB_OUTPUT"
82+
83+
# Set up node.js
84+
- name: Setup Node.js
85+
if: ${{ hashFiles('package.json') != '' }}
86+
id: setup-node
87+
uses: actions/setup-node@v4
88+
with:
89+
node-version: 24
90+
cache: npm
91+
92+
- name: Install Dependencies
93+
id: npm-ci
94+
run: npm ci
95+
# npm prepare scripts will run builds, so build-time envs go here
96+
# env:
97+
# BASE_URL: "/space/${{ steps.readDefaultSpaceUuid.outputs.content }}/"
98+
99+
100+
# - name: 'Setup jq'
101+
# uses: dcarbone/install-jq-action@v3
102+
- run: echo "char count of WASUP_ID is $(echo "$WASUP_ID" | wc -c)"
103+
env:
104+
WASUP_ID: "${{ secrets.WASUP_ID }}"
105+
- run: npx wasupdoc --help
106+
- run: echo "$WASUP_ID" | npx wasupdoc --controller /dev/stdin
107+
env:
108+
WASUP_ID: "${{ secrets.WASUP_ID }}"
109+
110+
- run: ./scripts/ci-space.json.sh
111+
env:
112+
WASUP_ID: "${{ secrets.WASUP_ID }}"
113+
WASUP_REACT_SPACE_UUID: "${{ steps.echoSpaceSubjectCuuid.outputs.SPACE_SUBJECT_CUUID }}"
114+
115+
- run: |
116+
SPACE_JSON="$(./scripts/ci-space.json.sh)"
117+
echo "SPACE_JSON<<EOF" >> $GITHUB_OUTPUT
118+
echo "$SPACE_JSON" >> $GITHUB_OUTPUT
119+
echo "EOF" >> $GITHUB_OUTPUT
120+
env:
121+
WASUP_ID: "${{ secrets.WASUP_ID }}"
122+
WASUP_REACT_SPACE_UUID: "${{ steps.echoSpaceSubjectCuuid.outputs.SPACE_SUBJECT_CUUID }}"
123+
id: echoSpaceJson
124+
125+
- run: |
126+
echo SPACE_JSON:
127+
echo "${{ steps.echoSpaceJson.outputs.SPACE_JSON }}"
128+
129+
- run: echo SPACE_JSON=$SPACE_JSON
130+
env:
131+
SPACE_JSON: "${{ steps.echoSpaceJson.outputs.SPACE_JSON }}"
132+
133+
- run: npm i -g https://github.com/gobengo/wasup
134+
- run: |
135+
WASUP_ID_FILE="$RUNNER_TEMP"/WASUP_ID
136+
trap 'rm -f $WASUP_ID_FILE' EXIT
137+
echo "$WASUP_ID" > "$WASUP_ID_FILE"
138+
echo "$SPACE_JSON" | wasup /dev/stdin "$SPACE_URL" --identity "$WASUP_ID_FILE" -v
139+
wasup README.md "$SPACE_URL"/README.md --identity "$WASUP_ID_FILE" -v
140+
141+
# add linkset.json
142+
echo "creating linkset with uuid $WASUP_REACT_SPACE_UUID"
143+
LINKSET_JSON="$(./scripts/linkset.json.ts --uuid "$WASUP_REACT_SPACE_UUID")"
144+
LINKSET_JSON_FILE="$RUNNER_TEMP"/LINKSET_JSON
145+
LINKSET_JSON_URL="$SPACE_URL/linkset.json"
146+
echo "$LINKSET_JSON" > "$LINKSET_JSON_FILE"
147+
wasup --content-type application/linkset+json "$LINKSET_JSON_FILE" "$LINKSET_JSON_URL" --identity "$WASUP_ID_FILE" -v
148+
echo "wrote $LINKSET_JSON_URL"
149+
150+
# add acl.json
151+
echo "creating acl with uuid $WASUP_REACT_SPACE_UUID"
152+
ACL_JSON="$(./scripts/acl.json.ts)"
153+
ACL_JSON_FILE="$RUNNER_TEMP"/ACL_JSON
154+
ACL_JSON_URL="$SPACE_URL/acl.json"
155+
echo "$ACL_JSON" > "$ACL_JSON_FILE"
156+
wasup --content-type application/json "$ACL_JSON_FILE" "$ACL_JSON_URL" --identity "$WASUP_ID_FILE" -v
157+
echo "wrote ACL_JSON_URL=$ACL_JSON_URL"
158+
env:
159+
SPACE_URL: "${{ steps.echoSpaceUrl.outputs.spaceUrl }}"
160+
SPACE_JSON: "${{ steps.echoSpaceJson.outputs.SPACE_JSON }}"
161+
WASUP_ID: "${{ secrets.WASUP_ID }}"
162+
WASUP_REACT_SPACE_UUID: "${{ steps.echoSpaceSubjectCuuid.outputs.SPACE_SUBJECT_CUUID }}"
163+
164+
# We want the same html to be served in response to /, /foo/, /foo/bar/, etc.
165+
# That html has script and link tags required to work.
166+
# What href should they use? /space/$WASUP_REACT_SPACE_UUID/
167+
# Assign that as BASE_URL and prepare the website,
168+
# which will update ../../website/build/client/index.html to use the new BASE_URL
169+
- name: re prepare website with BASE_URL="$WASUP_REACT_SPACE_UUID"
170+
run: |
171+
npm -w website run prepare
172+
env:
173+
BASE_URL: "/space/${{ steps.echoSpaceSubjectCuuid.outputs.SPACE_SUBJECT_CUUID }}/"
174+
175+
- name: Publish to WAS
176+
id: test-action
177+
uses: gobengo/wallet-attached-storage-action@main
178+
with:
179+
space: "${{ steps.echoSpaceUrl.outputs.spaceUrl }}"
180+
id: "${{ secrets.WASUP_ID }}"
181+
# ACTIONS_STEP_DEBUG: "${{ inputs.ACTIONS_STEP_DEBUG }}"
182+
files: "${{ inputs.files || './website/build/client/*' }}"
183+
filesStripPrefix: "${{ inputs.filesStripPrefix || 'website/build/client/' }}"
184+
185+
- name: Print Space URL
186+
id: output-space
187+
run: echo "${{ steps.test-action.outputs.space }}"
188+
189+
- run: |
190+
echo "# Publish Summary" >> $GITHUB_STEP_SUMMARY
191+
echo "" >> $GITHUB_STEP_SUMMARY
192+
echo "## Space" >> $GITHUB_STEP_SUMMARY
193+
echo "<${{ steps.test-action.outputs.space }}>" >> $GITHUB_STEP_SUMMARY
194+
echo "### Space Home Page" >> $GITHUB_STEP_SUMMARY
195+
echo "<${{ steps.test-action.outputs.space }}/>" >> $GITHUB_STEP_SUMMARY

scripts/acl.json.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env -S node --no-warnings
2+
3+
import { parseArgs } from 'node:util'
4+
const options = {
5+
}
6+
const args = parseArgs({ options })
7+
const acl = {
8+
type: "PublicCanRead"
9+
}
10+
console.info(JSON.stringify(acl, null, 2))

scripts/ci-space-cuuid.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from "child_process"
4+
5+
const env_WASUP_REACT_SPACE_UUID = globalThis?.process?.env?.WASUP_REACT_SPACE_UUID
6+
const uuid = env_WASUP_REACT_SPACE_UUID || crypto.randomUUID()
7+
console.debug(uuid)

scripts/ci-space.json.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
WASUP_ID="${WASUP_ID:-}"
3+
RUNNER_TEMP="${RUNNER_TEMP:-"$(mktemp -d)"}"
4+
TMP_WASUP_ID="$RUNNER_TEMP/WASUP_ID"
5+
6+
if [ -z "$WASUP_ID" ]; then
7+
echo "Error: WASUP_ID must be provided as an env var"
8+
exit 1
9+
fi
10+
11+
# write WASUP_ID to file so it can be used by wasupdoc to get the CONTROLLER_DID from it
12+
trap 'rm -f $TMP_WASUP_ID' EXIT
13+
echo "$WASUP_ID" > "$TMP_WASUP_ID"
14+
15+
CONTROLLER_DID="$(npx wasupdoc --controller "$TMP_WASUP_ID" | jq -r .controller)"
16+
CI_SPACE_CUUID="$(./scripts/ci-space-cuuid.ts)"
17+
18+
./scripts/space.json.ts \
19+
--controller "$CONTROLLER_DID" \
20+
--uuid "$CI_SPACE_CUUID"

scripts/did.json.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env -S node --no-warnings
2+
3+
const didDoc = {
4+
5+
}
6+
7+
console.debug(JSON.stringify(didDoc, null, 2))

scripts/linkset.json.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env -S node --no-warnings
2+
3+
import { parseArgs } from 'node:util'
4+
5+
const args = parseArgs({
6+
options: {
7+
server: {
8+
type: 'string',
9+
},
10+
uuid: {
11+
type: 'string',
12+
default: process.env.SPACE_UUID || crypto.randomUUID(),
13+
}
14+
}
15+
})
16+
const spaceUuid = args.values.uuid
17+
const id = `urn:uuid:${spaceUuid}`
18+
const SPACE_PATH = `/space/${spaceUuid}`
19+
const linkset = {
20+
"linkset": [
21+
{
22+
"anchor": `${SPACE_PATH}`,
23+
'serving-preference': [
24+
{
25+
type: 'DefaultHtml',
26+
href: `${SPACE_PATH}/index.html`,
27+
}
28+
]
29+
},
30+
{
31+
"anchor": `${SPACE_PATH}/`,
32+
"acl": [
33+
{
34+
"href": `${SPACE_PATH}/acl.json`
35+
}
36+
]
37+
},
38+
]
39+
}
40+
console.info(JSON.stringify(linkset, null, 2))

0 commit comments

Comments
 (0)