build: modernize python stack #1
This file contains hidden or 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: CI - Pull Request | |
on: | |
pull_request: | |
branches: | |
- master | |
jobs: | |
test: | |
needs: | |
- test-release | |
strategy: | |
max-parallel: 3 | |
fail-fast: true | |
matrix: | |
python_version: | |
# https://python-release-cycle.glitch.me/ | |
- "3.9" | |
- "3.10" | |
- "3.11" | |
- "3.12" | |
- "3.13" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "${{ matrix.python_version }}" | |
- name: Install uv | |
uses: astral-sh/setup-uv@v6 | |
with: | |
python-version: "${{ matrix.python_version }}" | |
enable-cache: true | |
cache-dependency-glob: "uv.lock" | |
version: "0.8.7" | |
- name: Lint | |
run: | | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
uvx ruff check . --fix --statistics --config ruff.toml --exclude specs | |
- name: Test in staging | |
env: | |
SDC_MONITOR_TOKEN: ${{ secrets.STAGING_MONITOR_API_TOKEN }} | |
SDC_SECURE_TOKEN: ${{ secrets.STAGING_SECURE_API_TOKEN }} | |
SDC_MONITOR_URL: "https://app-staging.sysdigcloud.com" | |
SDC_SECURE_URL: "https://secure-staging.sysdig.com" | |
run: uv run mamba -f documentation -t integration | |
test-release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup go-chglog | |
working-directory: /tmp | |
env: | |
VERSION: "0.10.0" | |
run: | | |
wget https://github.com/git-chglog/git-chglog/releases/download/v${VERSION}/git-chglog_${VERSION}_linux_amd64.tar.gz | |
gunzip git-chglog_${VERSION}_linux_amd64.tar.gz | |
tar -xvf git-chglog_${VERSION}_linux_amd64.tar | |
sudo mv git-chglog /usr/local/bin/ | |
- name: Generate changelog | |
run: git-chglog -c .github/git-chglog/config.yml -o RELEASE_CHANGELOG.md $(git describe --tags $(git rev-list --tags --max-count=1)) | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Install uv | |
uses: astral-sh/setup-uv@v6 | |
with: | |
python-version: "3.10" | |
enable-cache: true | |
version: "0.8.7" | |
- name: Build | |
run: uv build | |
check_version: | |
name: Check Version | |
runs-on: ubuntu-latest | |
needs: test | |
permissions: | |
contents: write # required for creating a tag | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.sha }} # required for better experience using pre-releases | |
fetch-depth: '0' # Required due to the way Git works, without it this action won't be able to find any or the correct tags | |
- name: Extract current version | |
id: pyproject_version | |
run: | | |
TAG=v$(grep 'version =' pyproject.toml | sed -e 's/version = "\(.*\)"/\1/') | |
echo "TAG=$TAG" >> "$GITHUB_OUTPUT" | |
- name: Get branch ref name | |
id: branch_ref | |
run: | | |
BRANCH_NAME=${{ github.base_ref || github.ref_name }} | |
echo "$BRANCH_NAME" | |
echo "BRANCH_NAME=$BRANCH_NAME" >> "$GITHUB_OUTPUT" | |
- name: Get tag version | |
id: semantic_release | |
uses: anothrNick/github-tag-action@1.71.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
DEFAULT_BUMP: "patch" | |
TAG_CONTEXT: 'repo' | |
WITH_V: true | |
DRY_RUN: true | |
- name: Compare versions | |
run: | | |
echo "Current version: ${{ steps.pyproject_version.outputs.TAG }}" | |
echo "New version: ${{ steps.semantic_release.outputs.tag }}" | |
if [ "${{ steps.pyproject_version.outputs.TAG }}" != "${{ steps.semantic_release.outputs.tag }}" ]; then | |
echo "### Version mismatch detected! :warning: | |
Current pyproject version: ${{ steps.pyproject_version.outputs.TAG }} | |
New Tag version: **${{ steps.semantic_release.outputs.tag }}** | |
Current Tag: ${{ steps.semantic_release.outputs.old_tag }} | |
Please update the version in pyproject.toml." >> $GITHUB_STEP_SUMMARY | |
exit 1 | |
else | |
echo "### Version match confirmed! :rocket: | |
Current pyproject version: ${{ steps.pyproject_version.outputs.TAG }} | |
New Tag version: **${{ steps.semantic_release.outputs.tag }}** | |
The version is up-to-date." >> $GITHUB_STEP_SUMMARY | |
fi |