forked from ramp4-pcar4/ramp4-pcar4
-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (111 loc) · 4.91 KB
/
demo-build.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
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
# 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: write
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
with:
path: ramp
- uses: actions/setup-node@v4
with:
node-version: '22.5.1'
cache: 'npm'
cache-dependency-path: ramp/package-lock.json
- name: Set up Git
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
- name: Create orphan branch if demo-page doesn't exist
run: |
cd ramp
git fetch origin
if git show-ref --quiet refs/remotes/origin/demo-page; then
echo "Branch 'demo-page' exists on origin."
else
echo "Branch 'demo-page' does not exist on origin. Creating an orphan branch... https://github.com/${{ github.repository_owner }}/ramp4-pcar4.git"
cd ../
mkdir -p demo-page
cd demo-page
git init
git checkout --orphan demo-page
git commit --allow-empty -m "Create orphan branch"
git remote add origin https://github.com/${{ github.repository_owner }}/ramp4-pcar4.git
git push -u origin demo-page
echo "Orphan branch 'demo-page' has been created and pushed to origin."
fi
- name: Remove the old demo if it exists and make docs folder
run: |
rm -rf demo-page/${{ github.ref_name }}
mkdir -p demo-page/${{ github.ref_name }}/docs/api-tech-docs
- name: Update docsite version references before docs are built
uses: jacobtomlinson/gha-find-replace@v3
with:
find: '{{ramp-version}}'
replace: ${{ github.ref_name }}
include: 'ramp/docs/**'
regex: false
- name: Update docsite version references before docs are built
uses: jacobtomlinson/gha-find-replace@v3
with:
find: '{{repo-owner}}'
replace: ${{ github.repository_owner }}
include: 'ramp/docs/**'
regex: false
- name: Build or delete the demo
run: |
cd ramp
npm ci
npm run build
npm run ts-docs:generate
npm run vite-docs:generate
- name: Publish to NPM
if: github.repository == 'ramp4-pcar4/ramp4-pcar4' && startsWith(github.ref, 'refs/tags/v')
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
npm version --allow-same-version --no-git-tag-version $TAG_VERSION
fi
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Move the built files and docs into the demo-page
run: |
mv ramp/dist/* demo-page/${{ github.ref_name }}
mv ramp/vite-docs/* demo-page/${{ github.ref_name }}/docs
mv ramp/ts-docs/* demo-page/${{ github.ref_name }}/docs/api-tech-docs
- name: Squash and push changes to demo-page
run: |
cd demo-page
git add .
git commit -m "Applied changes from demo-folder to demo-page"
# Squash the commit history into a single commit
git reset --soft $(git rev-list --max-parents=0 HEAD)
git commit -m "Applied changes from demo-folder to demo-page"
git push origin HEAD --force
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: demo-page
retention-days: 1
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4