CI/CD #19
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: 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-20.04, macos-latest, windows-latest] | |
include: | |
- os: ubuntu-20.04 # we build on 20.04 to match my local machine and the docker image (required to get libssl.so.1.1) | |
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 | |
- name: Cache Rust dependencies | |
uses: Swatinem/rust-cache@v2 | |
with: | |
key: "rust-cache-${{ hashFiles('**/Cargo.lock') }}-${{ github.run_id }}" | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
target: ${{ matrix.target }} | |
- if: matrix.os == 'windows-latest' | |
name: Install PostgreSQL | |
uses: ikalnytskyi/action-setup-postgres@v4 | |
- name: Build | |
run: cargo build --release --target ${{ matrix.target }} | |
env: | |
SERVER_ADDRESS: 'http://127.0.0.1:8080' | |
- if: matrix.os == 'ubuntu-20.04' | |
name: Upload smithe artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: smithe-${{ matrix.target }} | |
path: target/${{ matrix.target }}/release/smithe | |
- if: matrix.os == 'ubuntu-20.04' | |
name: Upload pidgtm artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: pidgtm-${{ matrix.target }} | |
path: target/${{ matrix.target }}/release/pidgtm | |
docker-deploy: | |
needs: build | |
runs-on: ubuntu-20.04 | |
if: > | |
(github.event_name == 'push' && github.ref == 'refs/heads/main') || | |
github.event_name == 'workflow_dispatch' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: pidgtm-x86_64-unknown-linux-gnu | |
path: target/x86_64-unknown-linux-gnu/release/ | |
- name: Display artifact | |
run: ls -la target/x86_64-unknown-linux-gnu/release/pidgtm && ldd target/x86_64-unknown-linux-gnu/release/pidgtm | |
- name: Set Executable Permissions | |
run: chmod +x target/x86_64-unknown-linux-gnu/release/pidgtm | |
- name: Build Docker image | |
run: | | |
docker build -t danstaken/pidgtm-user-updater:latest -f Dockerfile-UserUpdater . | |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u danstaken --password-stdin | |
docker push danstaken/pidgtm-user-updater:latest |