Create Tag and Bump for Next Release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create Tag and Bump for Next Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: # The new release tag to be created and used as the search value. | |
| description: 'New release tag (e.g., odh-v2.35)' | |
| required: true | |
| type: string | |
| next_tag_name: # The next tag to replace the current one in the Konflux files. | |
| description: 'Next development cycle tag: (e.g., odh-v2.36)' | |
| required: true | |
| type: string | |
| # | |
| # Note: This workflow assumes the release tag and image tags are in sync. | |
| # 'tag_name' is used to create the release and as the value to find in konflux files. | |
| # 'next_tag_name' provides the new value to set. | |
| # | |
| permissions: | |
| contents: write | |
| packages: write | |
| pull-requests: write | |
| env: | |
| TAG_NAME: ${{ github.event.inputs.tag_name }} | |
| NEXT_TAG_NAME: ${{ github.event.inputs.next_tag_name }} | |
| jobs: | |
| validate-tag: | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref_name, 'release-') | |
| steps: | |
| - name: Validate tag format | |
| run: | | |
| if [[ "$TAG_NAME" == "$NEXT_TAG_NAME" ]]; then | |
| echo "Error: tag name and next tag name must be different (both are: $TAG_NAME)" | |
| exit 1 | |
| fi | |
| if [[ ! "$TAG_NAME" =~ ^odh-v[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: tag name format invalid: $TAG_NAME (expected format: odh-vX.Y, e.g., odh-v2.35)" | |
| exit 1 | |
| fi | |
| if [[ ! "$NEXT_TAG_NAME" =~ ^odh-v[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: next tag name format invalid: $NEXT_TAG_NAME (expected format: odh-vX.Y, e.g., odh-v2.36)" | |
| exit 1 | |
| fi | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Validate current tag presence in mlserver-push.yaml | |
| run: | | |
| if [[ ! -f .tekton/mlserver-push.yaml ]]; then | |
| echo "Error: .tekton/mlserver-push.yaml not found" | |
| exit 1 | |
| fi | |
| if ! grep -q "mlserver:$TAG_NAME" .tekton/mlserver-push.yaml; then | |
| echo "Error: Tag $TAG_NAME not found in .tekton/mlserver-push.yaml" | |
| exit 1 | |
| fi | |
| fetch-tag: | |
| runs-on: ubuntu-latest | |
| needs: validate-tag | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| fetch-depth: 0 | |
| - name: Get latest tag | |
| id: get_tag | |
| run: | | |
| echo "old_tag_name=$(git for-each-ref --sort=creatordate --format '%(refname)' refs/tags | awk -F'/' '{print $3}' | tail -n1)" >> $GITHUB_OUTPUT | |
| - name: Print tags | |
| run: | | |
| echo "Old Tag=${{ steps.get_tag.outputs.old_tag_name }}" | |
| echo "New Tag=$TAG_NAME" | |
| echo "Next Tag=$NEXT_TAG_NAME" | |
| echo "$(basename ${{ github.ref }})" | |
| - name: Check if tag exists | |
| run: | | |
| import sys | |
| import subprocess | |
| import os | |
| tag_name = os.environ['TAG_NAME'] | |
| command = ['git', 'tag', '-l', tag_name] | |
| output = subprocess.check_output(command, stderr=subprocess.STDOUT) | |
| if output.decode() != "": | |
| print(f"Error: Tag '{tag_name}' already exists.", file=sys.stderr) | |
| sys.exit(1) | |
| else: | |
| print(f"Tag '{tag_name}' does not exist.") | |
| shell: python | |
| continue-on-error: false | |
| create-tag: | |
| runs-on: ubuntu-latest | |
| needs: fetch-tag | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Create Tag | |
| run: | | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "Release Bot" | |
| git tag -a $TAG_NAME -m "Release $TAG_NAME" | |
| git push origin $TAG_NAME | |
| bump-tag: | |
| runs-on: ubuntu-latest | |
| needs: create-tag | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Update mlserver-push.yaml with next tag | |
| run: | | |
| echo "Updating mlserver image tag from $TAG_NAME to $NEXT_TAG_NAME in .tekton/mlserver-push.yaml..." | |
| sed -i "s|mlserver:$TAG_NAME|mlserver:$NEXT_TAG_NAME|g" .tekton/mlserver-push.yaml | |
| echo "Update complete." | |
| - name: Create Pull Request | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| # Check if there are any changes to commit | |
| if [[ -z "$(git status --porcelain)" ]]; then | |
| echo "No changes to commit. Exiting." | |
| else | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "Release Bot" | |
| # Create a new branch for the PR | |
| BRANCH_NAME="bump-tag-$NEXT_TAG_NAME" | |
| git checkout -b "$BRANCH_NAME" | |
| # Stage and commit changes | |
| git add .tekton/mlserver-push.yaml | |
| git commit -m "chore(konflux): Bump release tag to $NEXT_TAG_NAME" | |
| git push -u origin "$BRANCH_NAME" | |
| # Create pull request using GitHub CLI | |
| gh pr create \ | |
| --title "chore(konflux): Bump release tag to $NEXT_TAG_NAME" \ | |
| --body "$(cat <<EOF | |
| ## Description | |
| - Updated image tag reference in Konflux configuration | |
| - Part of the release preparation workflow for $TAG_NAME | |
| ## Changes | |
| - Release tag updated from \`$TAG_NAME\` to \`$NEXT_TAG_NAME\` in \`.tekton/mlserver-push.yaml\` | |
| 🤖 Generated with GitHub Actions | |
| EOF | |
| )" \ | |
| --base ${{ github.ref_name }} \ | |
| --head "$BRANCH_NAME" | |
| fi |