Skip to content

Commit 910daf8

Browse files
committed
2 parents b5737af + 12fbf64 commit 910daf8

13 files changed

Lines changed: 127 additions & 64 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Deploy website
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'website/**'
9+
workflow_dispatch:
10+
11+
jobs:
12+
deploy:
13+
environment: release
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
deployments: write
18+
statuses: write
19+
pull-requests: write
20+
21+
steps:
22+
- name: Checkout main branch
23+
uses: actions/checkout@v4
24+
25+
- name: Deploy website directory to website branch
26+
uses: peaceiris/actions-gh-pages@v4
27+
with:
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
publish_dir: ./website
30+
publish_branch: website
31+
keep_files: true
32+
destination_dir: api
33+
user_name: 'github-actions[bot]'
34+
user_email: 'github-actions[bot]@users.noreply.github.com'
35+
commit_message: ${{ github.event.head_commit.message }}
36+
37+
- name: Set up Python 3.12
38+
uses: actions/setup-python@v3
39+
with:
40+
python-version: "3.12"
41+
42+
- name: Install dependencies
43+
run: |
44+
python -m pip install --upgrade pip
45+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
46+
pip install cryptography scratchattach
47+
48+
- name: Generate and mask Vercel secrets
49+
id: generate_vars
50+
env:
51+
FERNET_KEY: ${{ secrets.FERNET_KEY }}
52+
run: |
53+
cd tests
54+
# Extract secrets securely
55+
vercel_token_val=$(python -m util vercel | sed -n '1p')
56+
org_id_val=$(python -m util vercel | sed -n '2p')
57+
project_id_val=$(python -m util vercel | sed -n '3p')
58+
59+
# Mask values so they never appear in logs
60+
echo "::add-mask::$vercel_token_val"
61+
echo "::add-mask::$org_id_val"
62+
echo "::add-mask::$project_id_val"
63+
64+
# Store them as environment variables (scoped to this job)
65+
echo "vercel_token=$vercel_token_val" >> $GITHUB_ENV
66+
echo "org_id=$org_id_val" >> $GITHUB_ENV
67+
echo "project_id=$project_id_val" >> $GITHUB_ENV
68+
69+
cd ..
70+
shell: bash
71+
72+
- name: Checkout website branch
73+
uses: actions/checkout@v4
74+
with:
75+
ref: 'website'
76+
77+
- uses: nexterias/actions-vercel@v1
78+
id: vercel
79+
with:
80+
token: ${{ env.vercel_token }}
81+
org-id: ${{ env.org_id }}
82+
project-id: ${{ env.project_id }}
83+
production: true
84+
prebuilt: true

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12.5
1+
3.12.12

scratchattach/editor/blockshape.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Perhaps this should be merged with pallete.py
77
from dataclasses import dataclass
8-
from typing import Final
8+
from typing import Final, Literal
99

1010
from . import commons
1111
from scratchattach.utils.enums import _EnumWrapper
@@ -20,7 +20,7 @@ def __bool__(self):
2020
raise TypeError("Need mutation data to work out attribute value.")
2121

2222

23-
MUTATION_DEPENDENT: Final[_MutationDependent] = _MutationDependent()
23+
MUTATION_DEPENDENT: Final[Literal[_MutationDependent.INSTANCE]] = _MutationDependent.INSTANCE
2424
"""Value used when mutation data is required to work out the attribute value"""
2525

2626

scratchattach/editor/commons.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -141,53 +141,5 @@ def get_name_nofldr(name: str) -> str:
141141
else:
142142
return name[len(fldr) + 2:]
143143

144+
Singleton = Enum
144145

145-
class SingletonMeta(EnumMeta):
146-
147-
def __call__(self, value=0, *args, **kwds):
148-
if value != 0:
149-
raise ValueError("Value must be 0.")
150-
old_bases = self.__bases__
151-
self.__bases__ = old_bases + (Enum,)
152-
result = super().__call__(value, *args, **kwds)
153-
self.__bases__ = old_bases
154-
return result
155-
156-
157-
if TYPE_CHECKING:
158-
Singleton = Enum
159-
else:
160-
class Singleton(metaclass=SingletonMeta):
161-
162-
def __new__(cls, val=None):
163-
if cls is Singleton:
164-
raise TypeError("Singleton cannot be created directly.")
165-
if hasattr(cls, "INSTANCE"):
166-
return getattr(cls, "INSTANCE")
167-
if val == 0:
168-
return super().__new__(cls)
169-
raise TypeError("Has no instance.")
170-
171-
def __init__(self, *args, **kwds):
172-
pass
173-
174-
def __repr__(self):
175-
return self.__class__.__name__
176-
177-
def __str__(self):
178-
return self.__class__.__name__
179-
180-
def __format__(self, format_spec):
181-
return str.__format__(str(self), format_spec)
182-
183-
def __hash__(self):
184-
return hash(self.__class__)
185-
186-
def __reduce_ex__(self, proto):
187-
return self.__class__, ()
188-
189-
def __deepcopy__(self, memo):
190-
return self
191-
192-
def __copy__(self):
193-
return self

