|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: "Tag to release" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: ghcr.io |
| 16 | + IMAGE_NAME: ${{ github.repository }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + shellcheck: |
| 20 | + name: Shell Linting |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Run ShellCheck |
| 27 | + uses: ludeeus/action-shellcheck@master |
| 28 | + with: |
| 29 | + scandir: "." |
| 30 | + format: gcc |
| 31 | + severity: warning |
| 32 | + |
| 33 | + build-and-push: |
| 34 | + name: Build and Push Docker Image |
| 35 | + runs-on: ubuntu-latest |
| 36 | + needs: shellcheck |
| 37 | + permissions: |
| 38 | + contents: read |
| 39 | + packages: write |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Set up QEMU |
| 45 | + uses: docker/setup-qemu-action@v3 |
| 46 | + |
| 47 | + - name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@v3 |
| 49 | + |
| 50 | + - name: Log in to Container Registry |
| 51 | + uses: docker/login-action@v3 |
| 52 | + with: |
| 53 | + registry: ${{ env.REGISTRY }} |
| 54 | + username: ${{ github.actor }} |
| 55 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + |
| 57 | + - name: Extract metadata |
| 58 | + id: meta |
| 59 | + uses: docker/metadata-action@v5 |
| 60 | + with: |
| 61 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 62 | + tags: | |
| 63 | + type=ref,event=tag |
| 64 | + type=raw,value=latest,enable={{is_default_branch}} |
| 65 | +
|
| 66 | + - name: Build and push Docker image |
| 67 | + uses: docker/build-push-action@v5 |
| 68 | + with: |
| 69 | + context: . |
| 70 | + platforms: linux/amd64,linux/arm64 |
| 71 | + push: true |
| 72 | + tags: ${{ steps.meta.outputs.tags }} |
| 73 | + labels: ${{ steps.meta.outputs.labels }} |
| 74 | + cache-from: type=gha |
| 75 | + cache-to: type=gha,mode=max |
| 76 | + |
| 77 | + release: |
| 78 | + name: Create GitHub Release |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: build-and-push |
| 81 | + permissions: |
| 82 | + contents: write |
| 83 | + steps: |
| 84 | + - name: Checkout |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + fetch-depth: 0 |
| 88 | + |
| 89 | + - name: Get version from tag |
| 90 | + id: version |
| 91 | + run: | |
| 92 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 93 | + echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT |
| 94 | + else |
| 95 | + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Update version in claude.sh |
| 99 | + run: | |
| 100 | + VERSION="${{ steps.version.outputs.version }}" |
| 101 | + # Remove 'v' prefix if present |
| 102 | + VERSION=${VERSION#v} |
| 103 | + sed -i "s/^VERSION=.*/VERSION=\"$VERSION\"/" claude.sh |
| 104 | + git config --local user.email "action@github.com" |
| 105 | + git config --local user.name "GitHub Action" |
| 106 | + git add claude.sh |
| 107 | + git commit -m "Update version to $VERSION" || echo "No changes to commit" |
| 108 | +
|
| 109 | + - name: Generate release notes |
| 110 | + id: release_notes |
| 111 | + run: | |
| 112 | + # Get the previous tag |
| 113 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") |
| 114 | +
|
| 115 | + # Generate release notes |
| 116 | + if [ -n "$PREVIOUS_TAG" ]; then |
| 117 | + echo "## Changes since $PREVIOUS_TAG" > release_notes.md |
| 118 | + echo "" >> release_notes.md |
| 119 | + git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> release_notes.md |
| 120 | + else |
| 121 | + echo "## Initial Release" > release_notes.md |
| 122 | + echo "" >> release_notes.md |
| 123 | + echo "First release of Claude Code YOLO - Docker wrapper for Claude CLI with safe YOLO mode." >> release_notes.md |
| 124 | + fi |
| 125 | +
|
| 126 | + echo "" >> release_notes.md |
| 127 | + echo "## Docker Images" >> release_notes.md |
| 128 | + echo "" >> release_notes.md |
| 129 | + echo "- \`ghcr.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}\`" >> release_notes.md |
| 130 | + echo "- \`ghcr.io/${{ env.IMAGE_NAME }}:latest\`" >> release_notes.md |
| 131 | + echo "" >> release_notes.md |
| 132 | + echo "## Supported Architectures" >> release_notes.md |
| 133 | + echo "" >> release_notes.md |
| 134 | + echo "- linux/amd64" >> release_notes.md |
| 135 | + echo "- linux/arm64" >> release_notes.md |
| 136 | +
|
| 137 | + - name: Create Release |
| 138 | + uses: softprops/action-gh-release@v1 |
| 139 | + with: |
| 140 | + tag_name: ${{ steps.version.outputs.version }} |
| 141 | + name: Release ${{ steps.version.outputs.version }} |
| 142 | + body_path: release_notes.md |
| 143 | + generate_release_notes: true |
| 144 | + append_body: true |
| 145 | + env: |
| 146 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments