Compare commits
5 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8bf72b79d | ||
| f75e42d131 | |||
|
|
8f4047d151 | ||
| 98ec60641d | |||
|
|
9739d5e8e9 |
6 changed files with 137 additions and 66 deletions
|
|
@ -105,6 +105,60 @@ jobs:
|
|||
echo "New version: $NEW_VERSION"
|
||||
echo "Current VERSION file: $(cat VERSION 2>/dev/null || echo 'not found')"
|
||||
|
||||
- name: Update Version Files
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
TAG="${{ steps.version.outputs.tag }}"
|
||||
|
||||
echo "📝 Updating version files to: $VERSION"
|
||||
|
||||
# Configure git
|
||||
git config user.name "forgebot"
|
||||
git config user.email "forgebot@forgejo.io"
|
||||
|
||||
# Fetch latest changes to avoid conflicts
|
||||
git fetch origin main || echo "Fetch completed or already up to date"
|
||||
git checkout main || echo "Already on main"
|
||||
|
||||
# Update VERSION file
|
||||
echo "$VERSION" > VERSION
|
||||
|
||||
# Update portainer.yml with new version
|
||||
sed -i "s|\(image: git.jusemon.com/jusemon/threejs-test:\)[0-9.]*|\1$VERSION|" portainer.yml
|
||||
|
||||
# Verify the updates
|
||||
if grep -q "^$VERSION$" VERSION && grep -q "image: git.jusemon.com/jusemon/threejs-test:$VERSION" portainer.yml; then
|
||||
echo "✅ Successfully updated VERSION and portainer.yml to $VERSION"
|
||||
else
|
||||
echo "❌ Failed to update version files"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if there are changes to commit
|
||||
if git diff --quiet VERSION portainer.yml; then
|
||||
echo "⚠️ No changes to commit (files already up to date)"
|
||||
echo "VERSION_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
|
||||
else
|
||||
# Stage and commit with [skip ci] to prevent infinite loop
|
||||
# Note: Forgejo Actions should respect [skip ci] in commit messages
|
||||
git add VERSION portainer.yml
|
||||
git commit -m "chore: update version to $VERSION [skip ci]" || {
|
||||
echo "⚠️ Commit failed (may already be committed)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Push to main branch (remote should already be configured with token)
|
||||
git push origin main || {
|
||||
echo "⚠️ Push failed (check token permissions)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Get the commit hash of the version update commit
|
||||
VERSION_COMMIT_HASH=$(git rev-parse HEAD)
|
||||
echo "VERSION_COMMIT_HASH=$VERSION_COMMIT_HASH" >> $GITHUB_ENV
|
||||
echo "✅ Successfully committed and pushed version update to $VERSION (commit: $VERSION_COMMIT_HASH)"
|
||||
fi
|
||||
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
|
|
@ -128,20 +182,24 @@ jobs:
|
|||
VERSION="${{ steps.version.outputs.version }}"
|
||||
TAG="${{ steps.version.outputs.tag }}"
|
||||
IMAGE_NAME="git.jusemon.com/jusemon/threejs-test:$VERSION"
|
||||
COMMIT_HASH=$(git rev-parse HEAD)
|
||||
COMMIT_SHORT=$(git rev-parse --short HEAD)
|
||||
# Use the version update commit hash (which has the correct version in files)
|
||||
COMMIT_HASH="${VERSION_COMMIT_HASH:-$(git rev-parse HEAD)}"
|
||||
COMMIT_SHORT=$(git rev-parse --short "$COMMIT_HASH")
|
||||
BUILD_DATE=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
|
||||
|
||||
# Get commits since last tag
|
||||
# Get commits since last tag, excluding version update commits
|
||||
LATEST_TAG=$(git describe --tags --match 'v*.*.*' --abbrev=0 2>/dev/null || echo "")
|
||||
if [[ -n "$LATEST_TAG" ]]; then
|
||||
COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
|
||||
# Get commits excluding "chore: update version" commits (from previous releases)
|
||||
# We want commits from the tag to the version update commit (exclusive of the version commit itself)
|
||||
COMMITS=$(git log ${LATEST_TAG}..${COMMIT_HASH}^ --pretty=format:"- %s (%h)" --no-merges | grep -v "chore: update version")
|
||||
else
|
||||
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges -10)
|
||||
# Get commits excluding version update commits
|
||||
COMMITS=$(git log ${COMMIT_HASH}^ --pretty=format:"- %s (%h)" --no-merges -10 | grep -v "chore: update version")
|
||||
fi
|
||||
|
||||
# Get author of the commit
|
||||
COMMIT_AUTHOR=$(git log -1 --pretty=format:"%an <%ae>")
|
||||
# Get author of the version update commit (or HEAD if no version commit)
|
||||
COMMIT_AUTHOR=$(git log -1 --pretty=format:"%an <%ae>" "$COMMIT_HASH")
|
||||
|
||||
# Read template and replace placeholders
|
||||
TEMPLATE_FILE=".forgejo/release-template.md"
|
||||
|
|
@ -185,67 +243,21 @@ jobs:
|
|||
git config user.name "forgejo-actions"
|
||||
git config user.email "forgejo-actions@forgejo.io"
|
||||
TAG="${{ steps.version.outputs.tag }}"
|
||||
# Use the version update commit hash (which has the correct version in files)
|
||||
VERSION_COMMIT="${VERSION_COMMIT_HASH:-$(git rev-parse HEAD)}"
|
||||
|
||||
# Check if tag already exists
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
echo "Tag $TAG already exists, skipping tag creation"
|
||||
echo "TAG_CREATED=false" >> $GITHUB_ENV
|
||||
else
|
||||
git tag -a "$TAG" -F /tmp/release_message.txt
|
||||
# Create tag pointing to the version update commit (which has correct VERSION file)
|
||||
git tag -a "$TAG" -F /tmp/release_message.txt "$VERSION_COMMIT"
|
||||
git push origin "$TAG"
|
||||
echo "Created tag $TAG with detailed release notes"
|
||||
echo "Created tag $TAG pointing to version update commit $VERSION_COMMIT with detailed release notes"
|
||||
echo "TAG_CREATED=true" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Update Version Files
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
TAG="${{ steps.version.outputs.tag }}"
|
||||
|
||||
echo "📝 Updating version files to: $VERSION"
|
||||
|
||||
# Configure git
|
||||
git config user.name "forgebot"
|
||||
git config user.email "forgebot@forgejo.io"
|
||||
|
||||
# Fetch latest changes to avoid conflicts
|
||||
git fetch origin main || echo "Fetch completed or already up to date"
|
||||
git checkout main || echo "Already on main"
|
||||
|
||||
# Update VERSION file
|
||||
echo "$VERSION" > VERSION
|
||||
|
||||
# Update portainer.yml with new version
|
||||
sed -i "s|\(image: git.jusemon.com/jusemon/threejs-test:\)[0-9.]*|\1$VERSION|" portainer.yml
|
||||
|
||||
# Verify the updates
|
||||
if grep -q "^$VERSION$" VERSION && grep -q "image: git.jusemon.com/jusemon/threejs-test:$VERSION" portainer.yml; then
|
||||
echo "✅ Successfully updated VERSION and portainer.yml to $VERSION"
|
||||
else
|
||||
echo "❌ Failed to update version files"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if there are changes to commit
|
||||
if git diff --quiet VERSION portainer.yml; then
|
||||
echo "⚠️ No changes to commit (files already up to date)"
|
||||
else
|
||||
# Stage and commit with [skip ci] to prevent infinite loop
|
||||
# Note: Forgejo Actions should respect [skip ci] in commit messages
|
||||
git add VERSION portainer.yml
|
||||
git commit -m "chore: update version to $VERSION [skip ci]" || {
|
||||
echo "⚠️ Commit failed (may already be committed)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Push to main branch (remote should already be configured with token)
|
||||
git push origin main || {
|
||||
echo "⚠️ Push failed (check token permissions)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
echo "✅ Successfully committed and pushed version update to $VERSION"
|
||||
fi
|
||||
|
||||
- name: Job Summary
|
||||
if: success()
|
||||
run: |
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ RUN printf '{"version":"%s","buildDate":"%s"}\n' "${VERSION}" "${BUILD_DATE}" >
|
|||
COPY index.html /usr/share/nginx/html/
|
||||
COPY src/ /usr/share/nginx/html/src/
|
||||
|
||||
# Copy and run cache busting script (bash/sed - no external dependencies needed)
|
||||
COPY build-cache-bust.sh /tmp/build-cache-bust.sh
|
||||
RUN chmod +x /tmp/build-cache-bust.sh && \
|
||||
/tmp/build-cache-bust.sh "${VERSION}" /usr/share/nginx/html
|
||||
|
||||
# Copy nginx configuration
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
|
|
|
|||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
1.0.1
|
||||
1.0.4
|
||||
|
|
|
|||
46
build-cache-bust.sh
Executable file
46
build-cache-bust.sh
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/sh
|
||||
# Simple cache busting script - adds version query params to all JS imports
|
||||
# Only runs during Docker build, not during local development
|
||||
# This keeps development simple (no tools needed) while ensuring production cache busting
|
||||
|
||||
VERSION="${1:-dev}"
|
||||
SRC_DIR="${2:-/usr/share/nginx/html}"
|
||||
|
||||
echo "Adding cache busting (v=${VERSION}) to JS imports in ${SRC_DIR}/src..."
|
||||
|
||||
# Find all JS files and add version query param to relative imports
|
||||
find "$SRC_DIR/src" -type f -name "*.js" | while read -r file; do
|
||||
# Skip if file doesn't exist
|
||||
[ ! -f "$file" ] && continue
|
||||
|
||||
# Process file with sed to add version query params
|
||||
# Pattern: from './path.js' or from "../path.js" or import('./path.js')
|
||||
# Only match relative imports (./ or ../) ending in .js
|
||||
# Skip if already has query params (contains ?)
|
||||
|
||||
# Handle single quote imports: from './path.js'
|
||||
sed -i.bak \
|
||||
-e "s|from '\\(\\.[./][^']*\\.js\\)'|from '\\1?v=${VERSION}'|g" \
|
||||
-e "s|from '\\(\\.[./][^']*\\.js\\)?[^']*'|from '\\1?v=${VERSION}'|g" \
|
||||
"$file"
|
||||
|
||||
# Handle double quote imports: from "./path.js"
|
||||
sed -i.bak \
|
||||
-e "s|from \"\\(\\.[./][^\"]*\\.js\\)\"|from \"\\1?v=${VERSION}\"|g" \
|
||||
-e "s|from \"\\(\\.[./][^\"]*\\.js\\)?[^\"]*\"|from \"\\1?v=${VERSION}\"|g" \
|
||||
"$file"
|
||||
|
||||
# Handle dynamic imports: import('./path.js')
|
||||
sed -i.bak \
|
||||
-e "s|import('\\(\\.[./][^']*\\.js\\)')|import('\\1?v=${VERSION}')|g" \
|
||||
-e "s|import('\\(\\.[./][^']*\\.js\\)?[^']*')|import('\\1?v=${VERSION}')|g" \
|
||||
-e "s|import(\"\\(\\.[./][^\"]*\\.js\\)\")|import(\"\\1?v=${VERSION}\")|g" \
|
||||
-e "s|import(\"\\(\\.[./][^\"]*\\.js\\)?[^\"]*\")|import(\"\\1?v=${VERSION}\")|g" \
|
||||
"$file"
|
||||
|
||||
# Remove backup file
|
||||
rm -f "${file}.bak"
|
||||
done
|
||||
|
||||
echo "Cache busting complete! All JS imports now include ?v=${VERSION}"
|
||||
|
||||
18
nginx.conf
18
nginx.conf
|
|
@ -9,11 +9,19 @@ server {
|
|||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# Prevent caching of JavaScript files and version.json
|
||||
location ~* \.(js|mjs)$ {
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
# Cache JavaScript files with version query params for 1 year (immutable)
|
||||
# Files without version params are not cached
|
||||
location ~* \.(js|mjs)(\?v=[^&]+)?$ {
|
||||
if ($args ~ "v=") {
|
||||
# Has version param - cache for 1 year (immutable)
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
}
|
||||
if ($args !~ "v=") {
|
||||
# No version param - don't cache
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
}
|
||||
add_header Vary "Accept-Encoding";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ name: threejs-test
|
|||
|
||||
services:
|
||||
app:
|
||||
image: git.jusemon.com/jusemon/threejs-test:1.0.1
|
||||
image: git.jusemon.com/jusemon/threejs-test:1.0.4
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue