feat: merge workflows #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: | |
| - main | |
| - master | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push-docker: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| outputs: | |
| image-published: ${{ steps.push.outputs.published }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} | |
| - name: Build and push Docker image | |
| id: push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Set output | |
| id: output | |
| run: echo "published=${{ github.event_name != 'pull_request' }}" >> $GITHUB_OUTPUT | |
| build-debian-packages: | |
| needs: build-and-push-docker | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set package version | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/v* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| else | |
| VERSION="1.0.0-dev+$(git rev-parse --short HEAD)" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Package version: $VERSION" | |
| - name: Update version in control file | |
| run: | | |
| sed -i "s/^Version:.*/Version: ${{ steps.version.outputs.version }}/" debian/DEBIAN/control | |
| - name: Wait for image to be available | |
| run: | | |
| echo "Waiting for Docker image to be available..." | |
| sleep 10 | |
| for i in {1..30}; do | |
| if docker pull ghcr.io/${{ github.repository }}:latest; then | |
| echo "Image is available!" | |
| break | |
| fi | |
| echo "Attempt $i: Image not yet available, waiting..." | |
| sleep 10 | |
| done | |
| - name: Build Debian package (without image) | |
| run: make build | |
| - name: Rename package (without image) | |
| run: | | |
| mv swarm-cli_*.deb swarm-cli_${{ steps.version.outputs.version }}_all.deb | |
| - name: Build Debian package (with bundled image) | |
| run: make build-with-image | |
| - name: Rename package (with image) | |
| run: | | |
| mv swarm-cli_*.deb swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb | |
| - name: Upload Debian packages as artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: swarm-cli-deb-packages-${{ steps.version.outputs.version }} | |
| path: "*.deb" | |
| retention-days: 90 | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| cat > release_notes.md << 'EOF' | |
| ## Swarm CLI Release ${{ steps.version.outputs.version }} | |
| ### Docker Image | |
| ```bash | |
| docker pull ghcr.io/${{ github.repository }}:latest | |
| docker pull ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version }} | |
| ``` | |
| ### Installation Options | |
| **Option 1: Lightweight package (recommended)** | |
| - Download: `swarm-cli_${{ steps.version.outputs.version }}_all.deb` | |
| - Size: ~10KB | |
| - Requires internet connection to pull Docker image on first use | |
| **Option 2: Self-contained package** | |
| - Download: `swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb` | |
| - Size: ~50-100MB | |
| - Includes bundled Docker image, no internet required | |
| - Perfect for offline/air-gapped environments | |
| ### Install | |
| ```bash | |
| # Download your preferred package (lightweight) | |
| wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/swarm-cli_${{ steps.version.outputs.version }}_all.deb | |
| # Or download self-contained package | |
| wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb | |
| # Install | |
| sudo apt install ./swarm-cli_${{ steps.version.outputs.version }}_all.deb | |
| ``` | |
| ### Usage | |
| ```bash | |
| swarm-cli --help | |
| swarm-cli status | |
| swarm-cli upload myfile.txt | |
| ``` | |
| ### What's Changed | |
| - Docker image: `ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version }}` | |
| - Built from commit: ${{ github.sha }} | |
| EOF | |
| - name: Create or Update Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| swarm-cli_${{ steps.version.outputs.version }}_all.deb | |
| swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| make_latest: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Development Release | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: dev-latest | |
| name: Development Build (Latest) | |
| files: | | |
| swarm-cli_${{ steps.version.outputs.version }}_all.deb | |
| swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: true | |
| make_latest: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |