Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
POS/.github/workflows/deploy-frontend.yml at develop · Posnic/POS · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Posnic
POS
Repository navigation
Code
Issues
396
(396)
Pull requests
14
(14)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
POS
/
.github
/
workflows
/
deploy-frontend.yml
Copy path
View runs
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
177 lines (164 loc) · 8.37 KB
develop
Breadcrumbs
POS
/
.github
/
workflows
/
deploy-frontend.yml
Copy path
Top
File metadata and controls
Code
Blame
177 lines (164 loc) · 8.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#
Deploys the shop UI to the tenant instance whenever frontend/ changes.
#
#
Until this existed nothing shipped frontend/ anywhere: deploy-api.yml covers
#
api/ only, so the 17 shops ran whatever snapshot was last copied across by
#
hand. They were months behind the repo and nobody could tell, because the
#
pages still worked -- they were simply the wrong ones.
#
#
The pages are gulp output. layouts/, modules/ and modals/ are assembled into
#
frontend/public/, and that is what the tenants actually serve, so the build
#
has to run here rather than relying on whatever public/ someone happened to
#
commit or leave lying around.
#
#
Uses the same switches as deploy-api.yml:
#
variable DEPLOY_ENABLED = true
#
secrets DEPLOY_SSH_KEY / DEPLOY_HOST / DEPLOY_USER
name
:
Deploy frontend (tenant shops)
on
:
push
:
branches
:
[main]
paths
:
-
"
frontend/**
"
-
"
.github/workflows/deploy-frontend.yml
"
workflow_dispatch
:
concurrency
:
group
:
deploy-frontend
cancel-in-progress
:
true
#
Least privilege for GITHUB_TOKEN.
#
#
Without this the token takes the repository default, which on a public repo
#
is more than any of these jobs needs. None of them writes to GitHub - they
#
build, test, upload an artifact or deploy outward - so read is the ceiling.
#
Releases are created by release.yml, which asks for contents: write there.
permissions
:
contents
:
read
jobs
:
deploy
:
if
:
vars.DEPLOY_ENABLED == 'true'
runs-on
:
ubuntu-latest
steps
:
-
uses
:
actions/checkout@v7
-
uses
:
actions/setup-node@v7
with
:
node-version
:
22
cache
:
npm
cache-dependency-path
:
frontend/package-lock.json
-
name
:
Build the pages
working-directory
:
frontend
run
:
|
npm ci --no-audit --no-fund
npm run build:assets
#
A gulp failure can leave public/ half written, and rsync would then
#
happily publish a broken shop to every tenant. Refuse to deploy
#
anything that does not look like a complete build.
-
name
:
Check the build produced something usable
run
:
|
set -e
for f in \
frontend/public/dashboard.html \
frontend/public/login.html \
frontend/public/robots.txt \
frontend/public/sitemap.xml \
frontend/public/llms.txt
do
test -s "$f" || { echo "missing or empty after build: $f"; exit 1; }
done
# Bundle names carry a content hash, so they are matched by pattern.
ls frontend/public/style/dashboard.*.css >/dev/null 2>&1 \
|| { echo "missing hashed dashboard css"; exit 1; }
ls frontend/public/script/dashboard.*.js >/dev/null 2>&1 \
|| { echo "missing hashed dashboard js"; exit 1; }
echo "build looks complete: $(find frontend/public -type f | wc -l) files"
-
name
:
Set up SSH
run
:
|
mkdir -p ~/.ssh
printf '%s\n' "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy.pem
chmod 600 ~/.ssh/deploy.pem
ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
#
--delete is safe again, and was not when this workflow first ran.
#
#
Back then copyStatic reported success before its copies finished, and
#
built its glob from path.sep, so a Linux build emitted a different
#
tree from a Windows one. CI produced a partial layout, --delete took
#
the difference as intent, and every font and icon disappeared from all
#
17 tenants at once. Both bugs are fixed, and a build now emits exactly
#
what an instance should hold - verified file for file, 539 either side,
#
nothing extra in either direction.
#
#
Keeping it means an instance is a mirror of a known build rather than
#
a pile of whatever any deploy ever left behind, which is what made the
#
original failure so hard to see.
#
Hashed bundles are PROTECTED from --delete (rsync filter), because a
#
page already open in a browser still references the previous hashes -
#
deleting them mid-session strips a working shop of its stylesheet
#
("mobile view add category shown and page broken. crashed" was an open
#
tab meeting a deploy that had pruned style/dashboard.<oldhash>.css).
#
The CDN workflow learned this on day one; this one learns it now.
#
The mirror principle survives via the retention step below: newest 3
#
per bundle family stay, older ones go.
-
name
:
Sync to the tenant instance
run
:
|
rsync -az --delete \
--filter='protect public/script/*.js' \
--filter='protect public/style/*.css' \
--exclude node_modules --exclude .git --exclude '.gitignore' \
--exclude 'public/all.zip' \
-e "ssh -i ~/.ssh/deploy.pem" \
frontend/ "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:~/apps/tenants/app/frontend/"
#
Retention: for every hashed bundle family (name.<hash8>.ext), keep the
#
newest 3 and remove the rest. An open tab survives at least two more
#
deploys; the instance never accumulates unboundedly.
-
name
:
Prune old hashed bundles (keep newest 3 per family)
run
:
|
ssh -i ~/.ssh/deploy.pem "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" 'bash -s' <<'REMOTE'
set -u
for d in ~/apps/tenants/app/frontend/public/script ~/apps/tenants/app/frontend/public/style; do
[ -d "$d" ] || continue
cd "$d"
ls -1 2>/dev/null | grep -E '^[A-Za-z0-9_-]+\.[0-9a-f]{8}\.(js|css)$' \
| sed -E 's/\.[0-9a-f]{8}\.(js|css)$/.\1/' | sort -u \
| while read -r fam; do
base="${fam%.*}"; ext="${fam##*.}"
ls -1t "$base".????????."$ext" 2>/dev/null | tail -n +4 \
| while read -r old; do rm -f -- "$old" && echo "pruned $d/$old"; done
done
done
REMOTE
#
No pm2 restart on purpose: these are static files read from disk per
#
request, so the tenants pick them up with no interruption to a shop
#
that is mid-sale.
#
Checks assets, not just pages. When the first run of this workflow
#
deleted every font and icon, all four pages still returned 200 and the
#
deploy looked clean; the shops were only visibly broken once someone
#
opened one. Assert the things a page depends on, not the page.
-
name
:
Confirm the shops can still load what the pages need
run
:
|
ssh -i ~/.ssh/deploy.pem "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" '
set -e
cd ~/apps/tenants/app/frontend
fail=0
# The pages by name; the bundles by hashed pattern (the name
# carries a content hash and changes every deploy).
for f in public/dashboard.html public/login.html public/robots.txt public/sitemap.xml public/llms.txt; do
if [ -s "$f" ]; then echo " ok $f"; else echo " MISSING $f"; fail=1; fi
done
ls public/style/dashboard.*.css >/dev/null 2>&1 && echo " ok hashed dashboard css" || { echo " MISSING hashed dashboard css"; fail=1; }
ls public/script/dashboard.*.js >/dev/null 2>&1 && echo " ok hashed dashboard js" || { echo " MISSING hashed dashboard js"; fail=1; }
# Assets by category, not by filename. The first version of this
# check named individual files under public/static/static, and when
# the build stopped writing that directory the check failed on every
# run while the deploy itself was fine. A directory that should have
# files in it either does or does not, and that stays true when a
# font or an icon is renamed.
for d in fonts images json pages; do
n=$(find "public/static/$d" -type f 2>/dev/null | wc -l)
if [ "$n" -gt 0 ]; then echo " ok public/static/$d ($n files)";
else echo " EMPTY public/static/$d"; fail=1; fi
done
total=$(find public -type f | wc -l)
echo " pages and assets: $total files"
# A sane floor. A deploy that leaves a handful of files behind has
# gone wrong even if every check above happens to pass.
if [ "$total" -lt 200 ]; then echo " too few files to be a complete build"; fail=1; fi
exit $fail
'
You can’t perform that action at this time.