Skip to content

Commit

Permalink
Use same CI workflow as kvu project in order to build binaries for …
Browse files Browse the repository at this point in the history
…more platform
  • Loading branch information
jihchi committed Aug 6, 2022
1 parent bb92a1f commit ca1622d
Showing 1 changed file with 123 additions and 169 deletions.
292 changes: 123 additions & 169 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,198 +2,152 @@ name: CI

on:
push:
tags:
- 'v*'
branches:
- 'master'
pull_request:

jobs:
check:
name: Check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
rust: [stable]
steps:
- name: Setup Rust Action
uses: hecrj/setup-rust-action@v1
with:
rust-version: ${{ matrix.rust }}
env:
CARGO_TERM_COLOR: always

- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
defaults:
run:
# necessary for windows
shell: bash

jobs:
test:
name: Test Suite
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
rust: [stable]
runs-on: ubuntu-latest
steps:
- name: Setup Rust Action
uses: hecrj/setup-rust-action@v1
with:
rust-version: ${{ matrix.rust }}

- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
- uses: actions/checkout@v2
- name: Setup Rust toolcnain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo test
uses: actions-rs/cargo@v1
components: clippy
- name: Cargo cache
uses: actions/cache@v2
with:
command: test

lints:
name: Lints
runs-on: ${{ matrix.os }}
path: |
~/.cargo/registry
./target
key: test-cargo-registry
- name: List
run: find ./
- name: Run lint
run: cargo clippy
- name: Run tests
run: cargo test --verbose

build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
rust: [stable]
# a list of all the targets
include:
- TARGET: x86_64-unknown-linux-gnu # tested in a debian container on a mac
OS: ubuntu-latest
- TARGET: x86_64-unknown-linux-musl # test in an alpine container on a mac
OS: ubuntu-latest
- TARGET: aarch64-unknown-linux-gnu # tested on aws t4g.nano
OS: ubuntu-latest
- TARGET: aarch64-unknown-linux-musl # tested on aws t4g.nano in alpine container
OS: ubuntu-latest
- TARGET: armv7-unknown-linux-gnueabihf # raspberry pi 2-3-4, not tested
OS: ubuntu-latest
- TARGET: armv7-unknown-linux-musleabihf # raspberry pi 2-3-4, not tested
OS: ubuntu-latest
- TARGET: arm-unknown-linux-gnueabihf # raspberry pi 0-1, not tested
OS: ubuntu-latest
- TARGET: arm-unknown-linux-musleabihf # raspberry pi 0-1, not tested
OS: ubuntu-latest
- TARGET: x86_64-apple-darwin # tested on a mac, is not properly signed so there are security warnings
OS: macos-latest
- TARGET: aarch64-apple-darwin
OS: macos-latest
- TARGET: x86_64-pc-windows-gnu # tested on a windows machine
OS: windows-latest
needs: test
runs-on: ${{ matrix.OS }}
env:
NAME: dify
TARGET: ${{ matrix.TARGET }}
OS: ${{ matrix.OS }}
steps:
- name: Setup Rust Action
uses: hecrj/setup-rust-action@v1
with:
rust-version: ${{ matrix.rust }}

- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
- uses: actions/checkout@v2
- name: Setup Rust toolcnain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

distribution:
name: Distribution
needs: [check, test, lints]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-16.04, macOS-latest, windows-latest]
include:
- os: ubuntu-16.04
name: dify-Linux-x86_64.tar.gz
- os: macOS-latest
name: dify-Darwin-x86_64.tar.gz
- os: windows-latest
name: dify-Windows-x86_64.zip
steps:
- name: Setup | Checkout code
uses: actions/checkout@v2

- name: Setup | Cache Cargo
- name: Cargo cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Setup | Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Build | Build
if: startsWith(github.ref, 'refs/tags/')
uses: actions-rs/cargo@v1
with:
command: build
args: --release

- name: Package
if: startsWith(github.ref, 'refs/tags/')
shell: bash
./target
key: build-cargo-registry-${{matrix.TARGET}}
- name: List
run: find ./
- name: Install and configure dependencies
run: |
# dependencies are only needed on ubuntu as that's the only place where
# we make cross-compilation
if [[ $OS =~ ^ubuntu.*$ ]]; then
sudo apt-get install -qq crossbuild-essential-arm64 crossbuild-essential-armhf
fi
# some additional configuration for cross-compilation on linux
cat >>~/.cargo/config <<EOF
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.arm-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
EOF
- name: Install rust target
run: rustup target add $TARGET
- name: Run build
run: cargo build --release --verbose --target $TARGET
- name: List target
run: find ./target
- name: Compress
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]
then
strip target/release/dify.exe
cd target/release
7z a ../../${{ matrix.name }} dify.exe
mkdir -p ./artifacts
# windows is the only OS using a different convention for executable file name
if [[ $OS =~ ^windows.*$ ]]; then
EXEC=$NAME.exe
else
strip target/release/dify
cd target/release
tar czvf ../../${{ matrix.name }} dify
EXEC=$NAME
fi
cd -
- name: Publish
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
if [[ $GITHUB_REF_TYPE =~ ^tag$ ]]; then
TAG=$GITHUB_REF_NAME
else
TAG=$GITHUB_SHA
fi
mv ./target/$TARGET/release/$EXEC ./$EXEC
tar -czf ./artifacts/$NAME-$TARGET-$TAG.tar.gz $EXEC
- name: Archive artifact
uses: actions/upload-artifact@v2
with:
draft: false
files: 'dify*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-and-push-image:
name: Push Docker image to Github registry (ghcr.io)
runs-on: ubuntu-latest
needs: [check, test, lints]
name: result
path: |
./artifacts
# deploys to github releases on tag
deploy:
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: read
packages: write
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ghcr.io/${{ github.repository }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: result
path: ./artifacts
- name: List
run: find ./artifacts
- name: Release
uses: softprops/action-gh-release@v1
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
files: ./artifacts/*.tar.gz

0 comments on commit ca1622d

Please sign in to comment.