|
1 | 1 | name: CI - Build, Test, and Publish SDKs |
2 | 2 |
|
| 3 | +# This workflow builds, tests, and publishes Python SDK packages |
| 4 | +# - Builds and tests run on all branches (main, release/*) |
| 5 | +# - Publishing to package repository ONLY happens on release/* branches |
| 6 | +# - Development versions (with 'dev' suffix) are created on all non-tagged commits |
| 7 | +# - Official releases (without 'dev' suffix) require a Git tag on a release/* branch |
| 8 | + |
3 | 9 | on: |
4 | 10 | push: |
5 | | - branches: [ main, master ] |
| 11 | + branches: [ main, "release/*" ] |
6 | 12 | pull_request: |
7 | | - branches: [ main, master ] |
| 13 | + branches: [ main, "release/*" ] |
8 | 14 |
|
9 | 15 | jobs: |
10 | 16 | version-number: |
11 | 17 | runs-on: ubuntu-latest |
12 | 18 | steps: |
13 | | - - name: Set current date in UTC as env variable |
14 | | - run: | |
15 | | - export CURRENT_DATE="$(date -u +'%Y.%m.%d')" |
16 | | - echo "Current date is ${CURRENT_DATE}" |
17 | | - echo "CURRENT_DATE=${CURRENT_DATE}" >> $GITHUB_ENV |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Need full history for git versioning |
| 23 | + |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: '3.11' |
18 | 28 |
|
19 | | - - id: build_version |
20 | | - name: Generate Build Version |
| 29 | + - name: Install setuptools-git-versioning |
21 | 30 | run: | |
22 | | - export BUILD_VERSION="$CURRENT_DATE.${{ github.run_number }}" |
23 | | - echo "Build version is ${BUILD_VERSION}" |
24 | | - echo "BUILD_VERSION=${BUILD_VERSION}" >> $GITHUB_OUTPUT |
| 31 | + python -m pip install --upgrade pip |
| 32 | + python -m pip install setuptools-git-versioning |
25 | 33 |
|
26 | 34 | - id: package_version |
27 | | - name: Generate Package Version |
| 35 | + name: Calculate Package Version |
28 | 36 | run: | |
29 | | - export PACKAGE_VERSION="$CURRENT_DATE-preview.${{ github.run_number }}" |
30 | | - echo "Package version is ${PACKAGE_VERSION}" |
31 | | - echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT |
32 | | - export PYTHON_PACKAGE_VERSION="$CURRENT_DATE+preview.${{ github.run_number }}" |
33 | | - echo "Python package version is ${PYTHON_PACKAGE_VERSION}" |
34 | | - echo "PYTHON_PACKAGE_VERSION=${PYTHON_PACKAGE_VERSION}" >> $GITHUB_OUTPUT |
| 37 | + cd ./versioning |
| 38 | + version=$(python -m setuptools_git_versioning) |
| 39 | + echo "Package version calculated: $version" |
| 40 | + echo "PACKAGE_VERSION=$version" >> $GITHUB_OUTPUT |
35 | 41 |
|
36 | 42 | outputs: |
37 | | - BUILD_VERSION: ${{ steps.build_version.outputs.BUILD_VERSION }} |
38 | 43 | PACKAGE_VERSION: ${{ steps.package_version.outputs.PACKAGE_VERSION }} |
39 | | - PYTHON_PACKAGE_VERSION: ${{ steps.package_version.outputs.PYTHON_PACKAGE_VERSION }} |
40 | 44 |
|
41 | 45 | changed-sdks: |
42 | 46 | name: Determine Changed SDKs |
@@ -110,7 +114,7 @@ jobs: |
110 | 114 |
|
111 | 115 | - name: Build package |
112 | 116 | run: | |
113 | | - A365_SDK_VERSION=${{ needs.version-number.outputs.PYTHON_PACKAGE_VERSION }} uv build --all-packages --wheel |
| 117 | + PackageVersion=${{ needs.version-number.outputs.PACKAGE_VERSION }} uv build --all-packages --wheel |
114 | 118 |
|
115 | 119 | - name: Run unit tests |
116 | 120 | run: | |
@@ -143,7 +147,11 @@ jobs: |
143 | 147 | path: ~/drop/python-${{ matrix.python-version }}.zip |
144 | 148 |
|
145 | 149 | - name: Publish |
146 | | - if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.changed-sdks.outputs.python-sdk == 'true' |
| 150 | + # Only publish when: |
| 151 | + # 1. It's a push event (not a PR) |
| 152 | + # 2. The branch is a release/* branch |
| 153 | + # 3. There are SDK changes |
| 154 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/') && needs.changed-sdks.outputs.python-sdk == 'true' |
147 | 155 | run: | |
148 | 156 | uv run twine upload --config-file .pypirc -r Agent365 dist/* |
149 | 157 | continue-on-error: true |
|
0 commit comments