Skip to content

Commit

Permalink
chore: git workflow improvements (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianScheidegger authored Jan 16, 2025
1 parent 6f38dad commit cb659e0
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 10 deletions.
53 changes: 48 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,54 @@ env:
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
IMAGE_NAME: ${{ github.repository }} # Image name will be <account>/<repo>
jobs:
release:
verify-with-tox:
runs-on: ubuntu-latest
steps:
- name: 📄 Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: 🧱 Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 -
- name: 🧱 Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.13'
cache: poetry
- name: 🧱 Install dependencies
run: poetry install --all-extras
- name: 🧪 Run tests
run: poetry run tox
- name: SonarCloud scan for PR
uses: sonarsource/sonarqube-scan-action@13990a695682794b53148ff9f6a8b6e22e43955e # v3.1.0
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: |
-Dsonar.pullrequest.base=${{ github.base_ref }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
- name: SonarCloud scan for Push
uses: sonarsource/sonarqube-scan-action@13990a695682794b53148ff9f6a8b6e22e43955e # v3.1.0
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: |
-Dsonar.branch.name=${{ github.head_ref }}
- name: Docker Hadolint
uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf
with:
format: tty
release-please:
needs: verify-with-tox
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- id: rp
- id: release
if: github.event_name != 'pull_request' && github.ref_name == 'main'
uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4.1.3
with:
Expand All @@ -35,11 +78,11 @@ jobs:
id: tags
env:
# When release-please is skipped, these values will be empty
is_release: ${{ steps.rp.outputs.release_created }}
version: v${{ steps.rp.outputs.major }}.${{ steps.rp.outputs.minor }}.${{ steps.rp.outputs.patch }}
release_created: ${{ steps.release.outputs.release_created }}
version: ${{ steps.release.outputs.version }}
run: |
tags=""
if [[ "$is_release" = 'true' ]]; then
if [[ "$release_created" = 'true' ]]; then
tags="type=semver,pattern={{version}},value=$version
type=semver,pattern={{major}},value=$version
type=semver,pattern={{major}}.{{minor}},value=$version"
Expand Down
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ repos:
rev: v4.1.0
hooks:
- id: commitizen
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ COPY ./app/ ${WORKING_DIR}/app/
COPY ./poetry.lock ${WORKING_DIR}
COPY ./pyproject.toml ${WORKING_DIR}

RUN pip install --no-cache-dir -r ${WORKING_DIR}/requirements.txt && poetry install --no-root
RUN pip install --no-cache-dir -r "${WORKING_DIR}"/requirements.txt && poetry install --no-root

ENTRYPOINT [ "poetry", "run", "python", "-m", "app.requirements_inspector_service" ]
1 change: 1 addition & 0 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DUMMY = "42"
Empty file added tests/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""TEST"""

from app import app


def test_dummy():
"""Dummy test."""
assert app.DUMMY == "42"
18 changes: 14 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ envlist =
py313
minversion = 4.21.2

[testenv]
description = set index urls

[testenv:lint]
description = run linters and formatters
deps =
ruff
mypy
commands =
ruff format
ruff check
mypy .

[testenv]
deps =
coverage
pytest
commands =
coverage run -m pytest . --junitxml="junittest.xml"
coverage report -m --fail-under 90
coverage xml

[coverage:run]
relative_files = True
source = app/
branch = True

0 comments on commit cb659e0

Please sign in to comment.