name: Release on: push: tags: - 'v*' workflow_dispatch: inputs: version: description: 'Version tag (e.g., v1.0.0)' required: false type: string env: BINARY_NAME: claudia-docs GO_VERSION: '1.22' jobs: build: runs-on: ubuntu-latest container: image: golang:1.22-alpine strategy: matrix: include: - goos: linux goarch: amd64 ext: '' - goos: linux goarch: arm64 ext: '' - goos: windows goarch: amd64 ext: '.exe' - goos: darwin goarch: amd64 ext: '' - goos: darwin goarch: arm64 ext: '' steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Get version id: version run: | VERSION=${{ github.event.inputs.version || github.ref_name }} echo "version=${VERSION#v}" >> $GITHUB_OUTPUT echo "tag=$VERSION" >> $GITHUB_OUTPUT - name: Build env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} CGO_ENABLED: 0 run: | BINARY="{{ env.BINARY_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}" mkdir -p dist go build -ldflags="\ -w -s \ -X main.version=${{ steps.version.outputs.version }} \ -X main.commit=$(git rev-parse --short HEAD) \ -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ -o "dist/${BINARY}" \ ./cmd/claudia-docs - name: Package run: | cd dist BINARY="{{ env.BINARY_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}" case "${{ matrix.goos }}" in windows) apk add --no-cache zip zip "${BINARY}.zip" "${BINARY}" ;; darwin|linux) tar -czf "${BINARY}.tar.gz" "${BINARY}" ;; esac - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: ${{ matrix.goos }}-${{ matrix.goarch }} path: dist/* retention-days: 5 release: runs-on: ubuntu-latest needs: build if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.version != '' container: image: alpine:3.19 steps: - name: Setup run: apk add --no-cache git curl - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Get version id: version run: | VERSION=${{ github.event.inputs.version || github.ref_name }} echo "version=${VERSION#v}" >> $GITHUB_OUTPUT echo "tag=$VERSION" >> $GITHUB_OUTPUT - name: Download artifacts uses: actions/download-artifact@v4 with: path: dist/ merge-multiple: true - name: Generate changelog id: changelog run: | PREV_TAG=$(git tag --sort=-version:refname | sed -n '2p') if [ -z "$PREV_TAG" ]; then echo "# Changes (full history)" > changelog.md git log --pretty=format:"- %s (%h)" -20 >> changelog.md else echo "# Changes since ${PREV_TAG}" > changelog.md git log "${PREV_TAG}..${{ steps.version.outputs.tag }}" \ --pretty=format="- %s (%h)" >> changelog.md fi cat changelog.md - name: Generate checksums run: | cd dist sha256sum * > checksums.txt cat checksums.txt - name: Generate install script run: | cat > install.sh << 'INSTALL_SCRIPT' #!/bin/bash set -e VERSION="${VERSION:-latest}" BINARY="claudia-docs" # Detect OS OS="$(uname -s | tr '[:upper:]' '[:lower:]')" ARCH="$(uname -m)" # Map architecture case "$ARCH" in x86_64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; esac # Map macOS [ "$OS" = "darwin" ] && OS="darwin" # Download URL="https://gitea.danielarroyo.cl/proyectos/claudia-docs-cli/releases/download/${VERSION}/claudia-docs-${OS}-${ARCH}" echo "Installing Claudia Docs CLI ${VERSION}..." echo "Downloading from: ${URL}" curl -fsSL "${URL}" -o "${BINARY}" || { echo "Error: Failed to download binary" exit 1 } chmod +x "${BINARY}" # Install if [ -w /usr/local/bin ]; then mv "${BINARY}" /usr/local/bin/ echo "Installed to /usr/local/bin/claudia-docs" else echo "Installed to ./claudia-docs (not in PATH)" fi echo "Done!" INSTALL_SCRIPT chmod +x install.sh - name: Create Release uses: https://gitea.com/actions/gitea-release-action@v1 with: token: ${{ secrets.RELEASE_TOKEN }} tag_name: ${{ steps.version.outputs.tag }} name: "Claudia Docs CLI ${{ steps.version.outputs.tag }}" body_path: changelog.md files: | dist/*.tar.gz dist/*.zip dist/checksums.txt install.sh latest: runs-on: ubuntu-latest needs: release if: github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - name: Update latest tag run: | echo "Latest release updated"