build: test task to use tests directory only #146
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test, Build, Publish, Release | |
on: | |
push: | |
branches: [main, dev] | |
pull_request: | |
branches: [main, dev] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
# if branch is main, use prod, else dev | |
BUILD_NAME: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }} | |
jobs: | |
test: | |
name: 🔬 Linting, 📊 PyTest | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
- name: Install poetry | |
run: pipx install poetry | |
- name: View poetry | |
run: poetry --version | |
- name: 🐍 Set up Python | |
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c | |
with: | |
python-version: 3.12 | |
cache: "poetry" | |
- name: Add Poe the Poet plugin | |
run: poetry self add 'poethepoet[poetry_plugin]' | |
- name: Install dependencies | |
run: poetry install --no-root --with dev,lint,test | |
- name: Python Format (autoflake/isort/black) | |
run: poetry poe formatters | |
- name: Python Lint (pylint) | |
run: poetry poe pylint | |
- name: Python Typecheck (mypy) | |
run: poetry poe typings | |
- name: Run tests | |
run: poetry poe tests | |
build: | |
name: 🐳 Build and publish docker images | |
needs: test | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
- name: Echo GITHUB_ENV | |
run: | | |
echo $GITHUB_ENV | |
# Log into a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Login into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@9dc751fe249ad99385a2583ee0d084c400eee04e | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
labels: | | |
org.opencontainers.image.description=Slick Telemetry backend ${{ env.BUILD_NAME }} image | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 | |
with: | |
context: . | |
file: ./Dockerfile.${{ env.BUILD_NAME }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
release: | |
# create a release following the logic below: | |
# 1. when the branch is `main` AND | |
# 2. its a push event AND | |
# 3. the head commit's commit message does NOT starts with `bump:` | |
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' && ! startsWith(github.event.head_commit.message , 'bump:') }} | |
name: ⬆️ Bump version and create changelog with a GitHub release | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.SVC_PAT }} | |
- name: Create bump and changelog | |
uses: commitizen-tools/commitizen-action@bc2616fec6b3effc9ad20380f19550a8b18cdbdf | |
with: | |
github_token: ${{ secrets.SVC_PAT }} | |
changelog_increment_filename: body.md | |
- name: Release | |
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 | |
with: | |
body_path: "body.md" | |
tag_name: ${{ env.REVISION }} | |
token: ${{ secrets.SVC_PAT }} | |
generate_release_notes: true |