|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - VERSION |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: false |
| 13 | + |
| 14 | +env: |
| 15 | + SEMVER_PATTERN: '^(v)?([0-9]+)\.([0-9]+)\.([0-9]+)(-rc\.([0-9]+))?$' |
| 16 | + |
| 17 | +jobs: |
| 18 | + prepare: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + version: ${{ steps.vars.outputs.version }} |
| 22 | + tag: ${{ steps.vars.outputs.tag }} |
| 23 | + branch: ${{ steps.vars.outputs.branch }} |
| 24 | + is-prerelease: ${{ steps.vars.outputs.is-prerelease }} |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout source code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Validate version and set outputs |
| 33 | + id: vars |
| 34 | + run: | |
| 35 | + RAW_VERSION=$(cat VERSION | tr -d ' \n\r') |
| 36 | + VERSION=${RAW_VERSION#v} |
| 37 | + if [[ ! ${RAW_VERSION} =~ ${{ env.SEMVER_PATTERN }} ]]; then |
| 38 | + echo "Version '${RAW_VERSION}' does not match semver pattern." |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +
|
| 42 | + MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2) |
| 43 | + BRANCH="release-${MAJOR_MINOR}" |
| 44 | + TAG="v${VERSION}" |
| 45 | + IS_PRERELEASE=false |
| 46 | + if [[ ${VERSION} == *"-rc."* ]]; then |
| 47 | + IS_PRERELEASE=true |
| 48 | + fi |
| 49 | +
|
| 50 | + echo "Version '${RAW_VERSION}' matches semver pattern." |
| 51 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 52 | + echo "branch=${BRANCH}" >> $GITHUB_OUTPUT |
| 53 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 54 | + echo "is-prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT |
| 55 | +
|
| 56 | + - name: Ensure tag does not exist |
| 57 | + run: | |
| 58 | + git fetch --tags |
| 59 | + if git tag -l | grep -q "^${{ steps.vars.outputs.tag }}$"; then |
| 60 | + echo "Tag '${{ steps.vars.outputs.tag }}' already exists." |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Check manifests image tag matches version |
| 65 | + run: | |
| 66 | + TAG="${{ steps.vars.outputs.tag }}" |
| 67 | + MANIFEST_TAGS=$(grep -r 'newTag:' manifests | sed 's/.*newTag:[[:space:]]*//' | tr -d '"' | tr -d "'" | sort | uniq) |
| 68 | + if [ -z "$MANIFEST_TAGS" ]; then |
| 69 | + echo "No newTag found in manifests." |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + for t in $MANIFEST_TAGS; do |
| 73 | + if [ "$t" != "$TAG" ]; then |
| 74 | + echo "Image tag in manifests ($t) does not match version tag ($TAG)." |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + done |
| 78 | + echo "All image tags in manifests match version tag $TAG." |
| 79 | +
|
| 80 | + create_branch_and_tag: |
| 81 | + needs: |
| 82 | + - prepare |
| 83 | + runs-on: ubuntu-latest |
| 84 | + permissions: |
| 85 | + contents: write |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Checkout source code |
| 89 | + uses: actions/checkout@v4 |
| 90 | + with: |
| 91 | + fetch-depth: 0 |
| 92 | + |
| 93 | + - name: Configure Git |
| 94 | + run: | |
| 95 | + git config user.name "GitHub Actions" |
| 96 | + git config user.email "actions@github.com" |
| 97 | +
|
| 98 | + - name: Create release branch |
| 99 | + run: | |
| 100 | + BRANCH="${{ needs.prepare.outputs.branch }}" |
| 101 | + git fetch origin |
| 102 | + if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then |
| 103 | + echo "Release branch $BRANCH already exists." |
| 104 | + else |
| 105 | + echo "Creating release branch $BRANCH from $GITHUB_SHA" |
| 106 | + git checkout -b "$BRANCH" "$GITHUB_SHA" |
| 107 | + git push origin "$BRANCH" |
| 108 | + fi |
| 109 | +
|
| 110 | + - name: Create and push tag |
| 111 | + run: | |
| 112 | + git tag -a "${{ needs.prepare.outputs.tag }}" "$GITHUB_SHA" -m "Kubeflow Trainer ${{ needs.prepare.outputs.tag }}" |
| 113 | + git push origin "${{ needs.prepare.outputs.tag }}" |
| 114 | +
|
| 115 | + trigger_builds: |
| 116 | + needs: |
| 117 | + - prepare |
| 118 | + - create_branch_and_tag |
| 119 | + runs-on: ubuntu-latest |
| 120 | + permissions: |
| 121 | + actions: write |
| 122 | + |
| 123 | + steps: |
| 124 | + - name: Trigger image build for release tag |
| 125 | + uses: actions/github-script@v7 |
| 126 | + with: |
| 127 | + script: | |
| 128 | + await github.rest.actions.createWorkflowDispatch({ |
| 129 | + owner: context.repo.owner, |
| 130 | + repo: context.repo.repo, |
| 131 | + workflow_id: 'build-and-push-images.yaml', |
| 132 | + ref: '${{ needs.prepare.outputs.tag }}', |
| 133 | + }) |
| 134 | +
|
| 135 | + - name: Trigger Helm chart publish for release tag |
| 136 | + uses: actions/github-script@v7 |
| 137 | + with: |
| 138 | + script: | |
| 139 | + await github.rest.actions.createWorkflowDispatch({ |
| 140 | + owner: context.repo.owner, |
| 141 | + repo: context.repo.repo, |
| 142 | + workflow_id: 'publish-helm-charts.yaml', |
| 143 | + ref: '${{ needs.prepare.outputs.tag }}', |
| 144 | + }) |
| 145 | +
|
| 146 | + github_release: |
| 147 | + needs: |
| 148 | + - prepare |
| 149 | + - trigger_builds |
| 150 | + permissions: |
| 151 | + contents: write |
| 152 | + runs-on: ubuntu-latest |
| 153 | + |
| 154 | + steps: |
| 155 | + - name: Checkout |
| 156 | + uses: actions/checkout@v4 |
| 157 | + with: |
| 158 | + fetch-depth: 0 |
| 159 | + |
| 160 | + - name: Generate changelog |
| 161 | + id: changelog |
| 162 | + uses: orhun/git-cliff-action@v4 |
| 163 | + with: |
| 164 | + config: cliff.toml |
| 165 | + args: --latest --tag ${{ needs.prepare.outputs.tag }} |
| 166 | + env: |
| 167 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 168 | + |
| 169 | + - name: Create GitHub Release |
| 170 | + uses: softprops/action-gh-release@v2 |
| 171 | + with: |
| 172 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + name: "Kubeflow Trainer ${{ needs.prepare.outputs.tag }}" |
| 174 | + tag_name: ${{ needs.prepare.outputs.tag }} |
| 175 | + target_commitish: ${{ github.sha }} |
| 176 | + prerelease: ${{ needs.prepare.outputs.is-prerelease == 'true' }} |
| 177 | + draft: false |
| 178 | + body: ${{ steps.cliff.outputs.content }} |
0 commit comments