Add GitHub pages release #25
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
| # Release workflow for celq binaries | ||
|
Check failure on line 1 in .github/workflows/release_github.yml
|
||
| # Credit: Inspired by https://github.com/01mf02/jaq/blob/main/.github/workflows/release.yml | ||
| # Also see: https://github.com/BurntSushi/ripgrep/blob/61733f6378b62fa2dc2e7f3eff2f2e7182069ca9/.github/workflows/release.yml | ||
| name: GitHub Release | ||
| on: | ||
| workflow_dispatch: # Manual trigger only | ||
| push: | ||
| tags: | ||
| - "v[0-9]*" # Trigger on version tags like v1.0.0 | ||
| defaults: | ||
| run: | ||
| shell: bash | ||
| env: | ||
| NAME: celq | ||
| VERSION: ${{ github.ref_name }} | ||
| # Required for gh release upload | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| build: | ||
| name: ${{ matrix.target }} | ||
| runs-on: ${{ matrix.os }} | ||
| environment: github_release | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| # macOS ARM64 (native) | ||
| - { target: aarch64-apple-darwin, os: macos-15 } | ||
| # Windows x86-64 (native) | ||
| - { target: x86_64-pc-windows-msvc, os: windows-2025 } | ||
| # Linux x86-64 (native - glibc) | ||
| - { target: x86_64-unknown-linux-gnu, os: ubuntu-24.04 } | ||
| # Linux x86-64 (native - musl static binary) | ||
| - { target: x86_64-unknown-linux-musl, os: ubuntu-24.04 } | ||
| # Linux ARM64 (native) | ||
| - { target: aarch64-unknown-linux-gnu, os: ubuntu-24.04-arm } | ||
| # Linux ARM64 (native - musl static binary) | ||
| - { target: aarch64-unknown-linux-musl, os: ubuntu-24.04-arm } | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| targets: ${{ matrix.target }} | ||
| - name: Install musl tools (for musl targets) | ||
| if: contains(matrix.target, 'musl') | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y musl-tools | ||
| - name: Build | ||
| run: cargo build --locked --release --target ${{ matrix.target }} | ||
| - name: Create release archive | ||
| id: archive | ||
| run: | | ||
| EXE_suffix="" | ||
| case ${{ matrix.target }} in | ||
| *-pc-windows-*) EXE_suffix=".exe" ;; | ||
| esac | ||
| BIN_PATH="target/${{ matrix.target }}/release/${NAME}${EXE_suffix}" | ||
| BIN_NAME="${NAME}${EXE_suffix}" | ||
| # Determine archive format based on platform | ||
| case ${{ matrix.target }} in | ||
| *-pc-windows-*) | ||
| # Windows: create .zip archive | ||
| ARCHIVE_NAME="${NAME}-${{ matrix.target }}.zip" | ||
| 7z a "${ARCHIVE_NAME}" "${BIN_PATH}" | ||
| ;; | ||
| *) | ||
| # Linux/macOS: create .tar.gz archive | ||
| ARCHIVE_NAME="${NAME}-${{ matrix.target }}.tar.gz" | ||
| tar czf "${ARCHIVE_NAME}" -C "target/${{ matrix.target }}/release" "${BIN_NAME}" | ||
| ;; | ||
| esac | ||
| echo "ARCHIVE_NAME=${ARCHIVE_NAME}" >> $GITHUB_OUTPUT | ||
| - name: Upload release archive | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: gh release upload ${VERSION} ${{ steps.archive.outputs.ARCHIVE_NAME }} | ||
| update-install-script: | ||
| name: Update install script on GitHub Pages | ||
| runs-on: ubuntu-latest | ||
| needs: build | ||
| environment: github_release | ||
| steps: | ||
| - name: Checkout celq repository (for template) | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| path: celq-repo | ||
| - name: Checkout get-celq.github.io repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: get-celq/get-celq.github.io | ||
| token: ${{ secrets.PAGES_DEPLOY_TOKEN }} | ||
| path: pages-repo | ||
| - name: Generate install scripts | ||
| run: | | ||
| VERSION="${{ github.ref_name }}" | ||
| # Generate versioned install script (e.g., v0.1.1/install.sh or v0.2.0-beta.1/install.sh) | ||
| mkdir -p "pages-repo/${VERSION}" | ||
| sed "s/{{CELQ_VERSION}}/${VERSION}/g" celq-repo/template_install.sh > "pages-repo/${VERSION}/install.sh" | ||
| chmod +x "pages-repo/${VERSION}/install.sh" | ||
| # Only update root install.sh if this is NOT a pre-release | ||
| # Pre-releases have a hyphen (e.g., v0.2.0-beta.1, v1.0.0-rc.1) | ||
| if [[ ! "$VERSION" =~ -[a-zA-Z] ]]; then | ||
| echo "Stable release detected, updating root install.sh" | ||
| sed "s/{{CELQ_VERSION}}/${VERSION}/g" celq-repo/template_install.sh > pages-repo/install.sh | ||
| chmod +x pages-repo/install.sh | ||
| else | ||
| echo "Pre-release detected, skipping root install.sh update" | ||
| fi | ||
| # Copy generated script for GitHub release attachment | ||
| cp "pages-repo/${VERSION}/install.sh" celq-repo/install.sh | ||
| - name: Upload install.sh to GitHub release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| cd celq-repo | ||
| gh release upload ${{ github.ref_name }} install.sh --clobber | ||
| - name: Commit and push changes to Pages repo | ||
| run: | | ||
| cd pages-repo | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| VERSION="${{ github.ref_name }}" | ||
| # Add versioned install script | ||
| git add "${VERSION}/install.sh" | ||
| # Only add root install.sh if it was updated (stable release) | ||
| if [[ ! "$VERSION" =~ -[a-zA-Z] ]]; then | ||
| git add install.sh | ||
| git commit -m "Update install script to $VERSION (stable release)" || echo "No changes to commit" | ||
| else | ||
| git commit -m "Add install script for $VERSION (pre-release)" || echo "No changes to commit" | ||
| fi | ||
| git push | ||