Feature/Update versioning logic (#7)
All checks were successful
Build and Publish Docker Image / Build and Validate (push) Successful in 8s
Build and Publish Docker Image / Publish to Registry (push) Successful in 7s

Reviewed-on: #7
Co-authored-by: Juan Sebastian Montoya <juansmm@outlook.com>
Co-committed-by: Juan Sebastian Montoya <juansmm@outlook.com>
This commit is contained in:
Juan Sebastián Montoya 2025-11-26 11:22:30 -05:00 committed by Juan Sebastián Montoya
parent c933f5f8cc
commit 28c820488e
6 changed files with 117 additions and 9 deletions

View file

@ -18,7 +18,7 @@ jobs:
- name: Build Docker Image
run: |
docker build -t threejs-test:test .
docker build --build-arg VERSION=test --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -t threejs-test:test .
- name: Validate Image
run: |
@ -82,11 +82,14 @@ jobs:
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG"
echo "New version: $NEW_VERSION"
echo "Current VERSION file: $(cat VERSION 2>/dev/null || echo 'not found')"
- name: Build Docker Image
run: |
IMAGE_NAME="git.jusemon.com/jusemon/threejs-test:${{ steps.version.outputs.version }}"
docker build -t "$IMAGE_NAME" .
VERSION="${{ steps.version.outputs.version }}"
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
IMAGE_NAME="git.jusemon.com/jusemon/threejs-test:$VERSION"
docker build --build-arg VERSION="$VERSION" --build-arg BUILD_DATE="$BUILD_DATE" -t "$IMAGE_NAME" .
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
- name: Push Docker Image
@ -154,6 +157,56 @@ jobs:
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 "forgejo-actions"
git config user.email "forgejo-actions@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
git push origin main || {
echo "⚠️ Push failed (may need manual intervention or branch protection)"
exit 0
}
echo "✅ Successfully committed and pushed version update to $VERSION"
fi
- name: Job Summary
if: success()
run: |
@ -183,11 +236,15 @@ jobs:
echo "- ⚠️ Tag \`$TAG\` already exists, skipped creation" >> "$SUMMARY_FILE"
fi
cat >> "$SUMMARY_FILE" << 'EOF'
cat >> "$SUMMARY_FILE" << EOF
### Version Files
- ✅ VERSION file updated to \`$VERSION\`
- ✅ portainer.yml updated to \`$VERSION\`
### Pull Command
```bash
\`\`\`bash
docker pull git.jusemon.com/jusemon/threejs-test:latest
```
\`\`\`
EOF

View file

@ -1,5 +1,12 @@
FROM nginx:alpine
# Accept build argument for version
ARG VERSION=dev
ARG BUILD_DATE=unknown
# Create version.json file with build information
RUN printf '{"version":"%s","buildDate":"%s"}\n' "${VERSION}" "${BUILD_DATE}" > /usr/share/nginx/html/version.json
# Copy the HTML file
COPY index.html /usr/share/nginx/html/index.html

2
VERSION Normal file
View file

@ -0,0 +1,2 @@
0.1.5

View file

@ -1,7 +1,11 @@
name: threejs-test
services:
ui:
build: .
app:
build:
context: .
args:
VERSION: ${VERSION:-dev}
BUILD_DATE: ${BUILD_DATE:-unknown}
restart: unless-stopped

View file

@ -72,10 +72,25 @@
text-align: center;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}
#version {
position: absolute;
top: 20px;
right: 20px;
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
z-index: 100;
font-family: 'Courier New', monospace;
}
@media (max-width: 768px) {
#instructions {
font-size: 14px;
}
#version {
font-size: 12px;
top: 10px;
right: 10px;
}
}
</style>
</head>
@ -85,6 +100,8 @@
<div>Health: <span id="health">100</span></div>
</div>
<div id="version">v<span id="versionNumber">-</span></div>
<div id="gameOver">
<h1>Game Over!</h1>
<p>Final Score: <span id="finalScore">0</span></p>
@ -97,6 +114,27 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// Load and display version information
(function() {
fetch('/version.json')
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Version file not found');
})
.then(data => {
const versionElement = document.getElementById('versionNumber');
if (versionElement && data.version) {
versionElement.textContent = data.version;
}
})
.catch(error => {
// Silently fail if version.json doesn't exist (e.g., in development)
console.debug('Version information not available:', error.message);
});
})();
// Base GameObject class
class GameObject {
constructor(scene, groundSize) {

View file

@ -2,7 +2,7 @@ name: threejs-test
services:
app:
image: git.jusemon.com/jusemon/threejs-test:latest
image: git.jusemon.com/jusemon/threejs-test:0.1.5
pull_policy: build
restart: unless-stopped