CD #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
on: | |
push: | |
branches: | |
- main | |
workflow_run: | |
workflows: ["CI"] | |
types: | |
- completed | |
jobs: | |
cross-build: | |
strategy: | |
matrix: | |
include: | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
- target: aarch64-unknown-linux-musl | |
os: ubuntu-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
target: ${{ matrix.target }} | |
toolchain: stable | |
override: true | |
- name: Cache Cross | |
id: cache-cross | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/bin/cross | |
key: ${{ runner.os }}-cross | |
- name: Check if Cross is installed | |
if: steps.cache-cross.outputs.cache-hit == 'true' | |
id: cross-check | |
run: | | |
if command -v cross &> /dev/null | |
then | |
echo "::set-output name=installed::true" | |
else | |
echo "::set-output name=installed::false" | |
fi | |
- name: Install Cross | |
if: steps.cross-check.outputs.installed != 'true' | |
uses: actions-rs/cargo@v1 | |
with: | |
command: install | |
args: cross | |
- name: Cache Cargo registry | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/registry | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache Cargo index | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/git | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache Cargo build | |
uses: actions/cache@v2 | |
with: | |
path: target | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} | |
- name: Cross Build | |
run: | | |
cross build --target ${{ matrix.target }} --release | |
- name: Archive | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ matrix.target }} | |
path: target/${{ matrix.target }}/release/* | |
native-build: | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
- target: x86_64-unknown-linux-musl | |
os: ubuntu-latest | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
target: ${{ matrix.target }} | |
toolchain: stable | |
override: true | |
- name: Cache Cargo registry | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/registry | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache Cargo index | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cargo/git | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} | |
- name: Cache Cargo build | |
uses: actions/cache@v2 | |
with: | |
path: target | |
key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} | |
- name: Install MUSL tools | |
if: matrix.target == 'aarch64-unknown-linux-musl' | |
run: sudo apt-get install -y musl-tools | |
- name: Build | |
run: | | |
cargo build --release --target = ${{ matrix.target }} | |
- name: Archive | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ${{ matrix.target }} | |
path: target/${{ matrix.target }}/release/* | |
release: | |
needs: [cross-build, native-build] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v2 | |
- name: Install tar | |
run: sudo apt-get install tar | |
- name: Package Artifacts | |
run: | | |
for target in aarch64-apple-darwin x86_64-apple-darwin aarch64-unknown-linux-musl x86_64-unknown-linux-musl; do | |
tar czvf $target.tgz $target | |
done | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./*.tgz | |
asset_name: release.tgz | |
asset_content_type: application/gzip | |