|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - 'release-*' |
| 8 | + paths: |
| 9 | + - 'kubeflow/__init__.py' |
| 10 | + workflow_dispatch: {} |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + id-token: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + prepare: |
| 18 | + name: Prepare release branch |
| 19 | + if: ${{ !(github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-') && github.actor == 'github-actions[bot]') }} |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + version: ${{ steps.vars.outputs.version }} |
| 23 | + branch: ${{ steps.vars.outputs.branch }} |
| 24 | + is-prerelease: ${{ steps.vars.outputs.is-prerelease }} |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Configure git user |
| 31 | + run: | |
| 32 | + git config user.name "github-actions[bot]" |
| 33 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 34 | +
|
| 35 | + - name: Check version and branch |
| 36 | + id: vars |
| 37 | + run: | |
| 38 | + VERSION=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' kubeflow/__init__.py) |
| 39 | + MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2) |
| 40 | + BRANCH=release-$MAJOR_MINOR |
| 41 | +
|
| 42 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 43 | + echo "branch=$BRANCH" >> $GITHUB_OUTPUT |
| 44 | +
|
| 45 | + if [[ "$VERSION" =~ rc[0-9]+$ ]]; then |
| 46 | + echo "is-prerelease=true" >> $GITHUB_OUTPUT |
| 47 | + else |
| 48 | + echo "is-prerelease=false" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Ensure release branch exists and contains version bump |
| 52 | + run: | |
| 53 | + set -euo pipefail |
| 54 | + VERSION="${{ steps.vars.outputs.version }}" |
| 55 | + BRANCH="${{ steps.vars.outputs.branch }}" |
| 56 | + MAIN_SHA="${{ github.sha }}" |
| 57 | +
|
| 58 | + if [[ "${GITHUB_REF_NAME}" == "$BRANCH" ]]; then |
| 59 | + echo "Triggered on $BRANCH. Skipping cherry-pick from main." |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | +
|
| 63 | + if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then |
| 64 | + echo "Using existing branch: $BRANCH" |
| 65 | + git fetch origin "$BRANCH":"$BRANCH" |
| 66 | + git checkout "$BRANCH" |
| 67 | + if git merge-base --is-ancestor "$MAIN_SHA" "$BRANCH"; then |
| 68 | + echo "Commit $MAIN_SHA already present in $BRANCH. Skipping cherry-pick." |
| 69 | + else |
| 70 | + if ! git cherry-pick -x "$MAIN_SHA"; then |
| 71 | + echo "Cherry-pick failed. Please resolve manually on $BRANCH." >&2 |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + fi |
| 75 | + else |
| 76 | + echo "Creating new branch: $BRANCH from main@$MAIN_SHA" |
| 77 | + git checkout -B "$BRANCH" "$MAIN_SHA" |
| 78 | + fi |
| 79 | + git push origin "$BRANCH" |
| 80 | +
|
| 81 | + build: |
| 82 | + name: Build package |
| 83 | + needs: [prepare] |
| 84 | + runs-on: ubuntu-latest |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v4 |
| 87 | + with: |
| 88 | + fetch-depth: 0 |
| 89 | + ref: ${{ needs.prepare.outputs.branch }} |
| 90 | + |
| 91 | + - name: Set up Python |
| 92 | + uses: actions/setup-python@v5 |
| 93 | + with: |
| 94 | + python-version: '3.11' |
| 95 | + |
| 96 | + - name: Setup build environment |
| 97 | + run: | |
| 98 | + make verify |
| 99 | +
|
| 100 | + - name: Run unit tests |
| 101 | + run: | |
| 102 | + make test-python |
| 103 | +
|
| 104 | + - name: Verify version |
| 105 | + run: | |
| 106 | + TAG_VERSION="${{ needs.prepare.outputs.version }}" |
| 107 | + CODE_VERSION="$(python -c "import kubeflow; print(kubeflow.__version__)")" |
| 108 | + echo "Tag version: $TAG_VERSION" |
| 109 | + echo "Code version: $CODE_VERSION" |
| 110 | + if [[ "$TAG_VERSION" != "$CODE_VERSION" ]]; then |
| 111 | + echo "Version mismatch"; exit 1; fi |
| 112 | + echo "Version verified: $TAG_VERSION" |
| 113 | +
|
| 114 | + - name: Build and validate package |
| 115 | + run: | |
| 116 | + uv build |
| 117 | + uvx twine check dist/* |
| 118 | +
|
| 119 | + - name: Upload build artifacts |
| 120 | + uses: actions/upload-artifact@v4 |
| 121 | + with: |
| 122 | + name: dist-${{ needs.prepare.outputs.version }} |
| 123 | + path: dist/ |
| 124 | + |
| 125 | + create-tag: |
| 126 | + name: Create and push tag |
| 127 | + needs: [prepare, build] |
| 128 | + runs-on: ubuntu-latest |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@v4 |
| 131 | + with: |
| 132 | + fetch-depth: 0 |
| 133 | + ref: ${{ needs.prepare.outputs.branch }} |
| 134 | + - name: Create tag |
| 135 | + run: | |
| 136 | + VERSION="${{ needs.prepare.outputs.version }}" |
| 137 | + if git ls-remote --tags origin "$VERSION" | grep -q "refs/tags/$VERSION"; then |
| 138 | + echo "Tag $VERSION already exists. Skipping"; exit 0; fi |
| 139 | + git tag "$VERSION" |
| 140 | + git push origin "$VERSION" |
| 141 | +
|
| 142 | + publish-pypi: |
| 143 | + name: Publish to PyPI |
| 144 | + needs: [prepare, build, create-tag] |
| 145 | + runs-on: ubuntu-latest |
| 146 | + environment: |
| 147 | + name: release |
| 148 | + url: https://pypi.org/project/kubeflow/ |
| 149 | + steps: |
| 150 | + - name: Download build artifacts |
| 151 | + uses: actions/download-artifact@v4 |
| 152 | + with: |
| 153 | + name: dist-${{ needs.prepare.outputs.version }} |
| 154 | + path: dist/ |
| 155 | + - name: Publish to PyPI |
| 156 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 157 | + with: |
| 158 | + verbose: true |
| 159 | + |
| 160 | + github-release: |
| 161 | + name: Create GitHub Release |
| 162 | + needs: [prepare, build, create-tag, publish-pypi] |
| 163 | + runs-on: ubuntu-latest |
| 164 | + environment: |
| 165 | + name: release |
| 166 | + url: https://github.com/kubeflow/sdk/releases |
| 167 | + steps: |
| 168 | + - uses: actions/checkout@v4 |
| 169 | + with: |
| 170 | + fetch-depth: 0 |
| 171 | + ref: ${{ needs.prepare.outputs.branch }} |
| 172 | + - name: Download build artifacts |
| 173 | + uses: actions/download-artifact@v4 |
| 174 | + with: |
| 175 | + name: dist-${{ needs.prepare.outputs.version }} |
| 176 | + path: dist/ |
| 177 | + - name: Extract changelog |
| 178 | + if: needs.prepare.outputs.is-prerelease != 'true' |
| 179 | + id: changelog |
| 180 | + run: | |
| 181 | + VERSION="${{ needs.prepare.outputs.version }}" |
| 182 | + MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2) |
| 183 | + CHANGELOG_FILE="CHANGELOG/CHANGELOG-${MAJOR_MINOR}.md" |
| 184 | + set -euo pipefail |
| 185 | + [[ -f "$CHANGELOG_FILE" ]] || { echo "ERROR: $CHANGELOG_FILE not found" >&2; exit 1; } |
| 186 | + HEADER_REGEX="^# \\[${VERSION//./\\.}\\]" |
| 187 | + SECTION=$(sed -n "/$HEADER_REGEX/,\$p" "$CHANGELOG_FILE" | tail -n +2) |
| 188 | + [[ -n "$SECTION" ]] || { echo "ERROR: No changelog section for $VERSION in $CHANGELOG_FILE" >&2; exit 1; } |
| 189 | + NEXT_VERSION=$(echo "$SECTION" | grep -m1 "^# \\[[0-9]" || true) |
| 190 | + if [[ -n "$NEXT_VERSION" ]]; then |
| 191 | + CHANGELOG=$(echo "$SECTION" | sed -n "1,/^# \\[[0-9]/p" | sed '1d;$d') |
| 192 | + else |
| 193 | + CHANGELOG=$(echo "$SECTION" | sed '1d') |
| 194 | + fi |
| 195 | + [[ -n "$CHANGELOG" ]] || { echo "ERROR: Empty changelog body for $VERSION in $CHANGELOG_FILE" >&2; exit 1; } |
| 196 | + { |
| 197 | + echo "changelog<<EOF" |
| 198 | + echo "$CHANGELOG" |
| 199 | + echo "EOF" |
| 200 | + } >> $GITHUB_OUTPUT |
| 201 | + - name: Create GitHub Release |
| 202 | + uses: softprops/action-gh-release@v1 |
| 203 | + with: |
| 204 | + tag_name: ${{ needs.prepare.outputs.version }} |
| 205 | + name: ${{ needs.prepare.outputs.version }} |
| 206 | + body: ${{ steps.changelog.outputs.changelog }} |
| 207 | + draft: false |
| 208 | + prerelease: ${{ needs.prepare.outputs.is-prerelease == 'true' }} |
| 209 | + generate_release_notes: false |
| 210 | + files: | |
| 211 | + dist/* |
0 commit comments