mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-16 15:22:43 +00:00
Plug-in Library: a package with an unreadable repo URL downloads nothing
When a package names a `repo` that isn't a GitHub repository URL (`https://github.com/<owner>/<repo>`, a trailing `/` or `.git` allowed, or a folder in one, `.../tree/<ref>/<path>`), Install, Update and Preview now refuse its release URLs with an error naming the package. Before, such a `repo` skipped the repository check and any GitHub release asset was downloaded. A package without a `repo` keeps any repository's release asset. The example catalog's schema now holds `repo` and release `url` to the same forms, and `scripts/validate.sh` checks that every release is an asset of the package's `repo` before it downloads anything.
This commit is contained in:
1 parent
75fed052e3
commit
5dfcadd09b
6 files changed
+117
-29
No files matched your search
@@ -12,9 +12,9 @@
|
||||
},
|
||||
"$defs": {
|
||||
"version": {"type": "string", "maxLength": 32, "pattern": "^[0-9]+(\\.[0-9]+)*$"},
|
||||
"github_url": {
|
||||
"release_url": {
|
||||
"type": "string",
|
||||
"pattern": "^https://(github\\.com|raw\\.githubusercontent\\.com|objects\\.githubusercontent\\.com|release-assets\\.githubusercontent\\.com)/[^\\s]+$"
|
||||
"pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s]+(/[^/?#\\\\\\s]+)+$"
|
||||
},
|
||||
"package": {
|
||||
"type": "object",
|
||||
@@ -26,7 +26,7 @@
|
||||
"author": {"type": "string"},
|
||||
"description": {"type": "string"},
|
||||
"license": {"type": "string"},
|
||||
"repo": {"type": "string", "pattern": "^https://"},
|
||||
"repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s]+)+)?/?$"},
|
||||
"tags": {"type": "array", "items": {"type": "string"}},
|
||||
"preview": {
|
||||
"type": "object",
|
||||
@@ -44,7 +44,7 @@
|
||||
"version": {"$ref": "#/$defs/version"},
|
||||
"api": {"type": "integer", "minimum": 0, "maximum": 4294967295},
|
||||
"minApp": {"$ref": "#/$defs/version"},
|
||||
"url": {"$ref": "#/$defs/github_url"},
|
||||
"url": {"$ref": "#/$defs/release_url"},
|
||||
"sha256": {"type": "string", "pattern": "^[0-9a-fA-F]{64}$"},
|
||||
"size": {"type": "integer", "minimum": 1, "maximum": 67108864},
|
||||
"effects": {"type": "array", "minItems": 1, "items": {"type": "string", "pattern": "^(?!ec\\.)[A-Za-z0-9._-]+$"}}
|
||||
|
||||
@@ -42,7 +42,25 @@ dups=$(jq -r '.packages[].id' "$catalog" | sort | uniq -d)
|
||||
[ -z "$dups" ] || fail "duplicate package ids: $dups"
|
||||
echo "ok"
|
||||
|
||||
echo "== 3. downloads"
|
||||
echo "== 3. release URLs"
|
||||
# When a package has a `repo`, every release must be an asset of that repository, as Install and
|
||||
# Preview require (the loader step installs from file:// copies, which skip this check).
|
||||
bad=$(jq -r '
|
||||
# Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case.
|
||||
def repo_of:
|
||||
(capture("^(?<h>[^/]+//[^/]+)/(?<o>[A-Za-z0-9._-]+)/(?<n>[A-Za-z0-9._-]+?)(\\.git)?/?$")
|
||||
// capture("^(?<h>[^/]+//[^/]+)/(?<o>[A-Za-z0-9._-]+)/(?<n>[A-Za-z0-9._-]+)/tree/[^?#]+$")
|
||||
| select(.h | ascii_downcase == "https://github.com") | "\(.o)/\(.n)" | ascii_downcase) // "?";
|
||||
.packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo
|
||||
| select($repo != "") | ($repo | repo_of) as $want
|
||||
| .versions[] | select(.url | startswith("file://") | not)
|
||||
| ((.url | ascii_downcase | capture("^https://github\\.com/(?<o>[^/]+)/(?<n>[^/]+)/releases/download/") | "\(.o)/\(.n)") // "?") as $got
|
||||
| select($want == "?" or $got != $want)
|
||||
| "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)"' "$catalog")
|
||||
[ -z "$bad" ] || fail "release URLs outside the package's repo:"$'\n'"$bad"
|
||||
echo "ok"
|
||||
|
||||
echo "== 4. downloads"
|
||||
# The checked files are what the loader step installs: a copy of the catalog names them by file://.
|
||||
local_catalog=$(jq '.' "$catalog")
|
||||
while IFS=$'\t' read -r p r id version url sha size; do
|
||||
@@ -58,7 +76,7 @@ done < <(jq -r '.packages | to_entries[] | .key as $p | .value as $pkg | $pkg.ve
|
||||
| [$p, .key, $pkg.id, .value.version, .value.url, .value.sha256, (.value.size // "")] | @tsv' "$catalog")
|
||||
echo "ok"
|
||||
|
||||
echo "== 4. load with EffectCraft"
|
||||
echo "== 5. load with EffectCraft"
|
||||
if [ -z "${EFFECTCRAFT_CLI:-}" ]; then
|
||||
echo "skipped (set EFFECTCRAFT_CLI to an effectcraft-cli build)"
|
||||
exit 0
|
||||
|
||||
Reference in new issue
Block a user