xremap/.github/workflows/build.yml
2022-08-22 19:10:02 -07:00

115 lines
3.6 KiB
YAML

name: cargo
on:
push:
branches:
- master
tags:
- v*
pull_request:
types:
- opened
- synchronize
- reopened
schedule:
- cron: '00 15 * * *' # 7:00 PST (-8), 8:00 PDT (-7)
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [x86_64, aarch64]
feature: [x11, gnome, sway]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
target: ${{ matrix.arch }}-unknown-linux-musl
- uses: Swatinem/rust-cache@v1
with:
key: ubuntu-latest-${{ matrix.arch }}-${{ matrix.feature }}
- run: cargo install cross
- name: cross build
run: cross build --release --features ${{ matrix.feature }} --target=${{ matrix.arch }}-unknown-linux-musl
- name: package
run: zip "xremap-linux-${{ matrix.arch }}-${{ matrix.feature }}.zip" xremap
working-directory: target/${{ matrix.arch }}-unknown-linux-musl/release
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: xremap-${{ matrix.arch }}-${{ matrix.feature }}
path: target/${{ matrix.arch }}-unknown-linux-musl/release/xremap-linux-${{ matrix.arch }}-${{ matrix.feature }}.zip
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: cargo fmt
run: cargo fmt -- --check
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
with:
key: ubuntu-latest
- run: cargo test
publish:
runs-on: ubuntu-latest
needs:
- build
- test
if: ${{ startsWith(github.ref, 'refs/tags/') }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
with:
key: ubuntu-latest
# Release crate
- name: cargo login
run: cargo login "$CARGO_TOKEN"
env:
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
- run: cargo publish
# Release binary
- { uses: actions/download-artifact@v3, with: { name: xremap-x86_64-x11, path: package/ } }
- { uses: actions/download-artifact@v3, with: { name: xremap-x86_64-gnome, path: package/ } }
- { uses: actions/download-artifact@v3, with: { name: xremap-x86_64-sway, path: package/ } }
- { uses: actions/download-artifact@v3, with: { name: xremap-aarch64-x11, path: package/ } }
- { uses: actions/download-artifact@v3, with: { name: xremap-aarch64-gnome, path: package/ } }
- { uses: actions/download-artifact@v3, with: { name: xremap-aarch64-sway, path: package/ } }
- name: Release
run: |
export VERSION=$(echo "$GITHUB_REF" | sed -e 's!refs/tags/!!')
curl -L "https://github.com/tcnksm/ghr/releases/download/${GHR_VERSION}/ghr_${GHR_VERSION}_linux_amd64.tar.gz" | tar xvz
"ghr_${GHR_VERSION}_linux_amd64/ghr" -u k0kubun -r xremap -replace -n "$VERSION" "$VERSION" package/
env:
GHR_VERSION: v0.14.0
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}