diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 74dac2d..d8e192b 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -17,7 +17,6 @@ Use this for all version releases: - ✅ Builds Docker image with all proper tags - ✅ Publishes Helm chart to GitHub Pages (`https://cpfarhood.github.io/devcontainer`) - ✅ Creates GitHub Release with changelog -- ✅ No more `[skip ci]` blocking builds! ### 2️⃣ For Quick Fixes → **Quick Fix Build** 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** Runs automatically on: +- Pushes to `main` (builds and pushes; skipped for release commits via `[skip ci]`) - Pull requests (builds but doesn't push) -- Tags starting with `v*` (builds and pushes) - Manual trigger available ## Workflow Files @@ -90,5 +89,5 @@ gh run watch ### After (Simple! 🎉) - **3 total workflows** (down from 6+) - **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 \ No newline at end of file diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index f5ee2ad..20ac734 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -16,9 +16,6 @@ env: jobs: build-and-push: 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: contents: read packages: write diff --git a/.github/workflows/release-unified.yaml b/.github/workflows/release-unified.yaml index 750135e..0a4552c 100644 --- a/.github/workflows/release-unified.yaml +++ b/.github/workflows/release-unified.yaml @@ -4,11 +4,11 @@ on: workflow_dispatch: inputs: version: - description: 'Version to release (e.g., 0.1.25)' - required: true + description: 'Explicit version (e.g., 1.2.3). Leave blank to auto-increment.' + required: false type: string release_type: - description: 'Release type' + description: 'Release type (used when version is blank)' required: true default: 'patch' type: choice @@ -49,37 +49,34 @@ jobs: - name: Determine Version id: version run: | - if [ "${{ github.event.inputs.version }}" != "" ]; then - VERSION="${{ github.event.inputs.version }}" + INPUT_VERSION="${{ github.event.inputs.version }}" + if [ -n "$INPUT_VERSION" ]; then + VERSION="$INPUT_VERSION" else - # Auto-determine next version based on release type + # Auto-increment based on release_type CURRENT=$(grep '^version:' chart/Chart.yaml | awk '{print $2}') - MAJOR=$(echo $CURRENT | cut -d. -f1) - MINOR=$(echo $CURRENT | cut -d. -f2) - PATCH=$(echo $CURRENT | cut -d. -f3) + # Strip any pre-release suffix (e.g., 2.0.0-dev -> 2.0.0) + CURRENT=$(echo "$CURRENT" | sed 's/-.*//') + 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 - major) - VERSION="$((MAJOR + 1)).0.0" - ;; - minor) - VERSION="${MAJOR}.$((MINOR + 1)).0" - ;; - patch) - VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" - ;; + major) VERSION="$((MAJOR + 1)).0.0" ;; + minor) VERSION="${MAJOR}.$((MINOR + 1)).0" ;; + patch) VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" ;; esac fi echo "version=${VERSION}" >> $GITHUB_OUTPUT echo "tag=v${VERSION}" >> $GITHUB_OUTPUT - echo "🚀 Releasing version ${VERSION}" + echo "Releasing version ${VERSION}" - name: Update Chart Version run: | sed -i "s/^version: .*/version: ${{ steps.version.outputs.version }}/" 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 run: | @@ -107,18 +104,25 @@ jobs: cache-to: type=gha,mode=max platforms: linux/amd64 - - name: Package and Publish Helm Chart to GitHub Pages + - name: Publish Helm Chart to GitHub Pages run: | - # Package the chart helm package chart/ + CHART_TGZ="devcontainer-${{ steps.version.outputs.version }}.tgz" - # Checkout or create gh-pages branch in a temporary directory - git worktree add /tmp/gh-pages gh-pages 2>/dev/null || { - git worktree add --detach /tmp/gh-pages - cd /tmp/gh-pages - git checkout --orphan gh-pages - git rm -rf . 2>/dev/null || true - cat > index.html <<'HTMLEOF' + # Set up gh-pages in a temporary directory + PAGES_DIR=$(mktemp -d) + if git ls-remote --heads origin gh-pages | grep -q gh-pages; then + # gh-pages exists — shallow clone just that branch + git clone --single-branch --branch gh-pages \ + "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" \ + "$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'