Skip to content

Commit 92ebaaa

Browse files
authored
Create build-and-deploy.yml
1 parent 805232f commit 92ebaaa

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build and Deploy React Projects to GitHub Pages (docs branch)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: '18'
21+
22+
- name: Build all React projects
23+
run: |
24+
projects=(
25+
"01-Tic-Tac-Toe"
26+
"02-Searchable-Product-Data-Table"
27+
"03. Counter"
28+
"04. ToDo-App"
29+
"05. Meals-API-Project"
30+
"06. Calculator"
31+
"07. Toggle-Background-Color"
32+
"08. Hidden-Search-Bar"
33+
"09. Testimonials"
34+
"10. Accordions"
35+
"11. Form Validation/v1"
36+
)
37+
38+
rm -rf output
39+
mkdir -p output
40+
41+
for project in "${projects[@]}"; do
42+
echo "Building $project"
43+
cd "$project"
44+
npm install
45+
46+
# Add homepage for GitHub Pages
47+
homepage="https://$GITHUB_REPOSITORY_OWNER.github.io/$project"
48+
npx json -I -f package.json -e "this.homepage=\"$homepage\""
49+
50+
npm run build
51+
cd ..
52+
53+
mkdir -p "output/$project"
54+
cp -r "$project/build/." "output/$project/"
55+
done
56+
57+
- name: Deploy to `docs` branch
58+
run: |
59+
cd output
60+
git init
61+
git config user.name "github-actions"
62+
git config user.email "[email protected]"
63+
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
64+
git checkout -b docs
65+
66+
touch .nojekyll # Avoid GitHub Pages ignoring folders starting with underscore
67+
git add .
68+
git commit -m "Deploy React projects to GitHub Pages [docs branch]"
69+
git push --force origin docs

0 commit comments

Comments
 (0)