Skip to content

Commit

Permalink
feat: upgrade to bee-js 8 (#215)
Browse files Browse the repository at this point in the history
* feat: upgrade to bee-js 8

* fix: fix pr-preview action yaml

* fix: add noop to bash

* fix: fix backtick escaping
  • Loading branch information
Cafe137 authored Oct 22, 2024
1 parent b012f54 commit f4b43d8
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 139 deletions.
70 changes: 37 additions & 33 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"license": "BSD-3-Clause",
"dependencies": {
"@actions/core": "^1.10.1",
"@ethersphere/bee-js": "^7.1.1"
"@ethersphere/bee-js": "^8.1.0",
"cafe-utility": "^23.9.0"
},
"devDependencies": {
"@tsconfig/node18": "^18.2.4",
Expand Down
6 changes: 3 additions & 3 deletions pr-preview/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ runs:
if [ "${{ inputs.index-document }}" = "false" ]
then
# Do nothing (equivalent to setting document to empty string)
:
elif [ ! -z "${{ inputs.index-document }}" ]
then
# Set document to the specified value
Expand Down Expand Up @@ -143,14 +144,13 @@ runs:
uses: peter-evans/create-or-update-comment@v1
with:
token: ${{ inputs.token }}
comment-id: ${{ steps.comment.outputs.comment-id  
} } # Likely uses step output directly
comment-id: ${{ steps.comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## 🐝 PR preview in Swarm
**Preview URL:** ${{ steps.metadata.outputs.bzz-link }}
**Swarm Hash:** `${{ steps.upload.outputs.reference }}
**Swarm Hash:** `${{ steps.upload.outputs.reference }}`
**Commit Hash:** ${{ github.event.pull_request.head.sha }}
**Commit Message:** ${{ steps.commit.outputs.result }}
edit-mode: replace
14 changes: 0 additions & 14 deletions swarm-actions-libs/package.json

This file was deleted.

21 changes: 0 additions & 21 deletions swarm-actions-libs/src/headers.ts

This file was deleted.

1 change: 0 additions & 1 deletion swarm-actions-libs/src/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions swarm-actions-libs/tsconfig.json

This file was deleted.

3 changes: 0 additions & 3 deletions upload-dir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@
"package": "ncc build --source-map --license licenses.txt",
"ci:package": "npm run build && npm run package",
"all": "npm run build && npm run format && npm run lint && npm run package"
},
"dependencies": {
"swarm-actions-libs": "^0.0.0"
}
}
36 changes: 20 additions & 16 deletions upload-dir/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as core from '@actions/core'
import type { BatchId, BeeRequestOptions, CollectionUploadOptions } from '@ethersphere/bee-js'
import { BATCH_ID_HEX_LENGTH, Bee } from '@ethersphere/bee-js'
import { parseHeaders } from 'swarm-actions-libs'
import { toBoolean, toNumber, toString } from './options'
import { Bee } from '@ethersphere/bee-js'
import { Objects, Types } from 'cafe-utility'
import { toBoolean, toNumber } from './options'

type Inputs = {
beeUrl: string
Expand All @@ -13,38 +13,42 @@ type Inputs = {
requestOptions: BeeRequestOptions
}

const run = async ({ beeUrl, postageBatchId, dir, headers, options, requestOptions }: Inputs): Promise<void> => {
const bee = new Bee(beeUrl, { headers })
const { reference, tagUid } = await bee.uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions)
async function run(inputs: Inputs) {
const bee = new Bee(inputs.beeUrl, { headers: inputs.headers })
const { reference, tagUid } = await bee.uploadFilesFromDirectory(
inputs.postageBatchId,
inputs.dir,
inputs.options,
inputs.requestOptions
)
core.setOutput('reference', reference)
core.setOutput('tagUid', tagUid)
}

const main = async (): Promise<void> => {
const postageBatchId = core.getInput('postage-batch-id', { required: true })
if (postageBatchId.length !== BATCH_ID_HEX_LENGTH) {
throw new Error(`postage-batch-id must be ${BATCH_ID_HEX_LENGTH} characters long`)
}
async function main() {
const postageBatchId = Types.asHexString(core.getInput('postage-batch-id', { required: true }), {
name: 'postage-batch-id',
byteLength: 32,
}) as BatchId

const options: CollectionUploadOptions = {
deferred: toBoolean(core.getInput('deferred')),
encrypt: toBoolean(core.getInput('encrypt')),
errorDocument: toString(core.getInput('error-document')),
indexDocument: toString(core.getInput('index-document')),
errorDocument: core.getInput('error-document'),
indexDocument: core.getInput('index-document'),
pin: toBoolean(core.getInput('pin')),
tag: toNumber(core.getInput('tag')),
}

const requestOptions: BeeRequestOptions = {
retry: toNumber(core.getInput('retry')),
timeout: toNumber(core.getInput('timeout')),
}

return run({
beeUrl: core.getInput('bee-url', { required: true }),
dir: core.getInput('dir', { required: true }),
postageBatchId: postageBatchId as BatchId,
headers: parseHeaders(core.getInput('headers')),
postageBatchId,
headers: Objects.parseKeyValues(core.getMultilineInput('headers')),
options,
requestOptions,
})
Expand Down
2 changes: 0 additions & 2 deletions upload-dir/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ export const toNumber = (value: string): number | undefined => {
}
return number
}

export const toString = (value: string): string => value
3 changes: 1 addition & 2 deletions write-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"all": "npm run build && npm run format && npm run lint && npm run package"
},
"dependencies": {
"ethereumjs-util": "^7.1.4",
"swarm-actions-libs": "^0.0.0"
"ethereumjs-util": "^7.1.4"
}
}
Loading

0 comments on commit f4b43d8

Please sign in to comment.