Skip to content

Testing check version check #953

Testing check version check

Testing check version check #953

Workflow file for this run

name: Build
on:
# Only run workflow when there is push to main or when there is a pull request to main
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
# When running with act (https://github.com/nektos/act), these lines need to be appended with the ACT variable
# to force each job to run
if: github.repository == 'adobe/buildrunner' #|| ${{ env.ACT }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
steps:
- uses: actions/checkout@v2
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
# Install dev dependencies
- name: Install dependencies
run: uv sync --locked
- name: Pre-commit checks
run: uv run pre-commit run --all-files
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Test with pytest
# Create the ssh key file once for all testing
run: |
ssh-keygen -t ecdsa -m PEM -N '' -f /tmp/buildrunner-test-id_rsa
uv run pytest -v -m "not serial" --numprocesses=auto --junitxml=test-reports/non-serial-test-results.xml
uv run pytest -v -m "serial" --junitxml=test-reports/serial-test-results.xml
uv run python scripts/combine_xml.py test-reports/serial-test-results.xml test-reports/non-serial-test-results.xml > test-reports/test-results.xml
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action/linux@v2
if: always()
with:
files: test-reports/test-results.xml
check_name: "Test Results ${{ matrix.python-version }}"
github_retries: 10
secondary_rate_limit_wait_seconds: 60.0
# Version source of truth: pyproject.toml [project] version. User must update it before merging to main.
# PRs are checked so that version differs from main. On push to main, CI tags and publishes that version.
get-version:
if: github.repository == 'adobe/buildrunner'
runs-on: ubuntu-latest
needs: test
permissions:
contents: write
outputs:
current-version: ${{ steps.version-number.outputs.CURRENT_VERSION }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: 3.9
- name: Install dependencies
run: uv sync --locked
- name: Get current version
id: version-number
run: echo "CURRENT_VERSION=$(uv version --short)" >> $GITHUB_OUTPUT
- name: Print current version
run: echo CURRENT_VERSION ${{ steps.version-number.outputs.CURRENT_VERSION }}
# PR check: version must differ from main and be strictly greater (semver: major.minor.patch).
# MAJOR may not decrease; MINOR may not decrease unless MAJOR increased; PATCH may not decrease unless MAJOR or MINOR changed.
version-changed:
if: github.repository == 'adobe/buildrunner' && github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: 3.9
- name: Check version increased from main
run: |
PR_VERSION=$(uv version --short)
git fetch origin main
MAIN_VERSION=$(git show origin/main:pyproject.toml | sed -n 's/^version *= *"\(.*\)".*/\1/p' | tr -d ' ')
if [ -z "$MAIN_VERSION" ]; then
echo "Could not read version from main's pyproject.toml"
exit 1
fi
# Parse major.minor.patch (default missing to 0; e.g. "3" -> 3.0.0, "3.22" -> 3.22.0)
main_major=$(echo "$MAIN_VERSION" | cut -d. -f1)
main_minor=$(echo "$MAIN_VERSION" | cut -d. -f2)
main_patch=$(echo "$MAIN_VERSION" | cut -d. -f3)
[ -z "$main_minor" ] && main_minor=0
[ -z "$main_patch" ] && main_patch=0
pr_major=$(echo "$PR_VERSION" | cut -d. -f1)
pr_minor=$(echo "$PR_VERSION" | cut -d. -f2)
pr_patch=$(echo "$PR_VERSION" | cut -d. -f3)
[ -z "$pr_minor" ] && pr_minor=0
[ -z "$pr_patch" ] && pr_patch=0
# Require PR version strictly greater than main (at least one component increased, none decreased per semver rules)
fail_msg="Version must be strictly greater than main ($MAIN_VERSION). Rules: MAJOR may not decrease; MINOR may not decrease unless MAJOR increased; PATCH may not decrease unless MAJOR or MINOR changed. Bump with e.g. \`uv version --bump patch\`."
if [ "$pr_major" -lt "$main_major" ]; then
echo "::error::MAJOR decreased ($main_major → $pr_major). $fail_msg"
exit 1
fi
if [ "$pr_major" -gt "$main_major" ]; then
echo "Version OK: $MAIN_VERSION → $PR_VERSION"
exit 0
fi
if [ "$pr_minor" -lt "$main_minor" ]; then
echo "::error::MINOR decreased ($main_minor → $pr_minor) without MAJOR increase. $fail_msg"
exit 1
fi
if [ "$pr_minor" -gt "$main_minor" ]; then
echo "Version OK: $MAIN_VERSION → $PR_VERSION"
exit 0
fi
if [ "$pr_patch" -lt "$main_patch" ]; then
echo "::error::PATCH decreased ($main_patch → $pr_patch) without MAJOR or MINOR change. $fail_msg"
exit 1
fi
if [ "$pr_patch" -gt "$main_patch" ]; then
echo "Version OK: $MAIN_VERSION → $PR_VERSION"
exit 0
fi
echo "::error::Version unchanged ($MAIN_VERSION). $fail_msg"
exit 1
tag-commit:
if: github.repository == 'adobe/buildrunner' && github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: [test, get-version]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: main
- name: Tag commit
run: git tag ${{ needs.get-version.outputs.current-version }} && git push --tags
publish-pypi:
if: github.repository == 'adobe/buildrunner' && (github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main'))
runs-on: ubuntu-latest
needs: [test, get-version]
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref == 'refs/heads/main' && 'main' || github.sha }}
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: 3.9
- name: Install dependencies
run: uv sync --locked
- name: Set version
run: uv version --no-sync "${{ needs.get-version.outputs.current-version }}"
- name: Build
run: uv build
- name: Check upload
run: uv run --with twine twine check dist/*
- name: Publish to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
# Only publish on pushes to main
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
user: __token__
password: ${{ secrets.ADOBE_BOT_PYPI_TOKEN }}
publish-docker:
if: github.repository == 'adobe/buildrunner' && (github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main'))
runs-on: ubuntu-latest
needs: [test, get-version]
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref == 'refs/heads/main' && 'main' || github.sha }}
- name: Docker Tags
id: docker_tags
uses: docker/metadata-action@v3
with:
images: ghcr.io/adobe/buildrunner
tags: |
latest
${{ needs.get-version.outputs.current-version }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: linux/amd64,linux/arm64
# Buildx is used to build multi-platform images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# Login to the docker registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
# Only login if this a push to main
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Image
uses: docker/build-push-action@v2
with:
context: .
# Only push images if this is a push to main
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_tags.outputs.tags }}
labels: ${{ steps.docker_tags.outputs.labels }}