Skip to content

Commit 2f6d56d

Browse files
committed
Merge branch 'feature/cdi-previewer'
2 parents 332f119 + bfeab58 commit 2f6d56d

52 files changed

Lines changed: 12708 additions & 8965 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import os, yaml, subprocess, shutil
2+
from checksumdir import dirhash
3+
4+
5+
def _check_metadata_extension(source_dir):
6+
"""Check if the previewer metadata file has the correct extension"""
7+
8+
# List all the files in the previewers directory
9+
files = os.listdir(".")
10+
11+
if "previewer-meta.yaml" in files:
12+
return "previewer-meta.yaml"
13+
elif "previewer-meta.yml" in files:
14+
return "previewer-meta.yml"
15+
else:
16+
raise FileNotFoundError(
17+
f"No previewer metadata file found for source directory {source_dir}"
18+
)
19+
20+
21+
def build_react_app(source_dir, TARGET_DIR):
22+
"""Builds the react app and copies the files to the target directory
23+
24+
Args:
25+
source_dir (str): Source directory of the react app.
26+
TARGET_DIR (str): Target directory to copy the files to.
27+
REPO_DIR (str): Directory of the repository.
28+
"""
29+
30+
# Move to the source directory to read metadata and instructions
31+
os.chdir(source_dir)
32+
33+
# Check if a previewer metadata file exists
34+
metadata_file = _check_metadata_extension(source_dir)
35+
36+
# Read the previewers metadata
37+
metadata = yaml.safe_load(open(metadata_file))
38+
39+
# Create path map to deploy the necessary files
40+
extension_paths = {
41+
"js": os.path.join(TARGET_DIR, "js"),
42+
"css": os.path.join(TARGET_DIR, "css"),
43+
"html": TARGET_DIR,
44+
}
45+
46+
# Get the hash of the source directory
47+
source_hash = dirhash(metadata["checkdir"], "sha256")
48+
49+
if metadata.get("checksum") == source_hash:
50+
print(f"No changes detected for {metadata['name']}")
51+
return
52+
53+
print(f"Changes detected for {metadata['name']} - Building previewer")
54+
55+
for command in metadata["build"]:
56+
# Run the build commands
57+
subprocess.call(command, shell=True)
58+
59+
for file in metadata["files"]:
60+
# Copy the files to the target directory
61+
fname = os.path.basename(file)
62+
extension = fname.split(".")[-1]
63+
shutil.copy(file, os.path.join(extension_paths[extension], fname))
64+
65+
# Update checksum in metadata file
66+
metadata["checksum"] = source_hash
67+
yaml.safe_dump(metadata, open(metadata_file, "w"), sort_keys=False)
68+
69+
print("Successfully built previewer - Checksum updated")
70+
71+
72+
if __name__ == "__main__":
73+
# Build the react previewers
74+
BASE_DIR = "./previewers/react-source/"
75+
REPO_DIR = os.getcwd()
76+
TARGET_DIR = os.path.join(REPO_DIR, "previewers", "betatest")
77+
78+
# Get all the react previewers
79+
react_previewers = [
80+
os.path.join(BASE_DIR, path)
81+
for path in os.listdir(BASE_DIR)
82+
if not path.startswith(".") and path != "README.md"
83+
]
84+
85+
for source_dir in react_previewers:
86+
# Build the react app
87+
build_react_app(source_dir, TARGET_DIR)
88+
89+
# Return to the repository directory
90+
os.chdir(REPO_DIR)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build React previewers
2+
3+
on: [push]
4+
5+
jobs:
6+
build_react_previewers:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
- name: Set up Python 3.10
12+
uses: actions/setup-python@v2
13+
with:
14+
python-version: "3.10"
15+
- name: Install dependencies
16+
run: python3 -m pip install pyyaml checksumdir
17+
- name: Set up npm
18+
uses: actions/setup-node@v3
19+
- name: Run script and build apps
20+
run: python3 ./.github/scripts/build_previewers.py
21+
- name: Push built previewers
22+
run: |
23+
if [[ `git status --porcelain` ]]; then
24+
git add --all
25+
git config --global user.name 'Previewer Builder'
26+
git config --global user.email 'builder@bot.com'
27+
git commit -am "Previewer update"
28+
git push
29+
else
30+
echo "Nothing changed!"
31+
fi
32+

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
11
/.project
22
/.settings
3+
.DS_STORE
4+
node_modules
5+
dist
6+
scripts/flow/*/.flowconfig
7+
.flowconfig
8+
*~
9+
*.pyc
10+
.grunt
11+
_SpecRunner.html
12+
__benchmarks__
13+
build/
14+
remote-repo/
15+
coverage/
16+
.module-cache
17+
fixtures/dom/public/react-dom.js
18+
fixtures/dom/public/react.js
19+
test/the-files-to-test.generated.js
20+
*.log*
21+
chrome-user-data
22+
*.sublime-project
23+
*.sublime-workspace
24+
.idea
25+
*.iml
26+
.vscode
27+
*.swp
28+
*.swo
29+
30+
packages/react-devtools-core/dist
31+
packages/react-devtools-extensions/chrome/build
32+
packages/react-devtools-extensions/chrome/*.crx
33+
packages/react-devtools-extensions/chrome/*.pem
34+
packages/react-devtools-extensions/firefox/build
35+
packages/react-devtools-extensions/firefox/*.xpi
36+
packages/react-devtools-extensions/firefox/*.pem
37+
packages/react-devtools-extensions/shared/build
38+
packages/react-devtools-extensions/.tempUserDataDir
39+
packages/react-devtools-inline/dist
40+
packages/react-devtools-shell/dist
41+
packages/react-devtools-timeline/dist

0 commit comments

Comments
 (0)