Skip to content

CI/CD

CI/CD #38

Workflow file for this run

name: CI/CD
on:
push:
branches:
- main
paths:
- '**.rs'
- '**/Cargo.toml'
- '**/Cargo.lock'
pull_request:
branches:
- main
paths:
- '**.rs'
- '**/Cargo.toml'
- '**/Cargo.lock'
workflow_dispatch:
jobs:
lint-and-format:
name: Lint with clippy and check formatting
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy, rustfmt
override: true
- name: Check formatting
run: cargo fmt -- --check
- name: Clippy check
run: cargo clippy -p smithe_backend -p smithe_database -p smithe_lib -p startgg -- -D warnings
build:
needs: lint-and-format
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- if: matrix.os == 'windows-latest'
name: Install PostgreSQL
uses: ikalnytskyi/action-setup-postgres@v4
- if: matrix.os == 'ubuntu-latest'
name: Install QEMU user emulation
run: docker run --rm --privileged tonistiigi/binfmt --install all
- if: matrix.os == 'ubuntu-latest'
name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
- name: Cache Rust targets
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
# Conditional step for standard Rust build for non-arm64 targets
- if: matrix.os == 'ubuntu-latest'
name: Cross build for arm64
run: |
cross build --release --target aarch64-unknown-linux-gnu
ls -la target/aarch64-unknown-linux-gnu/
env:
SERVER_ADDRESS: 'http://127.0.0.1:8080'
CROSS_CONTAINER_OPTS: '--platform linux/arm64'
- name: Build
run: cargo build --release --target ${{ matrix.target }}
env:
SERVER_ADDRESS: 'http://127.0.0.1:8080'
- if: matrix.os == 'ubuntu-latest'
name: Upload arm64 pidgtm artifact
uses: actions/upload-artifact@v2
with:
name: pidgtm-aarch64-unknown-linux-gnu
path: target/aarch64-unknown-linux-gnu/release/pidgtm
docker-deploy:
needs: build
runs-on: ubuntu-latest
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: pidgtm-aarch64-unknown-linux-gnu
path: target/aarch64-unknown-linux-gnu/release/
- name: Display artifact
run: ls -la target/aarch64-unknown-linux-gnu/release/pidgtm
- name: Set Executable Permissions
run: chmod +x target/aarch64-unknown-linux-gnu/release/pidgtm
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: danstaken
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push multi-architecture Docker pidgtm-user-updater image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile-UserUpdater
push: true
tags: danstaken/pidgtm-user-updater:latest
platforms: linux/arm64
- name: Build and push multi-architecture Docker rust-build-env-arm64 image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile-BuildArm64
push: true
tags: danstaken/rust-build-env-arm64:latest
platforms: linux/arm64