Bugfix/Separate CI files (#15)
Reviewed-on: #15 Co-authored-by: Juan Sebastian Montoya <juansmm@outlook.com> Co-committed-by: Juan Sebastian Montoya <juansmm@outlook.com>
This commit is contained in:
parent
94ddf8bde4
commit
e82446cf00
2 changed files with 88 additions and 83 deletions
53
.forgejo/workflows/build-and-validate.yaml
Normal file
53
.forgejo/workflows/build-and-validate.yaml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
name: Build and Publish Docker Image
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build-and-validate:
|
||||
name: Build and Validate
|
||||
runs-on: ubuntu
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Validate PR Title
|
||||
run: |
|
||||
PR_TITLE="${{ github.event.pull_request.title }}"
|
||||
echo "PR Title: $PR_TITLE"
|
||||
|
||||
# Check if PR title starts with valid prefix
|
||||
if [[ "$PR_TITLE" =~ ^(Release|Feature|Hotfix|Bugfix)/ ]]; then
|
||||
echo "✅ PR title is valid: $PR_TITLE"
|
||||
else
|
||||
echo "❌ PR title must start with one of: Release/, Feature/, Hotfix/, or Bugfix/"
|
||||
echo "Current title: $PR_TITLE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
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: |
|
||||
docker run --rm -d --name test-container -p 8080:80 threejs-test:test
|
||||
sleep 2
|
||||
curl -f http://localhost:8080 || exit 1
|
||||
docker stop test-container
|
||||
|
||||
- name: Job Summary
|
||||
if: success()
|
||||
run: |
|
||||
SUMMARY_FILE="${FORGEJO_STEP_SUMMARY}"
|
||||
cat >> "$SUMMARY_FILE" << 'EOF'
|
||||
## ✅ Build and Validation Complete
|
||||
|
||||
- ✅ Docker image built successfully
|
||||
- ✅ Image validated (container started and HTTP check passed)
|
||||
|
||||
The image is ready for deployment.
|
||||
EOF
|
||||
cat "$SUMMARY_FILE"
|
||||
|
|
@ -1,65 +1,14 @@
|
|||
name: Build and Publish Docker Image
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build-and-validate:
|
||||
name: Build and Validate
|
||||
runs-on: ubuntu
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Validate PR Title
|
||||
if: github.event_name == 'pull_request'
|
||||
run: |
|
||||
PR_TITLE="${{ github.event.pull_request.title }}"
|
||||
echo "PR Title: $PR_TITLE"
|
||||
|
||||
# Check if PR title starts with valid prefix
|
||||
if [[ "$PR_TITLE" =~ ^(Release|Feature|Hotfix|Bugfix)/ ]]; then
|
||||
echo "✅ PR title is valid: $PR_TITLE"
|
||||
else
|
||||
echo "❌ PR title must start with one of: Release/, Feature/, Hotfix/, or Bugfix/"
|
||||
echo "Current title: $PR_TITLE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
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: |
|
||||
docker run --rm -d --name test-container -p 8080:80 threejs-test:test
|
||||
sleep 2
|
||||
curl -f http://localhost:8080 || exit 1
|
||||
docker stop test-container
|
||||
|
||||
- name: Job Summary
|
||||
if: success()
|
||||
run: |
|
||||
SUMMARY_FILE="${FORGEJO_STEP_SUMMARY}"
|
||||
cat >> "$SUMMARY_FILE" << 'EOF'
|
||||
## ✅ Build and Validation Complete
|
||||
|
||||
- ✅ Docker image built successfully
|
||||
- ✅ Image validated (container started and HTTP check passed)
|
||||
|
||||
The image is ready for deployment.
|
||||
EOF
|
||||
|
||||
publish:
|
||||
name: Publish to Registry
|
||||
runs-on: ubuntu
|
||||
needs: build-and-validate
|
||||
if: github.event_name == 'push'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
|
@ -297,38 +246,6 @@ jobs:
|
|||
echo "✅ Successfully committed and pushed version update to $VERSION"
|
||||
fi
|
||||
|
||||
- name: Trigger Portainer Deployment
|
||||
if: success()
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
WEBHOOK_URL="${{ secrets.PORTAINER_WEBHOOK_URL }}"
|
||||
|
||||
if [[ -z "$WEBHOOK_URL" ]]; then
|
||||
echo "⚠️ Warning: PORTAINER_WEBHOOK_URL secret not set, skipping webhook call"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "🚀 Triggering Portainer deployment for version $VERSION"
|
||||
|
||||
# Call Portainer webhook to trigger stack update
|
||||
HTTP_CODE=$(curl -s -o /tmp/webhook_response.txt -w "%{http_code}" -X POST "$WEBHOOK_URL" \
|
||||
-H "Content-Type: application/json" \
|
||||
--max-time 30)
|
||||
|
||||
if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then
|
||||
echo "✅ Successfully triggered Portainer deployment (HTTP $HTTP_CODE)"
|
||||
if [[ -f /tmp/webhook_response.txt ]]; then
|
||||
echo "Response: $(cat /tmp/webhook_response.txt)"
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Warning: Webhook call returned HTTP $HTTP_CODE"
|
||||
if [[ -f /tmp/webhook_response.txt ]]; then
|
||||
echo "Response: $(cat /tmp/webhook_response.txt)"
|
||||
fi
|
||||
# Don't fail the workflow if webhook fails
|
||||
exit 0
|
||||
fi
|
||||
|
||||
- name: Job Summary
|
||||
if: success()
|
||||
run: |
|
||||
|
|
@ -369,4 +286,39 @@ jobs:
|
|||
docker pull git.jusemon.com/jusemon/threejs-test:latest
|
||||
\`\`\`
|
||||
EOF
|
||||
cat "$SUMMARY_FILE"
|
||||
|
||||
deploy:
|
||||
name: Deploy to Portainer
|
||||
runs-on: ubuntu
|
||||
needs: publish
|
||||
steps:
|
||||
- name: Trigger Portainer Deployment
|
||||
run: |
|
||||
WEBHOOK_URL="${{ secrets.PORTAINER_WEBHOOK_URL }}"
|
||||
|
||||
if [[ -z "$WEBHOOK_URL" ]]; then
|
||||
echo "⚠️ Warning: PORTAINER_WEBHOOK_URL secret not set, skipping webhook call"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "🚀 Triggering Portainer deployment for latest version"
|
||||
|
||||
# Call Portainer webhook to trigger stack update
|
||||
HTTP_CODE=$(curl -s -o /tmp/webhook_response.txt -w "%{http_code}" -X POST "$WEBHOOK_URL" \
|
||||
-H "Content-Type: application/json" \
|
||||
--max-time 30)
|
||||
|
||||
if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then
|
||||
echo "✅ Successfully triggered Portainer deployment (HTTP $HTTP_CODE)"
|
||||
if [[ -f /tmp/webhook_response.txt ]]; then
|
||||
echo "Response: $(cat /tmp/webhook_response.txt)"
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Warning: Webhook call returned HTTP $HTTP_CODE"
|
||||
if [[ -f /tmp/webhook_response.txt ]]; then
|
||||
echo "Response: $(cat /tmp/webhook_response.txt)"
|
||||
fi
|
||||
# Don't fail the workflow if webhook fails
|
||||
exit 0
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue