fix: overhaul release pipeline — 5 issues resolved
1. version input now optional — auto-increment from release_type works 2. replaced deprecated actions/create-release@v1 with gh release create 3. race condition fixed — release commit uses [skip ci], removed fragile github.actor guard from build-and-push.yaml 4. simplified gh-pages publishing — uses clean temp dir + shallow clone instead of convoluted git worktree fallback 5. version parsing strips pre-release suffixes (e.g., 2.0.0-dev → 2.0.0) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -17,7 +17,6 @@ Use this for all version releases:
|
|||||||
- ✅ Builds Docker image with all proper tags
|
- ✅ Builds Docker image with all proper tags
|
||||||
- ✅ Publishes Helm chart to GitHub Pages (`https://cpfarhood.github.io/devcontainer`)
|
- ✅ Publishes Helm chart to GitHub Pages (`https://cpfarhood.github.io/devcontainer`)
|
||||||
- ✅ Creates GitHub Release with changelog
|
- ✅ Creates GitHub Release with changelog
|
||||||
- ✅ No more `[skip ci]` blocking builds!
|
|
||||||
|
|
||||||
### 2️⃣ For Quick Fixes → **Quick Fix Build**
|
### 2️⃣ For Quick Fixes → **Quick Fix Build**
|
||||||
Use this for emergency fixes without version changes:
|
Use this for emergency fixes without version changes:
|
||||||
@@ -30,8 +29,8 @@ Use this for emergency fixes without version changes:
|
|||||||
|
|
||||||
### 3️⃣ Automatic CI → **Build and Push**
|
### 3️⃣ Automatic CI → **Build and Push**
|
||||||
Runs automatically on:
|
Runs automatically on:
|
||||||
|
- Pushes to `main` (builds and pushes; skipped for release commits via `[skip ci]`)
|
||||||
- Pull requests (builds but doesn't push)
|
- Pull requests (builds but doesn't push)
|
||||||
- Tags starting with `v*` (builds and pushes)
|
|
||||||
- Manual trigger available
|
- Manual trigger available
|
||||||
|
|
||||||
## Workflow Files
|
## Workflow Files
|
||||||
@@ -90,5 +89,5 @@ gh run watch
|
|||||||
### After (Simple! 🎉)
|
### After (Simple! 🎉)
|
||||||
- **3 total workflows** (down from 6+)
|
- **3 total workflows** (down from 6+)
|
||||||
- **1 button** for complete releases
|
- **1 button** for complete releases
|
||||||
- **No more `[skip ci]`** blocking builds
|
- Release builds its own Docker image — `[skip ci]` on the version commit prevents duplicate CI builds
|
||||||
- **Clear separation** of concerns
|
- **Clear separation** of concerns
|
||||||
@@ -16,9 +16,6 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# Skip builds triggered by release-unified.yaml commits (github-actions[bot])
|
|
||||||
# to prevent racing with the release workflow's own Docker build
|
|
||||||
if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' || github.actor != 'github-actions[bot]'
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: 'Version to release (e.g., 0.1.25)'
|
description: 'Explicit version (e.g., 1.2.3). Leave blank to auto-increment.'
|
||||||
required: true
|
required: false
|
||||||
type: string
|
type: string
|
||||||
release_type:
|
release_type:
|
||||||
description: 'Release type'
|
description: 'Release type (used when version is blank)'
|
||||||
required: true
|
required: true
|
||||||
default: 'patch'
|
default: 'patch'
|
||||||
type: choice
|
type: choice
|
||||||
@@ -49,37 +49,34 @@ jobs:
|
|||||||
- name: Determine Version
|
- name: Determine Version
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ github.event.inputs.version }}" != "" ]; then
|
INPUT_VERSION="${{ github.event.inputs.version }}"
|
||||||
VERSION="${{ github.event.inputs.version }}"
|
if [ -n "$INPUT_VERSION" ]; then
|
||||||
|
VERSION="$INPUT_VERSION"
|
||||||
else
|
else
|
||||||
# Auto-determine next version based on release type
|
# Auto-increment based on release_type
|
||||||
CURRENT=$(grep '^version:' chart/Chart.yaml | awk '{print $2}')
|
CURRENT=$(grep '^version:' chart/Chart.yaml | awk '{print $2}')
|
||||||
MAJOR=$(echo $CURRENT | cut -d. -f1)
|
# Strip any pre-release suffix (e.g., 2.0.0-dev -> 2.0.0)
|
||||||
MINOR=$(echo $CURRENT | cut -d. -f2)
|
CURRENT=$(echo "$CURRENT" | sed 's/-.*//')
|
||||||
PATCH=$(echo $CURRENT | cut -d. -f3)
|
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
|
||||||
|
MINOR=$(echo "$CURRENT" | cut -d. -f2)
|
||||||
|
PATCH=$(echo "$CURRENT" | cut -d. -f3)
|
||||||
|
|
||||||
case "${{ github.event.inputs.release_type }}" in
|
case "${{ github.event.inputs.release_type }}" in
|
||||||
major)
|
major) VERSION="$((MAJOR + 1)).0.0" ;;
|
||||||
VERSION="$((MAJOR + 1)).0.0"
|
minor) VERSION="${MAJOR}.$((MINOR + 1)).0" ;;
|
||||||
;;
|
patch) VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" ;;
|
||||||
minor)
|
|
||||||
VERSION="${MAJOR}.$((MINOR + 1)).0"
|
|
||||||
;;
|
|
||||||
patch)
|
|
||||||
VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||||
echo "tag=v${VERSION}" >> $GITHUB_OUTPUT
|
echo "tag=v${VERSION}" >> $GITHUB_OUTPUT
|
||||||
echo "🚀 Releasing version ${VERSION}"
|
echo "Releasing version ${VERSION}"
|
||||||
|
|
||||||
- name: Update Chart Version
|
- name: Update Chart Version
|
||||||
run: |
|
run: |
|
||||||
sed -i "s/^version: .*/version: ${{ steps.version.outputs.version }}/" chart/Chart.yaml
|
sed -i "s/^version: .*/version: ${{ steps.version.outputs.version }}/" chart/Chart.yaml
|
||||||
git add chart/Chart.yaml
|
git add chart/Chart.yaml
|
||||||
git diff --quiet --staged || git commit -m "chore: release version ${{ steps.version.outputs.version }}"
|
git diff --quiet --staged || git commit -m "chore(release): ${{ steps.version.outputs.version }} [skip ci]"
|
||||||
|
|
||||||
- name: Create and Push Tag
|
- name: Create and Push Tag
|
||||||
run: |
|
run: |
|
||||||
@@ -107,18 +104,25 @@ jobs:
|
|||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
|
|
||||||
- name: Package and Publish Helm Chart to GitHub Pages
|
- name: Publish Helm Chart to GitHub Pages
|
||||||
run: |
|
run: |
|
||||||
# Package the chart
|
|
||||||
helm package chart/
|
helm package chart/
|
||||||
|
CHART_TGZ="devcontainer-${{ steps.version.outputs.version }}.tgz"
|
||||||
|
|
||||||
# Checkout or create gh-pages branch in a temporary directory
|
# Set up gh-pages in a temporary directory
|
||||||
git worktree add /tmp/gh-pages gh-pages 2>/dev/null || {
|
PAGES_DIR=$(mktemp -d)
|
||||||
git worktree add --detach /tmp/gh-pages
|
if git ls-remote --heads origin gh-pages | grep -q gh-pages; then
|
||||||
cd /tmp/gh-pages
|
# gh-pages exists — shallow clone just that branch
|
||||||
git checkout --orphan gh-pages
|
git clone --single-branch --branch gh-pages \
|
||||||
git rm -rf . 2>/dev/null || true
|
"https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" \
|
||||||
cat > index.html <<'HTMLEOF'
|
"$PAGES_DIR"
|
||||||
|
else
|
||||||
|
# First time — initialize gh-pages
|
||||||
|
git init "$PAGES_DIR"
|
||||||
|
git -C "$PAGES_DIR" checkout --orphan gh-pages
|
||||||
|
git -C "$PAGES_DIR" remote add origin \
|
||||||
|
"https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
|
||||||
|
cat > "$PAGES_DIR/index.html" <<'HTMLEOF'
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head><title>Dev Container Helm Chart Repository</title></head>
|
<head><title>Dev Container Helm Chart Repository</title></head>
|
||||||
@@ -131,45 +135,38 @@ jobs:
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
HTMLEOF
|
HTMLEOF
|
||||||
git add index.html
|
fi
|
||||||
git commit -m "Initialize gh-pages branch"
|
|
||||||
git push origin gh-pages
|
|
||||||
cd -
|
|
||||||
}
|
|
||||||
|
|
||||||
# Copy packaged chart to gh-pages worktree
|
git -C "$PAGES_DIR" config user.name "github-actions[bot]"
|
||||||
cp devcontainer-${{ steps.version.outputs.version }}.tgz /tmp/gh-pages/
|
git -C "$PAGES_DIR" config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
# Update Helm repo index
|
# Copy chart package and rebuild index
|
||||||
cd /tmp/gh-pages
|
cp "$CHART_TGZ" "$PAGES_DIR/"
|
||||||
if [ -f index.yaml ]; then
|
if [ -f "$PAGES_DIR/index.yaml" ]; then
|
||||||
helm repo index . --url https://cpfarhood.github.io/devcontainer --merge index.yaml
|
helm repo index "$PAGES_DIR" --url https://cpfarhood.github.io/devcontainer --merge "$PAGES_DIR/index.yaml"
|
||||||
else
|
else
|
||||||
helm repo index . --url https://cpfarhood.github.io/devcontainer
|
helm repo index "$PAGES_DIR" --url https://cpfarhood.github.io/devcontainer
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Commit and push
|
# Commit and push
|
||||||
git add index.yaml *.tgz index.html 2>/dev/null || true
|
git -C "$PAGES_DIR" add .
|
||||||
git commit -m "Publish chart ${{ steps.version.outputs.version }}"
|
git -C "$PAGES_DIR" commit -m "Publish chart ${{ steps.version.outputs.version }}"
|
||||||
git push origin gh-pages
|
git -C "$PAGES_DIR" push origin gh-pages
|
||||||
cd -
|
|
||||||
|
|
||||||
# Clean up worktree
|
- name: Create GitHub Release
|
||||||
git worktree remove /tmp/gh-pages
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Generate Release Notes
|
|
||||||
id: notes
|
|
||||||
run: |
|
run: |
|
||||||
# Get commits since last tag
|
# Build release notes
|
||||||
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
||||||
if [ -z "$PREV_TAG" ]; then
|
if [ -z "$PREV_TAG" ]; then
|
||||||
COMMITS=$(git log --pretty=format:"- %s (%h)" HEAD)
|
COMMITS=$(git log --pretty=format:"- %s (%h)" HEAD)
|
||||||
else
|
else
|
||||||
COMMITS=$(git log --pretty=format:"- %s (%h)" ${PREV_TAG}..HEAD)
|
COMMITS=$(git log --pretty=format:"- %s (%h)" "${PREV_TAG}..HEAD")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat << EOF > release-notes.md
|
cat > release-notes.md <<EOF
|
||||||
## 🚀 Release ${{ steps.version.outputs.version }}
|
## Release ${{ steps.version.outputs.version }}
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
${COMMITS}
|
${COMMITS}
|
||||||
@@ -187,17 +184,6 @@ jobs:
|
|||||||
\`\`\`
|
\`\`\`
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo "notes<<EOF" >> $GITHUB_OUTPUT
|
gh release create "${{ steps.version.outputs.tag }}" \
|
||||||
cat release-notes.md >> $GITHUB_OUTPUT
|
--title "Release ${{ steps.version.outputs.tag }}" \
|
||||||
echo "EOF" >> $GITHUB_OUTPUT
|
--notes-file release-notes.md
|
||||||
|
|
||||||
- name: Create GitHub Release
|
|
||||||
uses: actions/create-release@v1
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
with:
|
|
||||||
tag_name: ${{ steps.version.outputs.tag }}
|
|
||||||
release_name: Release ${{ steps.version.outputs.tag }}
|
|
||||||
body: ${{ steps.notes.outputs.notes }}
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
|
|||||||
Reference in New Issue
Block a user