diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index e1539c9..b2293b8 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -1,5 +1,5 @@ # Based on: https://pastebin.com/99Fq2b2w -name: Build and deploy automation_rs +name: Build and deploy on: push: branches: @@ -7,49 +7,8 @@ on: - feature/** jobs: - check: - name: Run pre-commit checks - runs-on: ubuntu-latest - 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 - build: - name: Build automation_rs + name: Build application runs-on: ubuntu-latest container: catthehacker/ubuntu:act-latest steps: @@ -71,9 +30,9 @@ jobs: path: target/x86_64-unknown-linux-gnu/release/automation container: - name: Build Docker image + name: Build container runs-on: ubuntu-latest - needs: [build, checks] + needs: [build] container: catthehacker/ubuntu:act-latest steps: - name: Checkout @@ -89,6 +48,17 @@ jobs: chown 65532:65532 ./build/* chmod 0755 ./build/* + - name: Docker meta + id: meta + uses: https://github.com/docker/metadata-action@v5 + with: + images: git.huizinga.dev/dreaded_x/automation_rs + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - name: Login to registry uses: https://github.com/docker/login-action@v3 with: @@ -100,12 +70,12 @@ jobs: 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 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} deploy: - name: Deploy Docker container + name: Deploy container runs-on: ubuntu-latest container: catthehacker/ubuntu:act-latest needs: [container] @@ -127,7 +97,7 @@ jobs: -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 + git.huizinga.dev/dreaded_x/automation_rs:master docker network connect web automation_rs diff --git a/.gitea/workflows/checks.yml b/.gitea/workflows/checks.yml new file mode 100644 index 0000000..bf5d1b2 --- /dev/null +++ b/.gitea/workflows/checks.yml @@ -0,0 +1,17 @@ +name: Check +on: + push: + branches: "**" + +jobs: + check: + name: Run checks + runs-on: ubuntu-latest + container: git.huizinga.dev/dreaded_x/pre-commit:master + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run pre-commit + run: SKIP=sqlx-prepare pre-commit run --show-diff-on-failure --color=always --all-files + shell: bash