63 lines
1.5 KiB
YAML
63 lines
1.5 KiB
YAML
name: CI - Lint, Test, and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
pull_request:
|
|
branches: [ "main" ]
|
|
schedule:
|
|
- cron: '0 0 3 * *' # monthly refresh
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
lint-and-test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: '3.12'
|
|
cache: pip
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r requirements.txt
|
|
pip install coverage
|
|
|
|
- name: Ruff lint
|
|
run: ruff check .
|
|
|
|
- name: Run pytest with coverage
|
|
run: |
|
|
coverage run -m pytest tests/ -v
|
|
coverage report
|
|
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
needs: lint-and-test
|
|
if: github.event_name != 'pull_request'
|
|
steps:
|
|
- name: Set Image name
|
|
run: |
|
|
echo "IMAGE_NAME=k2patel/apcupsd-client:latest" >> $GITHUB_ENV
|
|
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_TOKEN }}
|
|
|
|
- name: Build the Docker image
|
|
id: build
|
|
run: |
|
|
docker build . -t ${{ env.IMAGE_NAME }}
|
|
|
|
- name: Push the Docker image
|
|
run: docker push ${{ env.IMAGE_NAME }} |