Skip to content

Commit

Permalink
Add linux packaging to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Jul 28, 2023
1 parent 37ed62d commit 36b1f73
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
49 changes: 40 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ jobs:
- target: macos
os: macos-latest
make: bash scripts/build-macos.sh
binary_path: target/release/macos/halloy.dmg
artifact_path: |
echo "ARTIFACT_PATH=target/release/macos/halloy.dmg" >> "$GITHUB_ENV"
- target: windows
os: windows-latest
make: bash scripts/build-windows.sh
binary_path: target/release/halloy.exe
artifact_path: |
Add-Content -Path ${env:GITHUB_ENV} -Value "ARTIFACT_PATH=target/release/halloy.exe"
- target: linux
os: ubuntu-latest
make: bash scripts/package-linux.sh package
artifact_path: |
echo "ARTIFACT_PATH=$(bash scripts/package-linux.sh archive_path)" >> "$GITHUB_ENV"
runs-on: ${{ matrix.target.os }}

steps:
Expand All @@ -31,14 +38,29 @@ jobs:
toolchain: stable
override: true

- name: Install linux deps
if: matrix.target.target == 'linux'
run: |
sudo apt install \
build-essential \
git \
pkg-config \
libdbus-1-dev \
libudev-dev \
libxkbcommon-dev \
libfontconfig1-dev
- name: Build
run: ${{ matrix.target.make }}

- name: Set artifact path
run: ${{ matrix.target.artifact_path }}

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.target.target }}
path: ${{ matrix.target.binary_path }}
path: ${{ env.ARTIFACT_PATH }}

create-release:
needs: build
Expand Down Expand Up @@ -67,29 +89,38 @@ jobs:
matrix:
target:
- artifact: macos
artifact_name: halloy.dmg
asset_name: halloy.dmg
artifact_name: |
echo "ARTIFACT_NAME=halloy.dmg" >> "$GITHUB_ENV"
asset_type: application/octet-stream
- artifact: windows
artifact_name: halloy.exe
asset_name: halloy.exe
artifact_name: |
Add-Content -Path ${env:GITHUB_ENV} -Value "ARTIFACT_NAME=halloy.exe"
asset_type: application/x-dosexec
- artifact: linux
artifact_name: |
echo "ARTIFACT_NAME=$(bash scripts/package-linux.sh archive_name)" >> "$GITHUB_ENV"
asset_type: application/gzip

runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ matrix.target.artifact }}
path: ${{ matrix.target.artifact }}

- name: Set artifact name
run: ${{ matrix.target.artifact_name }}

- name: Upload asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./${{ matrix.target.artifact }}/${{ matrix.target.artifact_name }}
asset_name: ${{ matrix.target.asset_name }}
asset_path: ./${{ matrix.target.artifact }}/${{ env.ARTIFACT_NAME }}
asset_name: ${{ env.ARTIFACT_NAME }}
asset_content_type: ${{ matrix.target.asset_type }}
43 changes: 43 additions & 0 deletions scripts/package-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

ARCH="x86_64"
TARGET="halloy"
VERSION=$(cat VERSION)
PROFILE="release"
ASSETS_DIR="assets/linux"
RELEASE_DIR="target/$PROFILE"
BINARY="$RELEASE_DIR/$TARGET"
ARCHIVE_DIR="$RELEASE_DIR/archive"
ARCHIVE_NAME="$TARGET-$VERSION-$ARCH-linux.tar.gz"
ARCHIVE_PATH="$RELEASE_DIR/$ARCHIVE_NAME"

build() {
cargo build --profile $PROFILE
}

archive_name() {
echo $ARCHIVE_NAME
}

archive_path() {
echo $ARCHIVE_PATH
}

package() {
build

install -D $ASSETS_DIR/* -t $ARCHIVE_DIR
install -Dm755 $BINARY $ARCHIVE_DIR
tar czvf $ARCHIVE_PATH -C $ARCHIVE_DIR .

echo "Packaged archive: $ARCHIVE_PATH"
}

case "$1" in
"package") package;;
"archive_name") archive_name;;
"archive_path") archive_path;;
*)
echo "avaiable commands: package, archive_name, archive_path"
;;
esac

0 comments on commit 36b1f73

Please sign in to comment.