forked from ramp4-pcar4/ramp4-pcar4
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (80 loc) · 3.34 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
# 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: Try to restore node_modules folder from cache
id: cache-node-modules
uses: actions/cache@v4
with:
path: ./node_modules
key: npm-${{ hashFiles('./package-lock.json') }}
- name: Otherwise install npm dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Update package.json version if necessary
if: 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
echo "::warning::Tag version ($TAG_VERSION) did not match package.json version ($PACKAGE_VERSION). Updated package.json to $TAG_VERSION."
else
echo "::info::Tag version ($TAG_VERSION) matches package.json version ($PACKAGE_VERSION)."
fi
- name: Build the files!
run: npm run build
env:
NODE_OPTIONS: '--max-old-space-size=8192'
- name: Download Pages artifact
uses: dawidd6/action-download-artifact@v6
with:
name: github-pages
path: pages
continue-on-error: true
- name: Rename dist folder, delete existing demo
run: |
BRANCH_OR_TAG_NAME=${GITHUB_REF#refs/heads/}
BRANCH_OR_TAG_NAME=${BRANCH_OR_TAG_NAME#refs/tags/}
mkdir -p pages
cd pages
if [ -f artifact.tar ]; then
tar -xvf artifact.tar;
rm artifact.tar;
else
echo "artifact.tar not found";
fi
rm -rf $BRANCH_OR_TAG_NAME
mv ../dist $BRANCH_OR_TAG_NAME
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'pages/'
retention-days: 30
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4