diff --git a/.github/workflows/release-deb.yml b/.github/workflows/release-deb.yml index 99c8d3577..88dc20c48 100644 --- a/.github/workflows/release-deb.yml +++ b/.github/workflows/release-deb.yml @@ -1,74 +1,146 @@ -name: Build and Release Zig Project - on: + workflow_dispatch: + inputs: + version: + description: 'Version to deploy (format: vX.Y.Z)' + required: true + upload: + description: 'Upload final artifacts to R2' + default: false push: tags: - - 'v*' + - 'v[0-9]+.[0-9]+.[0-9]+' + +name: Release Tag + jobs: - build: + setup: runs-on: ubuntu-latest - + outputs: + version: ${{ steps.extract_version.outputs.version }} + build: ${{ steps.extract_build_info.outputs.build }} + commit: ${{ steps.extract_build_info.outputs.commit }} + commit_long: ${{ steps.extract_build_info.outputs.commit_long }} steps: - # Checkout the repository - - name: Checkout Code - uses: actions/checkout@v3 + - name: Validate Version Input + if: github.event_name == 'workflow_dispatch' + run: | + if [[ ! "${{ github.event.inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Version must follow the format vX.Y.Z (e.g., v1.0.0)." + exit 1 + fi - # Install dependencies + echo "Version is valid: ${{ github.event.inputs.version }}" + + - name: Exract the Version + id: extract_version + run: | + if [[ "${{ github.event_name }}" == "push" ]]; then + # Remove the leading 'v' from the tag + VERSION=${GITHUB_REF#refs/tags/v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + VERSION=${{ github.event.inputs.version }} + VERSION=${VERSION#v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + else + echo "Error: Unsupported event type." + exit 1 + fi + + - name: Checkout code + uses: actions/checkout@v4 + with: + # Important so that build number generation works + fetch-depth: 0 - name: Install Dependencies run: | sudo apt update - sudo apt install -y build-essential libbz2-dev libfreetype6-dev zlib1g-dev libpng-dev libgtk-4-dev libadwaita-1-dev git libglib2.0-dev pkg-config snapd + sudo apt install -y build-essential libbz2-dev libfreetype6-dev zlib1g-dev libpng-dev libgtk-4-dev libadwaita-1-dev git libglib2.0-dev pkg-config sudo snap install --beta zig --classic - # Run the build script to create the .deb package - - name: Print GitHub Tag + - name: Fetch Zig Dependencies run: | - echo "GitHub Ref: $GITHUB_REF" - echo "Tag: ${GITHUB_REF##*/}" + echo "Setting up Zig cache directory..." + CACHE_DIR="/tmp/offline-cache" + mkdir -p "$CACHE_DIR" - - name: Build .deb Package - env: - ZIG_GLOBAL_CACHE_DIR: /tmp/offline-cache - VERSION: ${{ github.event.inputs.version }} + echo "Fetching Zig dependencies..." + export ZIG_GLOBAL_CACHE_DIR="$CACHE_DIR" + ./nix/build-support/fetch-zig-cache.sh + - name: Build Application run: | - chmod +x ./deb/build.sh - ./deb/build.sh + echo "Building..." + CACHE_DIR="/tmp/offline-cache" + zig build --prefix /usr --system "$CACHE_DIR/p" -Doptimize=ReleaseFast -Dcpu=baseline -Dversion-string=${VERSION} + if [ $? -ne 0 ]; then + echo "Build failed!" + exit 1 + fi - # Upload the generated .deb file as an artifact - - name: Upload .deb Package - uses: actions/upload-artifact@v3 + - name: Build DEB Package + run: | + BUILD_DIR="$(pwd)/build" + DEB_DIR="$BUILD_DIR/${APP_NAME}_${VERSION}_${ARCH}" + DESTDIR="$DEB_DIR/usr" + BIN_DIR="$DESTDIR/bin" + DESKTOP_DIR="$DEB_DIR/usr/share/applications" + + # Clean up old build directories + rm -rf "$BUILD_DIR" + + # Step 1: Create directory structure + mkdir -p "$DEB_DIR" + mkdir -p "$BIN_DIR" + mkdir -p "$DESKTOP_DIR" + + # Step 2: Add application binaries + cp /usr/bin/${APP_NAME} "$BIN_DIR/${APP_NAME}" + + # Step 3: Add and rename desktop file + cp ./dist/linux/app.desktop "$DESKTOP_DIR/ghostty.desktop" + + # Step 4: Create DEBIAN control file + mkdir -p "$DEB_DIR/DEBIAN" + cat < "$DEB_DIR/DEBIAN/control" + Package: $APP_NAME + Version: $VERSION + Architecture: $ARCH + Maintainer: Ronit Gandhi + Description: A fast, feature-rich, and cross-platform terminal emulator that uses platform-native UI and GPU acceleration. + EOF + + # Step 5: Build .deb package + dpkg-deb --build "$DEB_DIR" + + - name: Upload DEB Artifact + uses: actions/upload-artifact@v4 with: - name: ghostty-deb-package - path: build/*.deb + name: deb-package + path: | + $BUILD_DIR/${APP_NAME}_${VERSION}_${ARCH}.deb - release: - needs: build + create-release: + needs: setup runs-on: ubuntu-latest - steps: - # Checkout the repository - - name: Checkout Code - uses: actions/checkout@v3 + - name: Download DEB Artifact + uses: actions/download-artifact@v4 + with: + name: deb-package + path: ./artifacts - # Create a Release - - name: Create Release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create GitHub Release + uses: actions/create-release@v3 with: tag_name: ${{ github.ref_name }} release_name: Release ${{ github.ref_name }} + body: | + Automated release of ${{ github.ref_name }}. draft: false prerelease: false - - # Upload the .deb file to the Release - - name: Upload .deb to Release - uses: actions/upload-release-asset@v1 + generate_release_notes: true + assets: ./artifacts/*.deb env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: build/*.deb - asset_name: ghostty_${{ github.ref_name }}.deb - asset_content_type: application/vnd.debian.binary-package diff --git a/deb/build.sh b/deb/build.sh deleted file mode 100644 index 0632a230f..000000000 --- a/deb/build.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash - -# Set variables -APP_NAME="ghostty" -VERSION="v1.0.0" # TODO: Have to set this to take from github-action -echo "Using version: $VERSION" -ARCH="amd64" -BUILD_DIR="$(pwd)/build" -DEB_DIR="$BUILD_DIR/${APP_NAME}_${VERSION}_${ARCH}" -CACHE_DIR="/tmp/offline-cache" -DESTDIR="$DEB_DIR/usr" -BIN_DIR="$DESTDIR/bin" -DESKTOP_DIR="$DEB_DIR/usr/share/applications" - -# Clean up old build directories -rm -rf "$BUILD_DIR" - -# Step 1: Create directory structure -mkdir -p "$DEB_DIR/DEBIAN" -mkdir -p "$BIN_DIR" -mkdir -p "$DESKTOP_DIR" - -# Step 2: Fetch dependencies (requires internet access) -echo "Setting up Zig cache directory..." -mkdir -p "$CACHE_DIR" - -echo "Fetching Zig dependencies..." -export ZIG_GLOBAL_CACHE_DIR="$CACHE_DIR" -./nix/build-support/fetch-zig-cache.sh - -# Step 3: Build the application -echo "Building $APP_NAME..." -zig build --prefix /usr --system "$CACHE_DIR/p" -Doptimize=ReleaseFast -Dcpu=baseline -if [ $? -ne 0 ]; then - echo "Build failed!" - exit 1 -fi - -# Step 4: Verify that the binary was built successfully -if [ -f "/usr/bin/$APP_NAME" ]; then - # Copy the binary to the destination directory - cp "/usr/bin/$APP_NAME" "$BIN_DIR/" -else - echo "Error: Binary not found at /usr/bin/$APP_NAME" - exit 1 -fi - -# Step 5: Create DEBIAN/control file -echo "Creating control file..." -CONTROL_FILE="$DEB_DIR/DEBIAN/control" -cat < "$CONTROL_FILE" -Package: $APP_NAME -Version: $VERSION -Section: utils -Priority: optional -Architecture: $ARCH -Maintainer: Ronit Gandhi -Description: Ghostty - A fast, feature-rich, and cross-platform terminal emulator that uses platform-native UI and GPU acceleration. -EOF - -# Step 6: Create .desktop file for application menu/search -echo "Creating .desktop file..." -DESKTOP_FILE="$DESKTOP_DIR/$APP_NAME.desktop" -cat < "$DESKTOP_FILE" -[Desktop Entry] -Version=1.0 -Name=Ghostty -Comment=A fast, feature-rich, and cross-platform terminal emulator that uses platform-native UI and GPU acceleration. -Exec=$APP_NAME -Icon=$APP_NAME -Terminal=true -Type=Application -Categories=Utility;System; -EOF - -# Step 7: Set permissions -echo "Setting permissions..." -chmod -R 755 "$DEB_DIR" -chmod 644 "$CONTROL_FILE" -chmod 644 "$DESKTOP_FILE" -chmod +x "$BIN_DIR/$APP_NAME" # Ensure the binary is executable - -# Step 8: Build .deb package -echo "Building .deb package..." -dpkg-deb --build "$DEB_DIR" -if [ $? -eq 0 ]; then - echo "$APP_NAME version $VERSION .deb package created successfully!" - echo "File: $BUILD_DIR/${APP_NAME}_${VERSION}_${ARCH}.deb" -else - echo "Failed to build .deb package!" - exit 1 -fi