Skip to content
Merged
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
145 changes: 145 additions & 0 deletions .github/actions/standalone-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Publish the standalone release asset
description: Build the exact tag and verify the uploaded HTML against its local SHA-256.
inputs:
tag:
description: Published stable release tag to build.
required: true
replace-standalone:
description: Allow an explicit maintenance rebuild to replace differing HTML.
required: false
default: 'false'
verify-only:
description: Check the existing SDK manifest before notes repair without uploading assets.
required: false
default: 'false'
outputs:
digest:
description: Verified SHA-256 of the uploaded HTML.
value: ${{ steps.standalone.outputs.digest }}
runs:
using: composite
steps:
- name: Verify the target release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ inputs.tag }}
run: |
if [[ ! "$RELEASE_TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ || "$RELEASE_TAG" == v0.1.0 || "$RELEASE_TAG" == v0.1.1 ]]; then
echo "::error::Expected a stable vX.Y.Z tag after the two preserved releases."
exit 1
fi
gh api "repos/$GITHUB_REPOSITORY/releases/tags/$RELEASE_TAG" |
jq -e --arg tag "$RELEASE_TAG" '
.tag_name == $tag and .draft == false and (.published_at | fromdateiso8601 | type == "number")'

- name: Check out the release tag
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
ref: refs/tags/${{ inputs.tag }}
persist-credentials: false
path: released-source
fetch-depth: 0

- name: Confirm the tag belongs to the trusted main history
shell: bash
working-directory: released-source
env:
MAIN_SHA: ${{ github.sha }}
RELEASE_TAG: ${{ inputs.tag }}
run: |
[[ "$(git rev-parse HEAD)" == "$(git rev-parse "refs/tags/$RELEASE_TAG^{commit}")" ]]
git merge-base --is-ancestor HEAD "$MAIN_SHA"

- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ hashFiles('released-source/scripts/build-sdk.mjs') != '' && '24.18.0' || '22.23.5' }}
package-manager-cache: false

- name: Build the standalone edition
id: build
if: inputs.verify-only != 'true' || hashFiles('released-source/scripts/build-sdk.mjs') != ''
shell: bash
working-directory: released-source
run: |
npm clean-install
# Vite embeds the current time. Use the tagged commit time for repeatable HTML.
SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD)
export SOURCE_DATE_EPOCH
cat > "$RUNNER_TEMP/release-clock.cjs" <<'JS'
require('node:test').mock.timers.enable({
apis: ['Date'], now: Number(process.env.SOURCE_DATE_EPOCH) * 1000,
});
JS
NODE_OPTIONS="--require=$RUNNER_TEMP/release-clock.cjs" npm run build
if [[ -f scripts/build-sdk.mjs ]]; then
npm run check:sdk-dist
fi

