-
Notifications
You must be signed in to change notification settings - Fork 13
141 lines (120 loc) · 4.64 KB
/
ci.yml
File metadata and controls
141 lines (120 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: CI - Build, Test, and Publish SDKs
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
version-number:
runs-on: ubuntu-latest
steps:
- name: Set current date in UTC as env variable
run: |
export CURRENT_DATE="$(date -u +'%Y.%m.%d')"
echo "Current date is ${CURRENT_DATE}"
echo "CURRENT_DATE=${CURRENT_DATE}" >> $GITHUB_ENV
- id: build_version
name: Generate Build Version
run: |
export BUILD_VERSION="$CURRENT_DATE.${{ github.run_number }}"
echo "Build version is ${BUILD_VERSION}"
echo "BUILD_VERSION=${BUILD_VERSION}" >> $GITHUB_OUTPUT
- id: package_version
name: Generate Package Version
run: |
export PACKAGE_VERSION="$CURRENT_DATE-preview.${{ github.run_number }}"
echo "Package version is ${PACKAGE_VERSION}"
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
export PYTHON_PACKAGE_VERSION="$CURRENT_DATE+preview.${{ github.run_number }}"
echo "Python package version is ${PYTHON_PACKAGE_VERSION}"
echo "PYTHON_PACKAGE_VERSION=${PYTHON_PACKAGE_VERSION}" >> $GITHUB_OUTPUT
outputs:
BUILD_VERSION: ${{ steps.build_version.outputs.BUILD_VERSION }}
PACKAGE_VERSION: ${{ steps.package_version.outputs.PACKAGE_VERSION }}
PYTHON_PACKAGE_VERSION: ${{ steps.package_version.outputs.PYTHON_PACKAGE_VERSION }}
changed-sdks:
name: Determine Changed SDKs
runs-on: ubuntu-latest
outputs:
python-sdk: ${{ steps.check_python_sdk.outputs.changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: git_refs
name: Set Git refs for diff
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "base=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
echo "head=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
else
echo "base=${{ github.event.before }}" >> "$GITHUB_OUTPUT"
echo "head=${{ github.sha }}" >> "$GITHUB_OUTPUT"
fi
- id: check_python_sdk
name: Check Python SDK changes
run: |
if git diff --name-only "${{ steps.git_refs.outputs.base }}" "${{ steps.git_refs.outputs.head }}" -- 'python/**' | grep -q .; then
echo "Python SDK changes detected"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "No Python SDK changes detected"
echo "changed=false" >> $GITHUB_OUTPUT
fi
python-sdk:
name: Python SDK
needs: [version-number, changed-sdks]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
strategy:
matrix:
python-version: ['3.11', '3.12']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install the latest version of uv and set the python version
uses: astral-sh/setup-uv@v6
with:
version: '0.6.x'
python-version: ${{ matrix.python-version }}
working-directory: ./
enable-cache: true
cache-dependency-glob: "./pyproject.toml"
- name: Install the project
run: uv lock && uv sync --locked --all-extras --dev
- name: Check linting
run: |
uv run --frozen ruff check .
continue-on-error: true
- name: Check formatting
run: |
uv run --frozen ruff format --check .
- name: Build package
run: |
A365_SDK_VERSION=${{ needs.version-number.outputs.PYTHON_PACKAGE_VERSION }} uv build --all-packages --wheel
- name: Run tests
run: |
uv run --frozen python -m pytest tests/ -v --tb=short
# Copy package and samples to drop folder
- name: Copy package and samples to drop folder
run: |
mkdir -p ~/drop/python-${{ matrix.python-version }}/dist && cp -v dist/*.whl $_
# Zip files since upload-artifact does not seem like to like folders
- name: Create zip
run: cd ~/drop/python-${{ matrix.python-version }} && zip -r ~/drop/python-${{ matrix.python-version }}.zip .
- name: Upload package and samples as artifacts
uses: actions/upload-artifact@v4
with:
name: python-${{ matrix.python-version }}
path: ~/drop/python-${{ matrix.python-version }}.zip
- name: Publish
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.changed-sdks.outputs.python-sdk == 'true'
run: |
uv run twine upload --config-file .pypirc -r Agent365 dist/*
continue-on-error: true
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.AZURE_DEVOPS_TOKEN }}