-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (128 loc) · 5.91 KB
/
update.yml
File metadata and controls
151 lines (128 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
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@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.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}}