Skip to content

Commit

Permalink
Update Github Actions workflows
Browse files Browse the repository at this point in the history
* Update all Actions dependencies
* Use Rust triple instead of LLVM triple
* Remove unnecessary explicit installation of clippy
* Switch to zstd compression for Linux tarballs

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Apr 14, 2024
1 parent 6e00ad4 commit 7f2682d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 52 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,41 @@ jobs:
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -C strip=symbols
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
os:
- windows-latest
- ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Get Rust LLVM target triple
- name: Get Rust target triple
id: get_target
shell: bash
run: |
echo -n 'name=' >> "${GITHUB_OUTPUT}"
RUSTC_BOOTSTRAP=1 rustc -Z unstable-options --print target-spec-json \
| jq -r '."llvm-target"' \
>> "${GITHUB_OUTPUT}"
rustc -vV | sed -n 's|host: ||p' >> "${GITHUB_OUTPUT}"
- name: Install build dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt install -y libdbus-1-dev

- name: Install clippy
run: rustup component add clippy

- name: Run clippy checks in debug mode
env:
RUST_BACKTRACE: 1
run: |
cargo clippy --workspace -- -D warnings
- name: Build in debug mode
run: cargo build --verbose
run: cargo build

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: svrbsctl-${{ steps.get_target.outputs.name }}
path: |
Expand Down
65 changes: 24 additions & 41 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ on:
push:
# Uncomment to test against a branch
#branches:
# - ci
# - ci
tags:
- 'v*'
jobs:
create_release:
name: Create GitHub release
get_version:
name: Get version
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Get version from tag
Expand All @@ -24,85 +23,69 @@ jobs:
fi
echo "version=${version}" >> "${GITHUB_OUTPUT}"
- name: Create release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: Version ${{ steps.get_version.outputs.version }}
draft: false
prerelease: false

build_and_upload:
name: Build and upload assets
needs: create_release
needs: get_version
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -C strip=symbols
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
os:
- windows-latest
- ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Get Rust LLVM target triple
- name: Get Rust target triple
id: get_target
shell: bash
run: |
echo -n 'name=' >> "${GITHUB_OUTPUT}"
RUSTC_BOOTSTRAP=1 rustc -Z unstable-options --print target-spec-json \
| jq -r '."llvm-target"' \
>> "${GITHUB_OUTPUT}"
rustc -vV | sed -n 's|host: ||p' >> "${GITHUB_OUTPUT}"
- name: Install build dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt install -y libdbus-1-dev

- name: Install clippy
run: rustup component add clippy

- name: Run clippy checks in release mode
env:
RUST_BACKTRACE: 1
run: |
cargo clippy --workspace --release -- -D warnings
- name: Build in release mode
run: cargo build --release --verbose

- name: Strip release binary (non-Windows)
if: matrix.os == 'ubuntu-latest'
run: strip target/release/svrbsctl
run: cargo build --release

- name: Build archive
id: build_archive
shell: bash
run: |
base_name=svrbsctl-${{ needs.create_release.outputs.version }}-${{ steps.get_target.outputs.name }}
base_name=svrbsctl-${{ needs.get_version.outputs.version }}-${{ steps.get_target.outputs.name }}
mkdir "${base_name}"
cp {README.md,LICENSE} "${base_name}/"
if [[ "${{ matrix.os }}" == windows-* ]]; then
cp target/release/svrbsctl.exe "${base_name}/"
7z a "${base_name}.zip" "${base_name}"
echo "ASSET=${base_name}.zip" >> "${GITHUB_ENV}"
echo "name=${base_name}.zip" >> "${GITHUB_OUTPUT}"
else
cp target/release/svrbsctl "${base_name}/"
tar -Jcvf "${base_name}.tar.xz" "${base_name}"
echo "ASSET=${base_name}.tar.xz" >> "${GITHUB_ENV}"
tar -I zstd -cvf "${base_name}.tar.zst" "${base_name}"
echo "name=${base_name}.tar.zst" >> "${GITHUB_OUTPUT}"
fi
- name: Upload release assets
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v2
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_name: ${{ env.ASSET }}
asset_path: ${{ env.ASSET }}
asset_content_type: application/octet-stream
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: v${{ needs.get_version.outputs.version }}
name: Version ${{ needs.get_version.outputs.version }}
draft: true
prerelease: false
files: ${{ steps.build_archive.outputs.name }}

0 comments on commit 7f2682d

Please sign in to comment.