|
| 1 | +name: ci |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + tags: |
| 9 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + force_publish_pypi: |
| 13 | + description: "Bypass check to see if action is run on tag and attempt to publish" |
| 14 | + type: boolean |
| 15 | + default: false |
| 16 | + override_uv_version: |
| 17 | + description: "Build with a specific version" |
| 18 | + type: string |
| 19 | + default: "" |
| 20 | + ref: |
| 21 | + description: "ref to run CI against, if different than selected branch" |
| 22 | + type: string |
| 23 | + default: "" |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + build: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 34 | + with: |
| 35 | + ref: ${{ inputs.ref || github.ref }} |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - name: Read .tool-versions |
| 39 | + uses: marocchino/tool-versions-action@18a164fa2b0db1cc1edf7305fcb17ace36d1c306 # v1.2.0 |
| 40 | + id: versions |
| 41 | + |
| 42 | + - name: Install a specific version of uv |
| 43 | + uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1 |
| 44 | + with: |
| 45 | + version: "${{ steps.versions.outputs.uv }}" |
| 46 | + python-version: "${{ steps.versions.outputs.python }}" |
| 47 | + enable-cache: true |
| 48 | + |
| 49 | + - name: Install dependencies |
| 50 | + run: uv sync --frozen |
| 51 | + |
| 52 | + - name: Test with pytest |
| 53 | + run: make test |
| 54 | + |
| 55 | + - name: Archive test_logs |
| 56 | + if: always() |
| 57 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 58 | + with: |
| 59 | + name: test-logs |
| 60 | + path: test_logs/ |
| 61 | + retention-days: 7 |
| 62 | + |
| 63 | + - name: Build wheels |
| 64 | + env: |
| 65 | + UV_DYNAMIC_VERSIONING_BYPASS: ${{ inputs.override_uv_version }} |
| 66 | + run: uv build |
| 67 | + |
| 68 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 69 | + with: |
| 70 | + name: sdk-build |
| 71 | + path: dist/ |
| 72 | + retention-days: 1 |
| 73 | + |
| 74 | + verify-build: |
| 75 | + needs: [build] |
| 76 | + strategy: |
| 77 | + fail-fast: false |
| 78 | + matrix: |
| 79 | + version: ["3.11", "3.12", "3.13"] |
| 80 | + runs-on: ubuntu-latest |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 83 | + with: |
| 84 | + ref: ${{ inputs.ref || github.ref }} |
| 85 | + - uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 |
| 86 | + with: |
| 87 | + name: sdk-build |
| 88 | + path: .github/data/dist/ |
| 89 | + - name: verify download |
| 90 | + run: ls -la .github/data/dist/ |
| 91 | + - uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 |
| 92 | + with: |
| 93 | + context: .github/data/ |
| 94 | + build-args: | |
| 95 | + IMAGE=python:${{ matrix.version }}-slim |
| 96 | +
|
| 97 | + release-build: |
| 98 | + if: ${{ (startsWith(github.ref, 'refs/tags/') && github.event_name != 'workflow_dispatch') || inputs.force_publish_pypi }} |
| 99 | + needs: [verify-build] |
| 100 | + runs-on: ubuntu-latest |
| 101 | + steps: |
| 102 | + - name: Check if version if valid for publishing |
| 103 | + if: ${{ inputs.force_publish_pypi && !startsWith(inputs.ref, 'refs/tags/') }} |
| 104 | + run: | |
| 105 | + VERSION=${{ inputs.override_uv_version }} |
| 106 | + if [ -z "${VAR}" ]; then |
| 107 | + echo "Version override not set, continuing... " |
| 108 | + elif ! $(echo "$VERSION" | grep -q '[a-zA-Z]'); then |
| 109 | + cat << EOF |
| 110 | + Version '${VERSION}' in pyproject.toml is major version. |
| 111 | + Force publishing is only supported for pre-release versions. |
| 112 | + Please create a tag in order to perform a release. |
| 113 | + See here for versioning information: https://packaging.python.org/en/latest/discussions/versioning/ |
| 114 | + EOF |
| 115 | + exit 1 |
| 116 | + else |
| 117 | + echo "Version '${VERSION}' in pyproject.toml is pre-release, continuing... " |
| 118 | + fi |
| 119 | +
|
| 120 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 121 | + with: |
| 122 | + ref: ${{ inputs.ref || github.ref }} |
| 123 | + |
| 124 | + - name: Read .tool-versions |
| 125 | + uses: marocchino/tool-versions-action@18a164fa2b0db1cc1edf7305fcb17ace36d1c306 # v1.2.0 |
| 126 | + id: versions |
| 127 | + |
| 128 | + - name: Install a specific version of uv |
| 129 | + uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca # v6.0.1 |
| 130 | + with: |
| 131 | + version: "${{ steps.versions.outputs.uv }}" |
| 132 | + python-version: "${{ steps.versions.outputs.python }}" |
| 133 | + enable-cache: true |
| 134 | + |
| 135 | + - uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 |
| 136 | + with: |
| 137 | + name: sdk-build |
| 138 | + path: dist/ |
| 139 | + - name: Create release and upload assets |
| 140 | + if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name != 'workflow_dispatch' }} |
| 141 | + uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # v2.2.2 |
| 142 | + with: |
| 143 | + files: dist/f5_ai_gateway_sdk* |
| 144 | + generate_release_notes: true |
| 145 | + |
| 146 | + - name: Publish to Artifactory |
| 147 | + if: ${{ startsWith(github.ref, 'refs/tags/') || inputs.force_publish_pypi }} |
| 148 | + run: | |
| 149 | + mkdir -p ~/.config/uv |
| 150 | + cat <<EOF > ~/.config/uv/uv.toml |
| 151 | + [[index]] |
| 152 | + name = "f5-artifactory" |
| 153 | + url = "https://${{ secrets.ARTIFACTORY_HOST }}/artifactory/api/pypi/f5-aigw-pypi/simple" |
| 154 | + publish-url = "https://${{ secrets.ARTIFACTORY_HOST }}/artifactory/api/pypi/f5-aigw-pypi" |
| 155 | + explicit = true |
| 156 | + EOF |
| 157 | + uv publish --index f5-artifactory --username ${{ secrets.ARTIFACTORY_USER }} --password ${{ secrets.ARTIFACTORY_PASSWORD }} |
0 commit comments