diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index c2a7031..271b2d2 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -62,3 +62,80 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max platforms: linux/amd64 + + release: + if: startsWith(github.ref, 'refs/tags/v') + needs: build-and-push + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@v4 + + - name: Extract version from tag + id: version + run: | + TAG=${GITHUB_REF#refs/tags/} + VERSION=${TAG#v} + echo "tag=${TAG}" >> $GITHUB_OUTPUT + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "🚀 Creating release for ${TAG}" + + - name: Package and Push Helm Chart + run: | + helm registry login ghcr.io \ + --username ${{ github.actor }} \ + --password ${{ secrets.GITHUB_TOKEN }} + helm package chart/ + helm push devcontainer-${{ steps.version.outputs.version }}.tgz oci://ghcr.io/cpfarhood/charts + + - name: Generate Release Notes + id: notes + run: | + # Get commits since last tag + PREV_TAG=$(git describe --tags --abbrev=0 ${{ steps.version.outputs.tag }}^ 2>/dev/null || echo "") + if [ -z "$PREV_TAG" ]; then + COMMITS=$(git log --pretty=format:"- %s (%h)" ${{ steps.version.outputs.tag }}) + else + COMMITS=$(git log --pretty=format:"- %s (%h)" ${PREV_TAG}..${{ steps.version.outputs.tag }}) + fi + + cat << EOF > release-notes.md + ## 🚀 Release ${{ steps.version.outputs.version }} + + ### Changes + ${COMMITS} + + ### Docker Image + \`\`\`bash + docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }} + \`\`\` + + ### Helm Chart + \`\`\`bash + helm install devcontainer oci://ghcr.io/cpfarhood/charts/devcontainer --version ${{ steps.version.outputs.version }} + \`\`\` + EOF + + echo "notes<> $GITHUB_OUTPUT + cat release-notes.md >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - 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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 5d8e416..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,86 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v*' - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - release: - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - - steps: - - name: Checkout - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Set up Helm - uses: azure/setup-helm@v4 - - - name: Extract version from tag - id: version - run: | - TAG=${GITHUB_REF#refs/tags/} - VERSION=${TAG#v} - echo "tag=${TAG}" >> $GITHUB_OUTPUT - echo "version=${VERSION}" >> $GITHUB_OUTPUT - echo "🚀 Creating release for ${TAG}" - - - name: Package and Push Helm Chart - run: | - helm registry login ghcr.io \ - --username ${{ github.actor }} \ - --password ${{ secrets.GITHUB_TOKEN }} - helm package chart/ - helm push devcontainer-${{ steps.version.outputs.version }}.tgz oci://ghcr.io/cpfarhood/charts - - - name: Generate Release Notes - id: notes - run: | - # Get commits since last tag - PREV_TAG=$(git describe --tags --abbrev=0 ${{ steps.version.outputs.tag }}^ 2>/dev/null || echo "") - if [ -z "$PREV_TAG" ]; then - COMMITS=$(git log --pretty=format:"- %s (%h)" ${{ steps.version.outputs.tag }}) - else - COMMITS=$(git log --pretty=format:"- %s (%h)" ${PREV_TAG}..${{ steps.version.outputs.tag }}) - fi - - cat << EOF > release-notes.md - ## 🚀 Release ${{ steps.version.outputs.version }} - - ### Changes - ${COMMITS} - - ### Docker Image - \`\`\`bash - docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }} - \`\`\` - - ### Helm Chart - \`\`\`bash - helm install devcontainer oci://ghcr.io/cpfarhood/charts/devcontainer --version ${{ steps.version.outputs.version }} - \`\`\` - EOF - - echo "notes<> $GITHUB_OUTPUT - cat release-notes.md >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - 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 \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index 6e4305b..1a706a0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -174,8 +174,7 @@ helm install my-devcontainer ./chart -f custom-values.yaml ### CI/CD -- **`build-and-push.yaml`** — Builds and pushes to GHCR on every push to `main`, version tags (`v*`), and PRs. Tags: `latest` (main), semver, branch name, commit SHA. -- **`release.yaml`** — Creates a GitHub Release with docker pull instructions when a version tag is pushed. +- **`build-and-push.yaml`** — Builds and pushes to GHCR on every push to `main`, version tags (`v*`), and PRs. For version tags, also creates GitHub Release with Helm chart after Docker build completes. Tags: `latest` (main), semver, branch name, commit SHA. - **`dependabot.yml`** — Weekly updates for GitHub Actions and Docker base image. Image registry: `ghcr.io/cpfarhood/devcontainer`