automation_rs/.gitea/workflows/build.yml

140 lines
4.4 KiB
YAML

# Based on: https://pastebin.com/99Fq2b2w
name: Build and deploy automation_rs
on:
push:
branches:
- master
- feature/**
jobs:
build:
name: Build automation_rs
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- name: Build
run: cargo build --release --all-targets
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: build
path: target/x86_64-unknown-linux-gnu/release/automation
check:
name: Run pre-commit checks
runs-on: ubuntu-latest
# The lua definition check require that generate_definitions is build first
needs: [build]
container: catthehacker/ubuntu:act-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ">=1.20.1"
- name: Calculate cache hash
uses: https://gitea.com/actions/go-hashfiles@v0.0.1
id: hash-go
with:
patterns: |
.pre-commit-config.yaml
- name: Setup cache
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ steps.hash-go.outputs.hash }}
- name: Install pre-commit
run: python -m pip install pre-commit
shell: bash
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- name: Set rustup default
run: rustup default stable
shell: bash
- name: Run pre-commit
run: pre-commit run --show-diff-on-failure --color=always --all-files
shell: bash
container:
name: Build Docker image
runs-on: ubuntu-latest
needs: [build, checks]
container: catthehacker/ubuntu:act-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: build
- name: Set permissions
run: |
chown 65532:65532 ./build/*
chmod 0755 ./build/*
- name: Login to registry
uses: https://github.com/docker/login-action@v3
with:
registry: git.huizinga.dev
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push Docker image
uses: https://github.com/docker/build-push-action@v5
with:
context: .
push: ${{ gitea.ref == 'refs/heads/master' }}
# TODO: Automatically add the correct tags here
tags: git.huizinga.dev/dreaded_x/automation_rs:latest
deploy:
name: Deploy Docker container
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
needs: [container]
if: gitea.ref == 'refs/heads/master'
steps:
- name: Stop and remove current container
run: |
docker stop automation_rs || true
docker rm automation_rs || true
- name: Create container
run: |
docker create \
--pull always \
--restart unless-stopped \
--name automation_rs \
--network mqtt \
-e RUST_LOG=automation=debug \
-e MQTT_PASSWORD=${{ secrets.MQTT_PASSWORD }} \
-e HUE_TOKEN=${{ secrets.HUE_TOKEN }} \
-e NTFY_TOPIC=${{ secrets.NTFY_TOPIC }} \
git.huizinga.dev/dreaded_x/automation_rs:latest
docker network connect web automation_rs
- name: Start container
run: docker start automation_rs
# TODO: Perform a healthcheck