Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/actions/standalone-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ runs:
if: inputs.verify-only != 'true' || hashFiles('released-source/scripts/build-sdk.mjs') != ''
shell: bash
working-directory: released-source
env:
RELEASE_TAG: ${{ inputs.tag }}
run: |
npm clean-install
# Vite embeds the current time. Use the tagged commit time for repeatable HTML.
Expand All @@ -75,6 +77,10 @@ runs:
NODE_OPTIONS="--require=$RUNNER_TEMP/release-clock.cjs" npm run build
if [[ -f scripts/build-sdk.mjs ]]; then
npm run check:sdk-dist
if [[ -f scripts/sdk-paths.mjs ]] && node -e "import('./scripts/sdk-paths.mjs').then(m => process.exit(typeof m.isArchiveReleaseVersion === 'function' && m.isArchiveReleaseVersion(process.argv[1]) ? 0 : 1))" "$RELEASE_TAG"; then
npm run build:sdk -- --release "$RELEASE_TAG"
npm run check:sdk-dist -- --release "$RELEASE_TAG"
fi
fi

- name: Verify and publish the standalone HTML
Expand Down Expand Up @@ -131,6 +137,12 @@ runs:
run: |
manifest="dist/sdk/v1/${RELEASE_TAG#v}/SHA256SUMS"
asset="DecodeBox-SDK-$RELEASE_TAG-SHA256SUMS"
if [[ -f scripts/sdk-paths.mjs ]] && grep -q 'isArchiveReleaseVersion' scripts/sdk-paths.mjs; then
if ! node -e "import('./scripts/sdk-paths.mjs').then(m => process.exit(m.isArchiveReleaseVersion(process.argv[1]) ? 0 : 1))" "$RELEASE_TAG"; then
test ! -e "$manifest"
exit 0
fi
fi
test -s "$manifest"
names=$(gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name')
if grep -Fxq "$asset" <<< "$names"; then
Expand Down
20 changes: 17 additions & 3 deletions .github/scripts/verify-release-cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ test('the release uploads only HTML and still verifies local and legacy SDK mani
const node = action.find(s => s.uses?.startsWith('actions/setup-node@'));
assert.equal(node.with['node-version'], "$" + "{{ hashFiles('released-source/scripts/build-sdk.mjs') != '' && '24.18.0' || '22.23.5' }}");
assert.match(action.find(s => s.id === 'build').run, /npm run check:sdk-dist/);
assert.match(action.find(s => s.id === 'build').run, /--release "\$RELEASE_TAG"/);
const directory = path.join(f.dir, 'dist/sdk/v1/0.1.2');
fs.mkdirSync(directory, { recursive: true });
const manifest = 'checksums\n';
Expand All @@ -299,6 +300,14 @@ test('the release uploads only HTML and still verifies local and legacy SDK mani
f.change(s => { s.manifest = 'different bytes'; });
f.shell(step, false);
assert.equal(f.read().manifest, 'different bytes');
// Patch releases under the PATCH=0 policy do not require or expect a versioned archive manifest.
fs.mkdirSync(path.join(f.dir, 'scripts'), { recursive: true });
fs.copyFileSync(path.resolve(__dirname, '../../scripts/sdk-paths.mjs'), path.join(f.dir, 'scripts/sdk-paths.mjs'));
fs.rmSync(directory, { recursive: true, force: true });
f.shell(step);
fs.mkdirSync(directory, { recursive: true });
fs.writeFileSync(path.join(directory, 'SHA256SUMS'), manifest);
f.shell(step, false);
});

test('workflow routes are exclusive and formatting requires the baseline and verified upload', t => {
Expand All @@ -307,13 +316,15 @@ test('workflow routes are exclusive and formatting requires the baseline and ver
assert.equal(normal.if, "github.ref == 'refs/heads/main' && inputs.release_tag == '' && inputs.repair_release_notes_tag == ''");
assert.equal(manual.if, "github.ref == 'refs/heads/main' && (inputs.release_tag != '' || inputs.repair_release_notes_tag != '')");
assert.deepEqual(manual.permissions, { contents: 'write', 'pull-requests': 'read' });
const [conflict, checkout, rebuild, verify, repair] = manual.steps;
assert.equal(manual.steps.length, 5);
const [conflict, checkout, rebuild, rebuildArchive, verify, repair] = manual.steps;
assert.equal(manual.steps.length, 6);
assert.equal(conflict.if, "inputs.release_tag != '' && inputs.repair_release_notes_tag != ''");
f.shell(conflict, false);
assert(checkout.uses.startsWith('actions/checkout@'));
assert.equal(rebuild.if, "inputs.release_tag != '' && inputs.repair_release_notes_tag == ''");
assert.equal(rebuild.uses, './.github/actions/standalone-release');
assert.equal(rebuildArchive.if, rebuild.if);
assert.match(rebuildArchive.run, /publish-gh-pages\.mjs/);
assert.equal(repair.if, "inputs.repair_release_notes_tag != '' && inputs.release_tag == ''");
assert.equal(rebuild.with['replace-standalone'], 'true');
assert.equal(verify.if, repair.if);
Expand All @@ -322,10 +333,13 @@ test('workflow routes are exclusive and formatting requires the baseline and ver
assert.equal(repair.run, 'node .github/scripts/publish-release-notes.cjs repair');
const tail = normal.steps.slice(normal.steps.findIndex(step => step.id === 'release'));
assert.deepEqual(tail.map(s => s.id || s.run), ['release', 'baseline', 'standalone',
'node .github/scripts/publish-release-notes.cjs format', 'node .github/scripts/release-notes.cjs']);
'node .github/scripts/publish-release-notes.cjs format', 'sdk-archive', 'node .github/scripts/release-notes.cjs']);
assert.equal(tail[1].if, "steps.release.outputs.release_created == 'true'");
assert.equal(tail[2].if, "success() && steps.baseline.outcome == 'success'");
assert.equal(tail[3].if, "success() && steps.release.outputs.release_created == 'true' && steps.baseline.outcome == 'success' && steps.standalone.outcome == 'success'");
assert.equal(tail[4].if, tail[3].if);
assert.match(tail[4].run, /isArchiveReleaseVersion/);
assert.match(tail[4].run, /publish-gh-pages\.mjs/);
assert.equal(upload.if, "success() && inputs.verify-only != 'true' && steps.build.outcome == 'success'");
assert.equal(tail[3].env.VERIFIED_DIGEST, '$' + '{{ steps.standalone.outputs.digest }}');
f.standalone();
Expand Down
97 changes: 38 additions & 59 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ name: Deploy to GitHub Pages
# only warned, and a warning inside a green run is indistinguishable from
# nothing at all — the site was blank for an afternoon while every check passed.
#
# The branch is force-pushed as a single orphan commit each time. The output is
# generated from source. Each tree carries its immutable SDK release directories forward.
# The branch is updated atomically via compare-and-swap (--force-with-lease) so
# ordinary site + latest SDK deployments and milestone official archive releases
# never overwrite each other's updates.

on:
push:
Expand All @@ -27,7 +28,8 @@ on:
permissions:
contents: read

# One publish at a time, and never cancel one part-way through a force-push.
# Serialize overlapping site deployments; cross-workflow races with milestone
# archive publication are resolved atomically via --force-with-lease retries.
concurrency:
group: github-pages
cancel-in-progress: false
Expand All @@ -39,8 +41,7 @@ jobs:
timeout-minutes: 15

permissions:
# The only privilege in this workflow, and it exists for one command: the
# push to gh-pages at the end.
# The only privilege in this workflow, and it exists for publishing to gh-pages.
contents: write
pages: read

Expand All @@ -64,47 +65,19 @@ jobs:
- name: Build
run: npm run build

- name: Check new SDK artifacts and retain published versions
env:
GH_TOKEN: ${{ github.token }}
run: |
npm run check:sdk-dist
settings=$(gh api "repos/$GITHUB_REPOSITORY/pages")
jq -e '.source.branch == "gh-pages" and .source.path == "/"' <<< "$settings" >/dev/null
domain=$(jq -r '.cname // empty' <<< "$settings")
previous_ref=$(git ls-remote --heads origin refs/heads/gh-pages)
if [[ -n "$previous_ref" ]]; then
git fetch --no-tags --depth=1 origin refs/heads/gh-pages
if [[ -z "$domain" ]] && git cat-file -e FETCH_HEAD:CNAME 2>/dev/null; then
domain=$(git show FETCH_HEAD:CNAME)
fi
if git cat-file -e FETCH_HEAD:sdk 2>/dev/null; then
previous=$(mktemp -d)
git archive FETCH_HEAD sdk | tar -x -C "$previous"
for series in "$previous"/sdk/v*; do
[[ -d "$series" ]] || continue
name=$(basename "$series")
[[ "$name" =~ ^v[0-9]+$ ]] || continue
for release in "$series"/*/; do
target="dist/sdk/$name/$(basename "$release")"
if [[ -d "$release" && -d "$target" ]]; then
diff -qr "$release" "$target"
fi
done
mkdir -p "dist/sdk/$name"
cp -an "$series/." "dist/sdk/$name/"
done
fi
fi
rm -f dist/CNAME
if [[ -n "$domain" ]]; then
printf '%s\n' "$domain" > dist/CNAME
fi

- name: Verify the build is static and complete
run: |
npm run check:sdk-dist
test -s dist/index.html || { echo "::error::dist/index.html is missing"; exit 1; }
test -s dist/decodebox.html || { echo "::error::dist/decodebox.html is missing - the download button would 404"; exit 1; }
node --experimental-vm-modules -e '
const fs = require("node:fs");
const vm = require("node:vm");
const html = fs.readFileSync("dist/decodebox.html", "utf8");
const match = /<script type="module">\n([\s\S]*?)\n<\/script>/.exec(html);
if (!match) throw new Error("Standalone module script missing.");
new vm.SourceTextModule(match[1]);
'
# The application must never call out to a third party at runtime. This is a
# coarse check, but it catches an accidental CDN reference before it ships.
if grep -rIloE 'https?://(cdn|unpkg|jsdelivr)' dist --include='*.js' --include='*.html' | head -1 | grep -q .; then
Expand All @@ -114,25 +87,19 @@ jobs:

- name: Publish to the gh-pages branch
env:
GH_TOKEN: ${{ github.token }}
TOKEN: ${{ github.token }}
run: |
# A branch-served site runs Jekyll over the branch by default. Nothing
# here wants it, and it silently drops anything whose name begins with
# an underscore, which is a poor way to lose part of a build.
touch dist/.nojekyll

# A throwaway repository holding only the output, pushed over whatever
# was there before. gh-pages is therefore always exactly one commit
# deep, and this repository never grows by deploying.
cd dist
git init --quiet --initial-branch=gh-pages
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add --all
git commit --quiet --message "Deploy $GITHUB_SHA"
git push --quiet --force \
"https://x-access-token:${TOKEN}@github.com/${GITHUB_REPOSITORY}.git" gh-pages
echo "Published $(git rev-parse --short HEAD) to gh-pages."
settings=$(gh api "repos/$GITHUB_REPOSITORY/pages")
jq -e '.source.branch == "gh-pages" and .source.path == "/"' <<< "$settings" >/dev/null
domain=$(jq -r '.cname // empty' <<< "$settings")
node scripts/publish-gh-pages.mjs \
--mode latest \
--dist dist \
--staging build/sdk \
--domain "$domain" \
--repo "$GITHUB_REPOSITORY" \
--commit-message "Deploy $GITHUB_SHA"

# A push to gh-pages is not a deployment. Pages still has to notice the
# branch moved, rebuild and serve it, and it will do none of that if it is
Expand Down Expand Up @@ -179,6 +146,18 @@ jobs:
*"$entry"*)
echo "$url is serving this build."
npm run check:sdk-dist -- dist "$url"
node -e "
import('./scripts/sdk-paths.mjs').then(async ({ OBSOLETE_ARCHIVE_DIRS }) => {
const base = process.argv[1].replace(/\/?$/, '/');
for (const dir of OBSOLETE_ARCHIVE_DIRS) {
const target = new URL(dir + '/decodebox.js', base);
const res = await fetch(target, { redirect: 'manual', signal: AbortSignal.timeout(30000) });
if (res.status !== 404) {
throw new Error('Obsolete archive path still accessible: ' + target + ' (' + res.status + ')');
}
}
});
" "$url"
node scripts/check-sdk-browser.mjs "${url%/}/"
exit 0
;;
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ jobs:
VERIFIED_DIGEST: ${{ steps.standalone.outputs.digest }}
run: node .github/scripts/publish-release-notes.cjs format

- name: Publish official SDK archive for milestone releases
id: sdk-archive
if: >-
success() && steps.release.outputs.release_created == 'true' && steps.baseline.outcome == 'success' &&
steps.standalone.outcome == 'success'
env:
TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.release.outputs.tag_name }}
run: |
if node -e "import('./scripts/sdk-paths.mjs').then(m => process.exit(m.isArchiveReleaseVersion(process.argv[1]) ? 0 : 1))" "$RELEASE_TAG"; then
node scripts/publish-gh-pages.mjs \
--mode archive \
--archive-root released-source/dist \
--release "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--commit-message "Publish SDK archive $RELEASE_TAG"
else
echo "Release $RELEASE_TAG has non-zero PATCH; skipping official SDK archive publication."
fi

- name: Create or update the Release Please PR
env:
GH_TOKEN: ${{ github.token }}
Expand Down Expand Up @@ -137,6 +157,23 @@ jobs:
tag: ${{ inputs.release_tag }}
replace-standalone: 'true'

- name: Publish official SDK archive for milestone release rebuild
if: inputs.release_tag != '' && inputs.repair_release_notes_tag == ''
env:
TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ inputs.release_tag }}
run: |
if node -e "import('./scripts/sdk-paths.mjs').then(m => process.exit(m.isArchiveReleaseVersion(process.argv[1]) ? 0 : 1))" "$RELEASE_TAG"; then
node scripts/publish-gh-pages.mjs \
--mode archive \
--archive-root released-source/dist \
--release "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--commit-message "Publish SDK archive $RELEASE_TAG"
else
echo "Release $RELEASE_TAG has non-zero PATCH; skipping official SDK archive publication."
fi

- name: Verify published assets for notes repair
if: inputs.repair_release_notes_tag != '' && inputs.release_tag == ''
uses: ./.github/actions/standalone-release
Expand Down
26 changes: 15 additions & 11 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ npm run build
npm run check:sdk-dist
```

The build writes the site to `dist/`, the offline application to `dist/decodebox.html`, and
the SDK to the [distribution paths](sdk/README.md#distribution). Use `npm run preview` for
the site, or open the standalone file from disk. `npm run build:sdk` rebuilds the SDK alone.
The distribution check executes both module formats and verifies alias bytes and release hashes.
CI also loads every JavaScript entry point in Chrome and checks SHA-256 with the Java provider.
To run the browser check against a local preview, use the URL printed by Vite.
The build writes the site to `dist/`, the offline application to `dist/decodebox.html`, the
latest SDK staging bundle and manifest to `build/sdk/`, and the latest SDK aliases under
`dist/` (see [distribution paths](sdk/README.md#distribution)). Use `npm run preview` for the
site, or open the standalone file from disk. `npm run build:sdk` rebuilds the latest SDK alone,
while `npm run build:sdk -- --release vX.Y.Z` builds an immutable milestone archive when
`PATCH` is zero. The distribution check executes both module formats and verifies alias bytes
and staging hashes. CI also loads every JavaScript entry point in Chrome and checks SHA-256
with the Java provider. To run the browser check against a local preview, use the URL printed
by Vite.

```sh
node scripts/check-sdk-browser.mjs http://localhost:4173/
Expand All @@ -37,8 +40,9 @@ also need contract tests in [src/sdk/sdk.test.ts](../src/sdk/sdk.test.ts) and an
update. Submit changes on a temporary branch targeting `main`.

Release Please manages the project version. The SDK's API major is independent of that version.
The Pages workflow builds from source, carries forward previous SDK releases and the configured
custom domain, and publishes generated files to the root of `gh-pages`. It stops if an existing
version directory would change. A changed release artifact needs a new engine version through
the normal release process. For tags that contain the SDK, the release workflow attaches
the matching checksum manifest. Production bundles and test output stay outside the source tree.
The Pages workflow builds from `main`, updates the website and latest SDK aliases (`/api`,
`/api.js`, `/sdk/*`), carries forward existing official milestone archives and the configured
custom domain, and publishes atomically to `gh-pages`. Official versioned archives under
`/sdk/v1/{version}/` are published from exact Git tags only for stable milestone releases
(`PATCH === 0`) and never overwrite existing archives. Production bundles and test output stay
outside the source tree.
17 changes: 9 additions & 8 deletions docs/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ and MIME types still need verification once the official files are published.
The SDK source lives in [src/sdk](../../src/sdk). The build writes the following static files
under `dist/`. After publication their paths are relative to `https://decodebox.owasp.org`.

| Format | Aliases that follow the current build | Immutable engine release |
| Format | Latest build aliases (`main` deployments) | Official milestone archive (`PATCH === 0` tags) |
| --- | --- | --- |
| Classic script, global `DecodeBox` | `/api`, `/api.js`, `/sdk/decodebox.js`, `/sdk/v1/decodebox.js` | `/sdk/v1/{engineVersion}/decodebox.js` |
| ES module | `/sdk/decodebox.mjs`, `/sdk/v1/decodebox.esm.js` | `/sdk/v1/{engineVersion}/decodebox.mjs` |
| TypeScript module declarations | `/sdk/decodebox.d.mts` | `/sdk/v1/{engineVersion}/decodebox.d.mts` |

`v1` is the API major. Replace `{engineVersion}` with the project release version when pinning
a build. The release directory also contains `SHA256SUMS`. The Pages workflow retains published
version directories and rejects changes to their contents.
| Classic script, global `DecodeBox` | `/api`, `/api.js`, `/sdk/decodebox.js`, `/sdk/v1/decodebox.js` | `/sdk/v1/{version}/decodebox.js` |
| ES module | `/sdk/decodebox.mjs`, `/sdk/v1/decodebox.esm.js` | `/sdk/v1/{version}/decodebox.mjs` |
| TypeScript module declarations | `/sdk/decodebox.d.mts` | `/sdk/v1/{version}/decodebox.d.mts` |

`v1` is the API major. Latest aliases update on every deployment from `main`, while official
immutable archives under `/sdk/v1/{version}/` (with `SHA256SUMS`) are published from exact
Git tags only for stable milestone releases whose `PATCH` component is zero (for example,
`0.2.0`, `0.3.0`, `0.4.0`). Existing official archives are immutable and never overwritten.

## Local Development & Offline Usage

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ the classic namespace synchronously. Await `ready` before beginning work.

| Member | Result |
| --- | --- |
| `apiVersion`, `engineVersion` | Public contract and engine release version strings. |
| `apiVersion`, `engineVersion`, `buildId` | Public contract version, engine release version, and build commit identifier strings. |
| `capabilities()` | Active runtime, available crypto, randomness, compression formats, charsets and size limits. |
| `listOperations()` | Detached operation definitions with stable IDs, aliases and argument metadata. |
| `getOperation(id)` | One definition, or `null` for an unknown ID. |
Expand Down
Loading
Loading