You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
amcrest2mqtt/.github/workflows/deploy.yaml

181 lines
5.7 KiB
YAML

name: Release and Docker Deploy
on:
push:
branches:
- "main"
pull_request:
workflow_dispatch:
schedule:
- cron: "0 3 1 * *" # Monthly rebuild at 03:00 UTC on the 1st
permissions:
contents: write
issues: write
pull-requests: write
packages: write
jobs:
lint:
name: Lint (ruff/black)
runs-on: ubuntu-latest
if: github.event_name != 'schedule'
strategy:
fail-fast: false
max-parallel: 2
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
# If your dev tools (ruff/black/rst-lint/rich/etc.) are in optional-dependencies
# like [project.optional-dependencies.dev], this installs them.
- name: Install project (dev)
run: uv sync --all-extras --dev
- name: Ruff
run: uv run ruff check src
- name: Black
run: |
uv run black --version
uv run black --check --color --diff .
release:
name: Semantic Release
runs-on: ubuntu-latest
needs: [lint]
if: github.event_name != 'schedule'
outputs:
published: ${{ steps.semrel.outputs.new_release_published }}
version: ${{ steps.semrel.outputs.new_release_version }}
tag: ${{ steps.semrel.outputs.new_release_git_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run semantic-release
id: semrel
uses: cycjimmy/semantic-release-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
@semantic-release/npm
- name: Update VERSION file in repo
if: steps.semrel.outputs.new_release_published == 'true'
run: |
echo "${{ steps.semrel.outputs.new_release_version }}" > VERSION
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add VERSION
git diff --cached --quiet || git commit -m "chore: update VERSION to ${{ steps.semrel.outputs.new_release_version }}"
git push
docker:
name: Build and Push Docker Image
needs: [release]
if: github.event_name == 'schedule' || needs.release.result == 'success'
runs-on: ubuntu-latest
env:
RELEASE_VERSION: ${{ needs.release.outputs.version }}
RELEASE_TAG: ${{ needs.release.outputs.tag }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PAT }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: graystorm/amcrest2mqtt
tags: |
type=raw,value=${{ env.RELEASE_TAG }}
type=raw,value=latest
labels: |
org.opencontainers.image.title=amcrest2mqtt
org.opencontainers.image.description=Publishes Amcrest device data to MQTT for Home Assistant
org.opencontainers.image.url=https://www.graystorm.com
org.opencontainers.image.documentation=https://github.com/${{ github.repository }}#readme
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Fetch tags
run: git fetch --tags --force
- name: Ensure VERSION is set
id: version-fallback
run: |
if [ -z "${{ needs.release.outputs.version }}" ]; then
TAG=$(git tag --sort=-creatordate | head -n 1)
if [ -z "$TAG" ]; then
echo "No tags found — defaulting to 0.0.0"
TAG="0.0.0"
fi
echo "Using existing tag: $TAG"
echo "VERSION=$TAG" >> $GITHUB_ENV
else
echo "VERSION=${{ needs.release.outputs.version }}" >> $GITHUB_ENV
fi
- name: Build and push
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
push: true
build-args: |
VERSION=${{ env.VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64,linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.version=${{ env.RELEASE_TAG }}
org.opencontainers.image.title=amcrest2mqtt
org.opencontainers.image.source=${{ github.repository }}
org.opencontainers.image.authors=weirdTangent <jeff@weirdtangent.com>
org.opencontainers.image.url=https://www.graystorm.com
org.opencontainers.image.documentation=https://github.com/${{ github.repository }}#readme
org.opencontainers.image.description=Publishes Amcrest camera events, snapshots, and status updates via MQTT for Home Assistant auto-discovery
org.opencontainers.image.licenses=MIT
sbom: true
provenance: true