Skip to content

Update addons data #1592

Update addons data

Update addons data #1592

Workflow file for this run

name: Update addons data
on:
workflow_dispatch:
inputs:
Version:
description: SA Version (with `v` prefix)
required: false
type: string
Patch:
required: false
type: number
default: 0
Dryrun:
required: false
type: boolean
default: false
schedule:
- cron: 30 11/12 * * *
push:
branches: "main"
permissions:
id-token: write # Required for OIDC
contents: read
jobs:
update:
name: Update
runs-on: ubuntu-24.04
steps:
- name: Clone
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: ScratchAddons/ScratchAddons
sparse-checkout: |
addons/*/addon.json
addons/addons.json
LICENSE
manifest.json
sparse-checkout-cone-mode: false
fetch-tags: true
fetch-depth: 0
- name: Get version
run: |
VERSION=${{inputs.Version || '$(git describe --tags $(git rev-list --tags --max-count=1))'}}
echo "VERSION=$VERSION" >>"$GITHUB_ENV"
IFS=. read -r MAJOR MINOR PATCH <<< "${VERSION#v}"
echo "PUBLISH_VERSION=$(printf "%d%03d.%s" "$MAJOR" "$MINOR" "$PATCH")" >>"$GITHUB_ENV"
- name: Check version
id: check_version
if: ${{!inputs.Dryrun}}
run: |
if [[ "$(npm view @sa-community/addons-data version)" == "$PUBLISH_VERSION."* && $PATCH == 0 ]]; then
echo "No new version"
echo "new_version=false" >>"$GITHUB_OUTPUT"
else
echo "New version found"
echo "new_version=true" >>"$GITHUB_OUTPUT"
fi
env:
PATCH: ${{inputs.Patch||0}}
- name: Checkout
if: steps.check_version.outputs.new_version == 'true'
run: git checkout "$VERSION"
- name: Generate index.js
run: |
echo "module.exports = [" >index.js
jq -r '.[] | select(type == "string" and startswith("//") | not) | "{addonId: \"\(.)\", manifest: require(\"./addons/\(.).js\")}"' addons/addons.json | sed 's/$/,/' >>index.js
echo "];" >>index.js
echo -e 'declare const _exports: { addonId: string; manifest: import("./addons.d.ts").AddonManifest; }[];\nexport = _exports;' >index.d.ts
rm addons/addons.json
- name: Generate manifests
run: |
find . -type f -name "addon.json" | while read -r json_file; do
dirname="$(dirname "$json_file")"
echo -e -n '/** @type {import("../addons.d.ts").AddonManifest} */\nconst addon = ' >"$dirname.js"
cat "$json_file" >>"$dirname.js"
echo -e -n ";\nmodule.exports = addon;" >>"$dirname.js"
echo -e 'declare const addon: import("../addons.d.ts").AddonManifest;\nexport = addon;' >"$dirname.d.ts"
rm -r "$dirname/"
done
- name: Checkout
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: script
- name: Move types
run: mv script/addons.d.ts addons.d.ts
- name: Move README
run: mv script/README.md README.md
- if: steps.check_version.outputs.new_version == 'true'
run:
cat script/package.json | sed "s/VERSION/$PUBLISH_VERSION.${{inputs.Patch||0}}/"
>package.json
- name: Setup Node.JS
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with:
node-version: 24.11.1
registry-url: "https://registry.npmjs.org"
- name: Publish
if: steps.check_version.outputs.new_version == 'true'
run: npm publish --access public --tag latest
- name: Run typecheck
id: typecheck
run: |
echo "sha=$(git log -1 --pretty=format:%H)" >>"$GITHUB_OUTPUT"
cd script
npm ci
npx tsc ../index.js ../addons/**.js --allowJs --checkJs --noEmit --strict >typecheck.log || true
if [[ -s typecheck.log ]]; then
echo "has_errors=true" >>"$GITHUB_OUTPUT"
echo "LOG<<EOF" >>"$GITHUB_OUTPUT"
head -c 64000 typecheck.log >>"$GITHUB_OUTPUT"
echo "EOF" >>"$GITHUB_OUTPUT"
else
echo "has_errors=false" >>"$GITHUB_OUTPUT"
fi
- name: Create or comment on issue
if: steps.typecheck.outputs.has_errors == 'true'
uses: ovsds/create-or-update-unique-issue-action@8999e391f74f20449dcc70e94aee731a3938d543 # v1.1.0
with:
title: 🚨 Typecheck Failed in CI
unique-title-includes: 🚨 Typecheck Failed in CI
body:
"https://github.com/ScratchAddons/ScratchAddons/tree/${{steps.typecheck.outputs.sha}}\n```\n${{steps.typecheck.outputs.LOG}}\n```"
- name: Close issue if typecheck passed
if: steps.typecheck.outputs.has_errors == 'false'
uses: lee-dohm/close-matching-issues@e9e43aad2fa6f06a058cedfd8fb975fd93b56d8f # v2.1.0
with:
query: "🚨 Typecheck Failed in CI is:open author:app/github-actions"
token: ${{secrets.GITHUB_TOKEN}}