Skip to content

Commit

Permalink
Add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Nov 1, 2024
1 parent 0e53a9b commit ae5935f
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
workflow_dispatch:
push:
paths-ignore: ['**.md']
pull_request:
paths-ignore: ['**.md']

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name == 'main' && github.sha || github.ref }}
cancel-in-progress: true

jobs:
linux:
uses: ./.github/workflows/linux.yml

release:
needs: [linux]
uses: ./.github/workflows/release.yml
permissions:
contents: write
68 changes: 68 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Lint

on:
workflow_call:

env:
CARGO_TERM_COLOR: always

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run rustfmt
run: cargo fmt --all --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore cache
uses: actions/cache/restore@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
fail-on-cache-miss: true
- uses: clechasseur/rs-clippy-check@v3

msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dependencies
run: |
version=v0.16.2
artifact="cargo-msrv-x86_64-unknown-linux-gnu-$version"
curl -LO "https://github.com/foresterre/cargo-msrv/releases/download/$version/$artifact.tgz"
tar -xvf "$artifact.tgz"
mv "${artifact}/cargo-msrv" ./
- name: Detect MSRV changes
run: |
defined_msrv="$(./cargo-msrv show --output-format json 2>&1 | jq -r '.result.version' | tail -n 1)"
dependency_msrv="$(./cargo-msrv list --output-format json 2>&1 | jq -r '.result.list[0].msrv' | tail -n 1)"
echo "defined_msrv=$defined_msrv"
echo "dependency_msrv=$dependency_msrv"
if [ -z "$defined_msrv" ] || [ -z "$dependency_msrv" ]; then
echo "::error::Failed to detect MSRV"
exit 1
fi
if [ "$defined_msrv" != "$dependency_msrv" ]; then
echo "::error::MSRV changed | defined: '$defined_msrv', absolute: '$dependency_msrv'"
exit 1
fi
actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: docker://rhysd/actionlint:latest
with:
args: -color
30 changes: 30 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Linux

on:
workflow_call:

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install dependencies
run: sudo apt -qq install libudev-dev
- name: Build
run: cargo build

lint:
needs: build
uses: ./.github/workflows/lint.yml
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Release

on:
workflow_call:

env:
REPO: dcui
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install dependencies
run: |
sudo apt -qq install libudev-dev libfuse2
sudo curl -Lo /usr/local/bin/appimagetool "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
sudo chmod +x /usr/local/bin/appimagetool
cargo install cargo-appimage
cargo install cargo-deb
- name: Build
run: |
cargo build --release --verbose
cargo appimage
cargo deb
- name: Prepare artifacts
run: |
target=$(rustc --print cfg | grep 'target_arch\|target_os' | sort -r | cut -d'=' -f2 | tr -d '"' | paste -sd '-')
mkdir "$target"
artifact="dcui-$target"
mv "./target/appimage/$REPO.AppImage" "./$target/$artifact.AppImage"
mv ./target/debian/"$REPO"*.deb "./$target/$artifact.deb"
mv "./target/release/$REPO" "./$target/$artifact"
ls "$target"
echo "TARGET=$target" >> "$GITHUB_ENV"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.REPO }}-${{ env.TARGET }}
path: ${{ env.TARGET }}/${{ env.REPO }}*
- name: Prepare release
if: >
github.repository_owner == 'ttytm'
&& ((github.ref_name == 'main' && github.event_name == 'push') || github.ref_type == 'tag')
run: |
if [ "$GITHUB_REF_TYPE" == tag ]; then
{
echo "TAG=$GITHUB_REF_NAME";
echo "TITLE=$REPO ${GITHUB_REF_NAME:1}"; # v1.0.0 -> dcui 1.0.0
} >> "$GITHUB_ENV"
else
{
echo "IS_PRERELEASE=true";
echo "TAG=nightly";
echo "TITLE=nightly build $(date -u +'%Y-%m-%d %H:%M:%S UTC')";
echo "BODY=Generated from commit $GITHUB_SHA.";
} >> "$GITHUB_ENV"
fi
- name: Update nightly tag
if: env.IS_PRERELEASE
uses: richardsimko/update-tag@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: nightly
- name: Release
if: >
github.repository_owner == 'ttytm'
&& ((github.ref_name == 'main' && github.event_name == 'push') || github.ref_type == 'tag')
uses: softprops/action-gh-release@v2
with:
files: ${{ env.TARGET }}/${{ env.REPO }}*
tag_name: ${{ env.TAG }}
body: ${{ env.BODY }}
name: ${{ env.TITLE }}
prerelease: ${{ env.IS_PRERELEASE }}

0 comments on commit ae5935f

Please sign in to comment.