forked from ramp4-pcar4/ramp4-pcar4
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (84 loc) · 3.46 KB
/
build-demo.yml
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
# Workflow for building and deploying a demo site to GitHub Pages
name: Deploy static demo files to Pages
on: push
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these deployments to complete.
concurrency:
group: 'pages'
cancel-in-progress: false
jobs:
build:
name: Build the project
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22.5.1'
cache: 'npm'
- name: Build or delete the demo
run: |
BRANCH_OR_TAG_NAME=${GITHUB_REF#refs/heads/}
BRANCH_OR_TAG_NAME=${BRANCH_OR_TAG_NAME#refs/tags/}
git config --global user.email "miles.petrov@ec.gc.ca"
git config --global user.name "Miles Petrov"
# Check if demo-page branch exists and create it if necessary
if git show-ref --quiet refs/heads/demo-page; then
echo "demo-page exists."
else
echo "demo-page does not exist. Creating an orphan branch."
git checkout --orphan demo-page
git rm -rf . || true
rm -r * || true
git commit --allow-empty -m "Initial commit on orphan demo-page"
fi
# Checkout to current branch or tag and create a temporary branch
git checkout $BRANCH_OR_TAG_NAME
git checkout -b temp-$BRANCH_OR_TAG_NAME
# Create a subfolder and checkout demo-page's content
mkdir demo-folder
git --work-tree=demo-folder checkout demo-page -- . || true
# Modify and commit changes
if [ ${{ github.event.deleted}} == 'true' ]; then
rm -rf demo-folder/$BRANCH_OR_TAG_NAME
else
npm ci
npm run build
mv dist demo-folder/$BRANCH_OR_TAG_NAME
rm -rf node_modules
fi
git add demo-folder
git commit -m "Modified contents of demo-page within demo-folder"
# Apply the changes to demo-page
git checkout demo-page
echo 1
git checkout temp-$BRANCH_OR_TAG_NAME -- demo-folder
echo 2
mv demo-folder/* .
echo 3
rmdir demo-folder
echo 4
git add .
echo 5
git commit -m "Applied changes from demo-folder to demo-page"
echo 6
git push origin demo-page
echo 7
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '.'
retention-days: 1
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4