scratchattach/eventhandlers/cloud_storage.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def get(self, db_name, key) -> str:
105105
return f"Error: Key {key} doesn't exist in database {db_name}"
106106

107107
def set(self, db_name, key, value):
108-
print(db_name, key, value, self._databases)
109108
return self.get_database(db_name).set(key, value)
110109

111110
def keys(self, db_name) -> list:
@@ -133,4 +132,4 @@ def save(self):
133132
Saves the data in the JSON files for all databases in self._databases
134133
"""
135134
for dbname in self._databases:
136-
self._databases[dbname].save_to_json()
135+
self._databases[dbname].save_to_json()

scratchattach/site/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def load_description(self):
326326

327327
# -- Project contents (body/json) -- #
328328

329-
def download(self, *, filename=None, dir=""):
329+
def download(self, *, filename=None, dir="."):
330330
"""
331331
Downloads the project json to the given directory.
332332
@@ -338,14 +338,15 @@ def download(self, *, filename=None, dir=""):
338338
if filename is None:
339339
filename = str(self.id)
340340
if not (dir.endswith("/") or dir.endswith("\\")):
341-
dir = dir + "/"
341+
dir += "/"
342342
self.update()
343343
response = requests.get(
344344
f"https://projects.scratch.mit.edu/{self.id}?token={self.project_token}",
345345
timeout=10,
346346
)
347-
filename = filename.replace(".sb3", "")
348-
open(f"{dir}{filename}.sb3", "wb").write(response.content)
347+
filename = filename.removesuffix(".sb3")
348+
with open(f"{dir}{filename}.sb3", "wb") as f:
349+
f.write(response.content)
349350
except Exception:
350351
raise (
351352
exceptions.FetchError(

tests/test_studio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_studio():
1212
sess = session()
1313

1414
studio = sess.connect_studio(34253687)
15-
assert studio.get_exact_project_count() == 1251
15+
assert studio.get_exact_project_count() == 1250
1616

1717
studio = sess.connect_studio(50809872)
1818

tests/util/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ def teacher_session() -> Optional[_Session]:
4242
_teacher_session = login(data["username"], data["password"])
4343

4444
return _teacher_session
45+

tests/util/__main__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
try:
88
from .keyhandler import FERNET
9-
except ImportError:
9+
from .vercelauth import vercel_auth
10+
except ImportError as excp:
1011
from keyhandler import FERNET
12+
from vercelauth import vercel_auth
1113

1214

1315
def gen_keystr():
@@ -28,6 +30,8 @@ class Args(argparse.Namespace):
2830
decrypt.add_argument("content", nargs="?")
2931
if keygen := command.add_parser("keygen", help="Generate a key. You could set this to $FERNET_KEY if you want"):
3032
...
33+
if vercelauth := command.add_parser("vercel", help="Output the vercel auth data."):
34+
...
3135

3236
args = parser.parse_args(namespace=Args())
3337

@@ -44,6 +48,11 @@ class Args(argparse.Namespace):
4448

4549
case "keygen":
4650
print(gen_keystr())
51+
52+
case "vercel":
53+
print(
54+
"\n".join(vercel_auth())
55+
)
4756

4857

4958
if __name__ == "__main__":

tests/util/auth.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ scratchattachv2 = "gAAAAABozo75u7Eov4zakrObMqLVs6wmwSNXQ7KroU5ntU7vZvM49fW-RnEWl
1212
[teacher_auth]
1313
username = "gAAAAABo2AwGrm5MsCqFTz7yPBZf8F--b3529aCsi9olynL0DKBi5EllZR1jNtsTt4vUPdke7eyEHBToMfN00QgxAU4RmlH3GCAK4TpXs7Qd7eI4iGD1hIU="
1414
password = "gAAAAABo2AwLc-oRH45T6V-xlcpbaqH4Ds93nMCrMbgUv_AHoQhTO1L7NkU54npm54-Zjs7YVlkOSFS5kffWzJeMZB7maNAv1WKnHJ4YvzF_R7PlIaeIBa8="
15+
16+
[vercel_auth]
17+
vercel_token = "gAAAAABpB06MNHj6aq9DvD4NVe5KhC5wKn4yopSimtUKVDz1VvuE430xn2eytrLV0JtN05coZEg_ZjZ4Hekw3S2CjbN9pFLN61vsy87BsnPi-IemLTobQoY="
18+
org_id = "gAAAAABpB069BVBM7X0-TTS-VXv4rDcdGVb7Z3n2EWM73SHFv7gHQpBMtxoe2SLZf6OD1K5B1TGgC-52NwPOwKgA78Jt3WfQuGpL88El2MnUmdaoqvrn2OI="
19+
project_id = "gAAAAABpB04hpAEZdZT6LLvWEzibe-Vi3tORO_STdGUOSq4HwVids23UhKoHJSi9d9z-_5ULq7DO5h37kJ7GbcpjfDS85b7IGgHmQu-Z1FT_rLYsHnhAMGKLIKEuXXVV-nLLY7WlDa_0"

0 commit comments

Comments
 (0)