Compare commits

...

2 commits

Author SHA1 Message Date
4ee3c5a097 update readme 2023-12-05 15:30:42 +01:00
e51b03aca2 add new workflows 2023-12-05 15:21:10 +01:00
7 changed files with 317 additions and 0 deletions

View file

@ -0,0 +1,38 @@
name: build pypackage
on:
workflow_call:
inputs:
repository:
required: true
type: string
description: "package repository"
secrets:
username:
required: true
description: "repository username"
token:
required: true
description: "repository token/password"
jobs:
build-pypackage:
runs-on: python311
env:
HATCH_INDEX_REPO: ${{ inputs.repository }}
HATCH_INDEX_USER: ${{ secrets.username }}
HATCH_INDEX_AUTH: ${{ secrets.token }}
steps:
- name: checkout code
uses: actions/checkout@v3
- name: install hatch
run: pip install -U hatch hatchling
- name: build package
run: hatch build --clean
- name: publish package
if: gitea.event_name != 'pull_request'
run: hatch publish --yes --no-prompt

View file

@ -0,0 +1,43 @@
name: check/lint python code
on:
workflow_call:
inputs:
src-dir:
required: false
type: string
description: "source directory"
default: "."
run-tests:
required: false
type: boolean
description: "run tests"
default: false
tests-dir:
required: false
type: string
description: "tests directory"
default: "tests"
jobs:
check-python:
runs-on: python311
steps:
- name: checkout code
uses: actions/checkout@v3
- name: install requirements
run: pip install -U ruff mypy pytest
- name: test mypy
run: mypy --non-interactive --install-types ${{ inputs.src-dir }}
- name: test ruff check
run: ruff check --diff ${{ inputs.src-dir }}
- name: test ruff format
run: ruff format --check --diff ${{ inputs.src-dir }}
- name: run tests
if: ${{ inputs.run-tests == true }}
run: pytest --exitfirst --verbose ${{ inputs.tests-dir }}

View file

@ -0,0 +1,30 @@
name: check/lint python code with hatch
on:
workflow_call:
inputs:
run-tests:
required: false
type: boolean
description: "run tests"
default: false
jobs:
check-python-hatch:
runs-on: python311
steps:
- name: checkout code
uses: actions/checkout@v3
- name: install hatch
run: pip install -U hatch
- name: test codestyle
run: hatch run lint:fmt
- name: test typing
run: hatch run lint:typing
- name: run tests
if: ${{ inputs.run-tests == true }}
run: hatch run default:test

View file

@ -0,0 +1,56 @@
name: build and release pypackage
on:
workflow_call:
inputs:
repository:
required: true
type: string
description: "package repository"
release-body:
required: false
type: string
description: "body of the release"
secrets:
username:
required: true
description: "repository username"
token:
required: true
description: "repository token/password"
jobs:
release-pypackage:
runs-on: python311
env:
HATCH_INDEX_REPO: ${{ inputs.repository }}
HATCH_INDEX_USER: ${{ secrets.username }}
HATCH_INDEX_AUTH: ${{ secrets.token }}
steps:
- name: checkout code
uses: actions/checkout@v3
- name: setup go
uses: actions/setup-go@v4
with:
go-version: '>=1.20'
- name: install hatch
run: pip install -U hatch hatchling
- name: build package
run: hatch build --clean
- name: publish package
if: gitea.event_name != 'pull_request'
run: hatch publish --yes --no-prompt
- name: create gitea release
uses: https://gitea.com/actions/release-action@main
if: gitea.event_name != 'pull_request'
with:
title: ${{ gitea.ref_name }}
body: ${{ inputs.release-body }}
files: |-
dist/**

View file

@ -0,0 +1,50 @@
name: upload code to sonarqube
on:
workflow_call:
inputs:
coverage:
required: false
type: boolean
description: "generate coverage"
default: false
tests-dir:
required: false
type: string
description: "tests directory"
default: "tests"
secrets:
sonar-host:
required: true
description: "sonarqube instance url"
sonar-token:
required: true
description: "sonarqube auth token"
jobs:
scan-code:
runs-on: python311
steps:
- name: checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: install requirements
if: ${{ inputs.coverage == true }}
run: pip install -U pytest coverage
- name: get coverage
if: ${{ inputs.coverage == true }}
run: |
coverage erase
coverage run -m pytest --exitfirst --verbose ${{ inputs.tests-dir }}
coverage report
coverage xml
- name: run sonar-scanner
uses: sonarsource/sonarqube-scan-action@v2.0.1
env:
SONAR_HOST_URL: ${{ secrets.sonar-host }}
SONAR_TOKEN: ${{ secrets.sonar-token }}

View file

@ -0,0 +1,30 @@
name: generate and update changelog
on:
workflow_call:
jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master
- name: install auto-changelog
run: npm install -g auto-changelog
- name: generate changelog
run: >-
auto-changelog -t keepachangelog --unreleased
--ignore-commit-pattern '(B|b)ump version|update changelog'
- name: commit changes
uses: EndBug/add-and-commit@v9
if: gitea.event_name != 'pull_request'
with:
message: "[bot] update changelog"
author_name: actions-bot
author_email: actions@bots.44net.ch

View file

@ -0,0 +1,70 @@
# reusable workflows for 44net git
> [docs](https://docs.github.com/en/actions/using-workflows/reusing-workflows)
## examples
### build a container
from `44net/docker-images`
```yml
jobs:
build-debian-base:
uses: actions/workflows/.gitea/workflows/build_container.yml@master
env:
IMAGE_NAME: debian-base
with:
registry: ${{ env.REGISTRY }}
image-name: ${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}
context: ${{ env.IMAGE_NAME }}
dockerfile: ${{ env.IMAGE_NAME }}/Dockerfile
platforms: linux/amd64,linux/arm64
secrets:
cr-username: ${{ secrets.CR_USERNAME }}
cr-password: ${{ secrets.CR_PASSWORD }}
```
### run tests (python)
from `44net/fftools`
```yml
jobs:
check-code:
uses: actions/workflows/.gitea/workflows/check_python_hatch.yml@master
with:
run-tests: true
```
### scan with sonar-scanner (python)
from `44net/fftools`
```yml
jobs:
scan-code:
uses: actions/workflows/.gitea/workflows/sonarqube_python.yml@master
needs: [check-code]
if: gitea.event_name != 'pull_request'
with:
coverage: true
secrets:
sonar-host: ${{ secrets.SONARQUBE_HOST }}
sonar-token: ${{ secrets.SONARQUBE_TOKEN }}
```
### build and release package (python)
from `44net/fftools`
```yml
jobs:
build-pypackage:
uses: actions/workflows/.gitea/workflows/release_pypackage.yml@master
with:
repository: https://git.44net.ch/api/packages/44net/pypi
secrets:
username: actions-bot
token: ${{ secrets.PACKAGE_TOKEN }}
```