chore(deps): update dependencies #251
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] | |
pull_request: | |
branches: [main] | |
jobs: | |
test: | |
name: 🔬 Linting, 📊 PyTest | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 | |
- name: Set up .env | |
run: cp .env.example .env | |
- name: Install poetry | |
run: pipx install poetry | |
- name: View poetry | |
run: poetry --version | |
- name: 🐍 Set up Python | |
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f | |
with: | |
python-version: 3.12.6 | |
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 linters | |
- name: Python Typecheck (mypy) | |
run: poetry poe typings | |
# - name: Run tests | |
# env: | |
# ENVIRONMENT: TEST # This disables New Relic initialization | |
# run: poetry poe tests | |
build: | |
name: 🐳 Build and publish docker images | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
# if branch is main, use prod | |
BUILD_NAME: ${{ github.ref == 'refs/heads/main' && 'prod' }} | |
# if the event is push and the commit message starts with `bump:`, upload the image | |
UPLOAD_IMAGE: ${{ github.event_name == 'push' && startsWith(github.event.head_commit.message , 'bump:') }} | |
needs: test | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 | |
# Get the latest tag | |
- name: Get latest tag | |
id: latest_tag | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea | |
with: | |
script: | | |
const repo = context.repo; | |
const tags = await github.rest.repos.listTags(repo); | |
if (tags.data.length > 0) { | |
const latestTag = tags.data[0].name; | |
console.log(`Latest tag: ${latestTag}`); | |
return latestTag; | |
} else { | |
console.log('No tags found; using default version 0.0.1'); | |
return '0.0.1'; | |
} | |
# Set the version from the latest tag or from the build name | |
# If the build is triggered by a push event and the commit message starts with `bump:` | |
# then the version is set to the latest tag | |
# Otherwise, the version is set to the build name | |
# This is used to tag the Docker image | |
- name: Set version | |
run: echo "VERSION=${{ steps.latest_tag.outputs.result || env.BUILD_NAME }}" >> $GITHUB_ENV | |
- name: Echo GITHUB_ENV | |
run: | | |
echo $GITHUB_ENV | |
# Log into a Docker registry | |
# The login is performed only if the event is push and the commit message starts with `bump:` | |
- name: Login into registry ${{ env.REGISTRY }} | |
if: ${{ env.UPLOAD_IMAGE != 'false' }} | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# Metadata is extracted only if the event is push and the commit message starts with `bump:` | |
- name: Extract Docker metadata | |
if: ${{ env.UPLOAD_IMAGE != 'false' }} | |
id: meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 | |
with: | |
tags: | | |
type=edge,branch=${{ github.ref }} | |
type=raw,value=${{ env.BUILD_NAME }} | |
type=ref,event=branch | |
type=semver,pattern={{version}},value=${{ github.ref == 'refs/heads/main' && env.VERSION || format('{0}-{1}', env.VERSION, github.ref_name) }} | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
labels: | | |
org.opencontainers.image.description=Slick Telemetry rearwing ${{ env.BUILD_NAME }} image | |
org.opencontainers.image.version=${{ env.VERSION }} | |
# Build and upload Docker image to GHCR with Buildx | |
# The image is uploaded only if the event is push and the commit message starts with `bump:` | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445 | |
with: | |
context: . | |
file: ./Dockerfile.${{ env.BUILD_NAME }} | |
push: ${{ env.UPLOAD_IMAGE }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
release: | |
# create a release following the logic below: | |
# 1. branch is `main` AND | |
# 2. workflow is triggered by 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: Checkout repo | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.SVC_PAT }} | |
- name: Create bump and changelog | |
uses: commitizen-tools/commitizen-action@1f11eb222996406681d2bfa1eb3d997eca46557c | |
with: | |
github_token: ${{ secrets.SVC_PAT }} | |
changelog_increment_filename: body.md | |
- name: Release | |
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 | |
with: | |
body_path: "body.md" | |
tag_name: ${{ env.REVISION }} # this is the version set in the previous step | |
token: ${{ secrets.SVC_PAT }} | |
generate_release_notes: true |