Versioning assets to handle browser cache.

This commit is contained in:
Bob Vandevliet 2024-06-27 09:03:54 +02:00
parent fdb6dcf18c
commit d3ee905ec2

View file

@ -20,6 +20,26 @@ jobs:
-
name: Checkout
uses: actions/checkout@v4
-
name: Get Metadata
id: metadata
run: |
branchName=${GITHUB_REF#refs/heads/}
version=$(date +"%y%m.%d.%H%M%S")
tagName=$version
preRelease=false
if [[ "$branchName" != "master" && "$branchName" != "main" ]]; then
tagName="$tagName-$branchName"
preRelease=true
fi
echo "BRANCH_NAME = $branchName"
echo "VERSION = $version"
echo "TAG_NAME = $tagName"
echo "PRERELEASE = $preRelease"
echo "BRANCH_NAME=$branchName" >> $GITHUB_OUTPUT
echo "VERSION=$version" >> $GITHUB_OUTPUT
echo "TAG_NAME=$tagName" >> $GITHUB_OUTPUT
echo "PRERELEASE=$preRelease" >> $GITHUB_OUTPUT
-
name: Setup pnpm
uses: pnpm/action-setup@v4.0.0
@ -29,6 +49,14 @@ jobs:
-
name: Compile CSS
run: pnpm run build
-
name: Append version as query arg to asset URLs
env:
VERSION: ${{ steps.metadata.outputs.VERSION }}
run: |
echo "VERSION = $VERSION"
find public -type f -name '*.html' -exec sed -i "s/\"\([^\"?]\+\.css\)\"/\"\1?v=$VERSION\"/g" {} +
find public -type f -name '*.html' -exec sed -i "s/\"\([^\"?]\+\.js\)\"/\"\1?v=$VERSION\"/g" {} +
-
name: Copy files to public folder
run: mkdir -p /usr/share/nginx/static/fpv; cp -rf public/* /usr/share/nginx/static/fpv