77 lines
2.5 KiB
YAML
77 lines
2.5 KiB
YAML
name: Build Project
|
|
|
|
on:
|
|
push:
|
|
branches: ["main"]
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: rust:latest
|
|
services:
|
|
db:
|
|
image: postgres:latest
|
|
env:
|
|
POSTGRES_USER: dev
|
|
POSTGRES_PASSWORD: dev
|
|
POSTGRES_DB: iot
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 5432:5432
|
|
|
|
steps:
|
|
- name: Install necessary dependencies
|
|
run: apt update && apt install nodejs pkg-config -y
|
|
- name: Install docker
|
|
run: curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v2
|
|
- name: Run migrations
|
|
run: cargo install sqlx-cli && sqlx migrate run
|
|
- name: Build server binary
|
|
run: cargo build --release
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
- name: Log in to Docker Registry
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: gitea.tobiasmaier.me
|
|
username: tobimai
|
|
password: ${{ secrets.docker_registry_key }}
|
|
- name: Extract Version from Cargo.toml
|
|
run: |
|
|
VERSION_PATCH=$(grep '^version' Cargo.toml | head -n 1 | cut -d ' ' -f 3 | tr -d '"')
|
|
VERSION_MINOR=$(grep '^version' Cargo.toml | head -n 1 | cut -d ' ' -f 3 | tr -d '"' | cut -d '.' -f 1,2)
|
|
VERSION_MAJOR=$(grep '^version' Cargo.toml | head -n 1 | cut -d ' ' -f 3 | tr -d '"' | cut -d '.' -f 1)
|
|
echo "VERSION_PATCH=$VERSION_PATCH" >> $GITEA_ENV
|
|
echo "VERSION_MINOR=$VERSION_MINOR" >> $GITEA_ENV
|
|
echo "VERSION_MAJOR=$VERSION_MAJOR" >> $GITEA_ENV
|
|
echo "Patch Version: $VERSION_PATCH"
|
|
echo "Minor Version: $VERSION_MINOR"
|
|
echo "Major Version: $VERSION_MAJOR"
|
|
- name: Build and Push Docker Image for Patch version
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: gitea.tobiasmaier.me/tobimai/iot:${{ env.VERSION_PATCH }}
|
|
- name: Build and Push Docker Image for minor version
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: gitea.tobiasmaier.me/tobimai/iot:${{ env.VERSION_MINOR }}
|
|
- name: Build and Push Docker Image for major version
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: gitea.tobiasmaier.me/tobimai/iot:${{ env.VERSION_MAJOR }}
|
|
|
|
|
|
|