- name: Verify and publish the standalone HTML
id: standalone
if: success() && inputs.verify-only != 'true' && steps.build.outcome == 'success'
shell: bash
working-directory: released-source
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ inputs.tag }}
REPLACE_STANDALONE: ${{ inputs.replace-standalone }}
run: |
if [[ ! -f dist/decodebox.html || ! -s dist/decodebox.html ]]; then
echo "::error::The standalone build produced no HTML file."
exit 1
fi
version=$(node -p "require('./package.json').version")
if [[ "$RELEASE_TAG" != "v$version" ]]; then
echo "::error::The package version does not match the release tag."
exit 1
fi
name="OWASP-DecodeBox-Standalone-$RELEASE_TAG.html"
ASSET_PATH="$RUNNER_TEMP/$name"
cp dist/decodebox.html "$ASSET_PATH"
digest="sha256:$(sha256sum "$ASSET_PATH" | cut -d' ' -f1)"
existing=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$RELEASE_TAG" |
jq -er --arg name "$name" '[.assets[] | select(.name == $name)] |
if length == 0 then "missing" elif length == 1 then (.[0].digest // "incomplete")
else error("duplicate standalone asset") end')
if [[ "$existing" == missing ]]; then
gh release upload "$RELEASE_TAG" "$ASSET_PATH"
elif [[ "$existing" != "$digest" ]]; then
[[ "$REPLACE_STANDALONE" == true ]] || { echo "::error::Existing HTML differs; review before rebuilding."; exit 1; }
gh release upload "$RELEASE_TAG" "$ASSET_PATH" --clobber
fi
gh api "repos/$GITHUB_REPOSITORY/releases/tags/$RELEASE_TAG" | \
jq -e --arg tag "$RELEASE_TAG" --arg name "$name" --arg digest "$digest" '
.tag_name == $tag and
any(.assets[]; .name == $name and .state == "uploaded" and .digest == $digest)'
echo "digest=$digest" >> "$GITHUB_OUTPUT"

- name: Attach the verified SDK manifest for SDK-capable tags
id: manifest
if: >-
success() && steps.build.outcome == 'success' && hashFiles('released-source/scripts/build-sdk.mjs') != '' &&
(steps.standalone.outcome == 'success' || inputs.verify-only == 'true')
working-directory: released-source
shell: bash
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ inputs.tag }}
VERIFY_ONLY: ${{ inputs.verify-only }}
run: |
manifest="dist/sdk/v1/${RELEASE_TAG#v}/SHA256SUMS"
asset="DecodeBox-SDK-$RELEASE_TAG-SHA256SUMS"
test -s "$manifest"
names=$(gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name')
if ! grep -Fxq "$asset" <<< "$names"; then
if [[ "$VERIFY_ONLY" == true ]]; then
echo "::error::Missing SDK manifest. Run the release_tag rebuild first."
exit 1
fi
cp "$manifest" "$RUNNER_TEMP/$asset"
gh release upload "$RELEASE_TAG" "$RUNNER_TEMP/$asset"
fi
gh release download "$RELEASE_TAG" --pattern "$asset" --output - | cmp - "$manifest"
98 changes: 98 additions & 0 deletions .github/scripts/fixtures/fake-gh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
"""Offline gh executable used only by the release CLI integration tests."""
import hashlib
import json
import os
import sys
from pathlib import Path

file = Path(os.environ["FAKE_GH_STATE"])
# Check the process boundary before handling either publisher or workflow requests.
if (os.environ["PATH"] != str(file.parent / "bin")
or os.environ["HOME"] != str(file.parent)
or os.environ["GH_CONFIG_DIR"] != str(file.parent / "gh-config")
or any(key in os.environ for key in (
"GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN",
"GH_HOST", "XDG_CONFIG_HOME", "GIT_CONFIG_GLOBAL", "GH_TEST_CALLER_ONLY",
))):
sys.exit("Expected the isolated, credential-free fixture environment.")
state = json.loads(file.read_text())
release = state["release"]
args = sys.argv[1:]
repo = "repos/OWASP/DecodeBox/"
tag = release["tag_name"]
data = json.load(sys.stdin) if "--input" in args else None
state["calls"].append([args, data])


def finish(value="", code=0):
file.write_text(json.dumps(state))
if isinstance(value, bytes):
sys.stdout.buffer.write(value)
else:
print(value if isinstance(value, str) else json.dumps(value))
sys.exit(code)


name = f"OWASP-DecodeBox-Standalone-{tag}.html"
manifest = f"DecodeBox-SDK-{tag}-SHA256SUMS"
if args == ["release", "view", tag, "--json", "assets", "--jq", ".assets[].name"]:
finish(manifest if "manifest" in state else "")
if args == ["release", "upload", tag, str(file.parent / manifest)]:
assert "manifest" not in state
state["manifest"] = (file.parent / manifest).read_text()
finish()
if args == ["release", "download", tag, "--pattern", manifest, "--output", "-"]:
finish(state["manifest"].encode())
if args[:2] == ["release", "upload"]:
expected = ["release", "upload", tag, str(file.parent / name)]
assert args == (expected + ["--clobber"] if release["assets"] else expected)
if state.get("fault") == "upload":
finish(code=1)
blob = (file.parent / name).read_bytes()
digest = hashlib.sha256(blob).hexdigest()
if state.get("fault") == "digest":
digest = "0" * 64
release["assets"] = [dict(id=73, name=name, state="uploaded", size=len(blob), digest="sha256:" + digest)]
finish()
if args == ["api", "-H", "Accept: application/octet-stream", repo + "releases/assets/73"]:
finish((file.parent / name).read_bytes())
if args == ["api", repo + "releases/tags/" + tag]:
finish(release)
if args[:2] != ["api", "--method"]:
finish("Unexpected invocation", 2)
method, endpoint = args[2:4]
assert args[4:] == ([] if method == "GET" else ["--input", "-"])
assert endpoint.startswith(repo)
route = endpoint[len(repo):]
if state.get("fault") == "invalid JSON":
finish("{")
if method == "GET" and state.get("fault") == "baseline edit" and route == f"releases/{release['id']}":
if sum(c[0] == args for c in state["calls"]) == 2:
release["body"] = "Maintainer edit before baseline."
if method == "GET" and route in (f"releases/{release['id']}", "releases/tags/" + tag):
if state.get("fault") == "concurrent edit" and route == f"releases/{release['id']}":
release["name"] = "Edited during contributor lookup"
finish(release)
if method == "POST" and route == "releases/generate-notes":
assert data == {"tag_name": tag, "previous_tag_name": "v0.1.1"}
if state.get("fault") == "contributors":
finish(code=1)
line = "* @alice made their first contribution in https://github.com/OWASP/DecodeBox/pull/31"
finish({"body": "## New Contributors\n" + line + "\n" + line})
if method == "GET" and route == "pulls/31":
finish(dict(number=31, merge_commit_sha="a" * 40, user=dict(login="alice"), base=dict(ref="main", repo=dict(full_name="OWASP/DecodeBox")),
merged_at="2026-11-20T00:00:00Z"))
if method == "GET" and route == f"compare/v0.1.1...{tag}?per_page=100&page=1":
finish(dict(status="ahead", total_commits=1, commits=[dict(sha="a" * 40)]))
if method == "PATCH" and route == f"releases/{release['id']}":
assert set(data) in ({"body"}, {"name", "body"})
if state.get("fault") == "reject PATCH":
finish(code=1)
release.update(data)
if state.get("fault") == "lose PATCH response":
finish(code=1)
if state.get("fault") == "invalid PATCH reply":
finish({})
finish(release)
finish("Unexpected route", 2)
Loading
Loading