Skip to content

Commit d347d41

Browse files
committed
fix: improve Docker image tagging for prereleases
- Add proper tag management for alpha/beta releases - Extract primary tag from metadata for testing and security scan - Disable latest tag for prereleases - Add prerelease tag for alpha/beta versions - Pass image tag through job outputs for better handling
1 parent 6949ed9 commit d347d41

File tree

2 files changed

+143
-5
lines changed

2 files changed

+143
-5
lines changed

.github/workflows/ci-cd.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ jobs:
158158
runs-on: ubuntu-latest
159159
needs: release
160160
if: needs.release.outputs.new-release-published == 'true' || needs.release.outputs.version-changed == 'true'
161+
outputs:
162+
image-tag: ${{ steps.set-tag.outputs.tag }}
161163

162164
steps:
163165
- name: Checkout code
@@ -182,9 +184,20 @@ jobs:
182184
images: ${{ secrets.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE }}
183185
tags: |
184186
type=semver,pattern={{version}},value=v${{ needs.release.outputs.new-release-version }}
185-
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.release.outputs.new-release-version }}
186-
type=semver,pattern={{major}},value=v${{ needs.release.outputs.new-release-version }}
187-
type=raw,value=latest
187+
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.release.outputs.new-release-version }},enable=${{ !contains(needs.release.outputs.new-release-version, '-') }}
188+
type=semver,pattern={{major}},value=v${{ needs.release.outputs.new-release-version }},enable=${{ !contains(needs.release.outputs.new-release-version, '-') }}
189+
type=raw,value=latest,enable=${{ !contains(needs.release.outputs.new-release-version, '-') }}
190+
type=raw,value=prerelease,enable=${{ contains(needs.release.outputs.new-release-version, '-') }}
191+
192+
- name: Set primary tag
193+
id: set-tag
194+
run: |
195+
echo "All tags from metadata:"
196+
echo "${{ steps.meta.outputs.tags }}"
197+
echo "---"
198+
PRIMARY_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
199+
echo "tag=$PRIMARY_TAG" >> $GITHUB_OUTPUT
200+
echo "Primary tag: $PRIMARY_TAG"
188201
189202
- name: Build and push Docker image
190203
uses: docker/build-push-action@v5
@@ -202,8 +215,10 @@ jobs:
202215
# Wait a moment for the image to be available
203216
sleep 10
204217
218+
echo "Testing image: ${{ steps.set-tag.outputs.tag }}"
219+
205220
# Test the published image
206-
echo "# Published Test v${{ needs.release.outputs.new-release-version }} **success**" | docker run --rm -i ${{ secrets.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE }}:${{ needs.release.outputs.new-release-version }}
221+
echo "# Published Test v${{ needs.release.outputs.new-release-version }} **success**" | docker run --rm -i "${{ steps.set-tag.outputs.tag }}"
207222
208223
security-scan:
209224
name: Security Scan
@@ -218,7 +233,7 @@ jobs:
218233
- name: Run Trivy vulnerability scanner
219234
uses: aquasecurity/trivy-action@master
220235
with:
221-
image-ref: ${{ secrets.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE }}:${{ needs.release.outputs.new-release-version }}
236+
image-ref: ${{ needs.docker-build-and-push.outputs.image-tag }}
222237
format: 'sarif'
223238
output: 'trivy-results.sarif'
224239

test-github-setup.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/bash
2+
3+
# Test script to verify GitHub repository setup
4+
# This script should be run after pushing to GitHub
5+
6+
set -e
7+
8+
echo "🔍 Testing GitHub repository setup..."
9+
10+
# Check if we're in a git repository
11+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
12+
echo "❌ Not in a git repository"
13+
exit 1
14+
fi
15+
16+
# Check if we have a remote origin
17+
if ! git remote get-url origin > /dev/null 2>&1; then
18+
echo "❌ No remote origin configured"
19+
exit 1
20+
fi
21+
22+
ORIGIN_URL=$(git remote get-url origin)
23+
echo "✅ Remote origin: $ORIGIN_URL"
24+
25+
# Check if we're on main branch
26+
CURRENT_BRANCH=$(git branch --show-current)
27+
if [ "$CURRENT_BRANCH" != "main" ]; then
28+
echo "⚠️ Currently on branch: $CURRENT_BRANCH (should be 'main')"
29+
else
30+
echo "✅ On main branch"
31+
fi
32+
33+
# Check if we have the required files
34+
echo ""
35+
echo "📋 Checking required files..."
36+
37+
required_files=(
38+
".github/workflows/ci-cd.yml"
39+
".github/workflows/pr-test.yml"
40+
"package.json"
41+
"package-lock.json"
42+
".releaserc.json"
43+
"CONTRIBUTING.md"
44+
"README.md"
45+
"LICENSE"
46+
)
47+
48+
for file in "${required_files[@]}"; do
49+
if [ -f "$file" ]; then
50+
echo "$file"
51+
else
52+
echo "$file (missing)"
53+
exit 1
54+
fi
55+
done
56+
57+
echo ""
58+
echo "🐳 Checking Docker setup..."
59+
60+
# Check if Docker is available
61+
if ! command -v docker &> /dev/null; then
62+
echo "⚠️ Docker not found (install for local testing)"
63+
else
64+
echo "✅ Docker available"
65+
66+
# Try to build the image
67+
if docker build -t md-to-bbcode:test . > /dev/null 2>&1; then
68+
echo "✅ Docker image builds successfully"
69+
70+
# Test the image
71+
if echo "# Test" | docker run --rm -i md-to-bbcode:test > /dev/null 2>&1; then
72+
echo "✅ Docker image works correctly"
73+
else
74+
echo "❌ Docker image failed to run"
75+
exit 1
76+
fi
77+
else
78+
echo "❌ Docker image build failed"
79+
exit 1
80+
fi
81+
fi
82+
83+
echo ""
84+
echo "🧪 Running tests..."
85+
86+
# Run Python tests
87+
if python test_converter.py > /dev/null 2>&1; then
88+
echo "✅ Python tests pass"
89+
else
90+
echo "❌ Python tests failed"
91+
exit 1
92+
fi
93+
94+
echo ""
95+
echo "📦 Checking Node.js setup..."
96+
97+
# Check if Node.js is available
98+
if ! command -v npm &> /dev/null; then
99+
echo "⚠️ npm not found (needed for semantic-release)"
100+
else
101+
echo "✅ npm available"
102+
103+
# Check if dependencies are installed
104+
if [ -d "node_modules" ]; then
105+
echo "✅ Node.js dependencies installed"
106+
else
107+
echo "🔄 Installing Node.js dependencies..."
108+
npm ci
109+
echo "✅ Node.js dependencies installed"
110+
fi
111+
fi
112+
113+
echo ""
114+
echo "🎯 Next steps:"
115+
echo "1. Push to GitHub: git push origin main"
116+
echo "2. Check GitHub Actions: https://github.com/YOUR_USERNAME/md_to_bbcode/actions"
117+
echo "3. Configure repository secrets:"
118+
echo " - DOCKER_USERNAME: Your Docker Hub username"
119+
echo " - DOCKER_PASSWORD: Your Docker Hub password/token"
120+
echo "4. Make a commit with 'feat: initial release' to trigger first release"
121+
122+
echo ""
123+
echo "🎉 Setup verification complete!"

0 commit comments

Comments
 (0)