name: Rust CI/CD
on:
push:
pull_request:
jobs:
test:
name: Test package
runs-on: ubuntu-latest
steps:
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- uses: actions/checkout@v3
- name: Run tests
run: cargo test --verbose
create-cross-platform-release:
runs-on: ${{ matrix.os }}
needs: [test]
if: github.ref_type == 'tag'
strategy:
matrix:
include:
- os: ubuntu-latest
build: linux-x86_64
target: x86_64-unknown-linux-gnu
binary: clineup
- os: macos-latest
build: macos-x86_64
target: x86_64-apple-darwin
binary: clineup
- os: ubuntu-latest
build: windows-x86_64
target: x86_64-pc-windows-gnu
binary: clineup.exe
steps:
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Checkout
uses: actions/checkout@v3
- name: Install MinGW
if: matrix.target == 'x86_64-pc-windows-gnu'
run: |
sudo apt install -y mingw-w64 pkg-config
- name: Build for ${{ matrix.os }} (Release)
run: |
rustup target add ${{ matrix.target }}
cargo build --release --target=${{ matrix.target }}
- name: Compress artifacts
run: |
mkdir -p release-artifacts
tar czf release-artifacts/clineup-${{ github.ref_name}}-${{ matrix.build }}.tar.gz -C target/${{ matrix.target }}/release/ ${{ matrix.binary }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}
path: release-artifacts/clineup-${{ github.ref_name}}-${{ matrix.build }}.tar.gz
retention-days: 1
create-release:
permissions:
contents: write
discussions: write
runs-on: ubuntu-latest
needs: [create-cross-platform-release]
if: github.ref_type == 'tag'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: release-artifacts
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
release-artifacts/**/*.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}
fail_on_unmatched_files: true
publish-crate:
runs-on: ubuntu-latest
needs: [create-cross-platform-release]
if: github.ref_type == 'tag'
steps:
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Check out code
uses: actions/checkout@v3
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
docker:
runs-on: ubuntu-latest
needs: [create-cross-platform-release]
if: github.ref_type == 'tag'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_SECRET }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push version
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/clineup:${{ github.ref_name}}
- name: Build and push latest
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/clineup:latest