Skip to content

build: enable pushing Docker image in ci-cd-build.yml #133

build: enable pushing Docker image in ci-cd-build.yml

build: enable pushing Docker image in ci-cd-build.yml #133

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
UV_CACHE_DIR: /tmp/.uv-cache
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
name: Continuous Integration (Tests, Linting, Docs)
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.11, 3.12, 3.13]
fail-fast: true
timeout-minutes: 20
steps:
- name: Checkout Repository
uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Restore UV Cache
uses: actions/[email protected]
with:
path: ${{ env.UV_CACHE_DIR }}
key: "uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}"
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
- name: Set up UV Environment
uses: astral-sh/[email protected]
with:
enable-cache: true
cache-dependency-glob: uv.lock
- name: Run Formatting, Linting, Type Checks, and Tests
run: |
uv run ruff format ./
uv run ruff check --fix ./
uv run mypy ./
uv run pytest --cov-report xml
- name: Upload Test Coverage to Codecov
uses: codecov/[email protected]
with:
token: '${{ secrets.CODECOV_TOKEN }}'
file: ./coverage.xml
fail_ci_if_error: true
- name: Scan with SonarCloud
uses: SonarSource/[email protected]
env:
SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}'
- name: Build Documentation
run: uv run --group=docs make clean html --directory docs/
- name: Upload documentation to GitHub Pages
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/html
- name: Minimize UV Cache
run: uv cache prune --ci
cd:
name: Continuous Deployment (Release, Publish, and Build)
needs: ci
permissions:
id-token: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Run Python Semantic Release
id: release
uses: python-semantic-release/[email protected]
with:
github_token: '${{ secrets.GITHUB_TOKEN }}'
git_committer_name: 'MountainGod2'
git_committer_email: '[email protected]'
ssh_private_signing_key: '${{ secrets.GIT_COMMIT_SSH_PRIV_KEY }}'
ssh_public_signing_key: '${{ secrets.GIT_COMMIT_SSH_PUB_KEY }}'
- name: Publish to TestPyPI
if: steps.release.outputs.released == 'true'
uses: pypa/[email protected]
with:
repository-url: 'https://test.pypi.org/legacy/'
- name: Test Install from TestPyPI
if: steps.release.outputs.released == 'true'
run: |
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple chaturbate-poller
- name: Publish to PyPI
if: steps.release.outputs.released == 'true'
uses: pypa/[email protected]
- name: Publish to GitHub Releases
if: steps.release.outputs.released == 'true'
uses: python-semantic-release/[email protected]
with:
github_token: '${{ secrets.GITHUB_TOKEN }}'
- name: Set up QEMU for Multi-Architecture Builds
if: steps.release.outputs.released == 'true'
uses: docker/[email protected]
- name: Set up Docker Buildx for Multi-Platform Builds
if: steps.release.outputs.released == 'true'
uses: docker/[email protected]
- name: Generate Docker Image Metadata
id: meta
if: steps.release.outputs.released == 'true'
uses: docker/[email protected]
with:
images: ghcr.io/mountaingod2/chaturbate_poller
tags: |
type=ref,event=branch,enable={{is_default_branch}},value=latest
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value={{ sha }},prefix=commit-
labels: |
org.opencontainers.image.revision={{ sha }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.created={{ now }}
org.opencontainers.image.version={{ version }}
- name: Log in to GitHub Container Registry
if: steps.release.outputs.released == 'true' && github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ghcr.io
username: '${{ github.repository_owner }}'
password: '${{ secrets.GITHUB_TOKEN }}'
- name: Build and Push Docker Image
if: steps.release.outputs.released == 'true' && github.event_name != 'pull_request'
uses: docker/[email protected]
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
- name: Run Docker Image Tests
if: steps.release.outputs.released == 'true'
run: docker run --rm ghcr.io/mountaingod2/chaturbate_poller:latest --version
summary:
name: Summary Report
needs: [ci, cd]
runs-on: ubuntu-latest
if: always()
steps:
- name: Post Summary
run: |
echo "### CI/CD Summary" >> $GITHUB_STEP_SUMMARY
echo "Continuous Integration and Deployment completed." >> $GITHUB_STEP_SUMMARY
echo "Docker Image built and tested successfully." >> $GITHUB_STEP_SUMMARY