From 3b81070c270cbb0c0d868eb54943a4032f83f41c Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Wed, 17 Sep 2025 13:37:54 +0000 Subject: [PATCH 01/31] Introduce version bump workflow --- .github/workflows/version-bump.yml | 168 +++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 .github/workflows/version-bump.yml diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml new file mode 100644 index 00000000..0d6a6698 --- /dev/null +++ b/.github/workflows/version-bump.yml @@ -0,0 +1,168 @@ +name: Bump Version + +on: + workflow_dispatch: + inputs: + version_part: + description: 'The part of the version to bump' + required: true + type: choice + default: 'patch' + options: + - major + - minor + - patch + - rc + - release + + create_pr_in_fork: + description: 'Create PR in fork' + required: false + type: boolean + default: false + +jobs: + bump-version: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Bump version + id: version + run: | + import re + import os + + files_to_update = [ + 'pyproject.toml', + 'src/fabric_cli/__init__.py', + 'src/fabric_cli/core/fab_constant.py' + ] + + def increment_version(version, part): + if 'rc' in version: + if '.rc' in version: + base_version, rc_part = version.split('.rc') + else: + base_version, rc_part = version.split('rc') + major, minor, patch = map(int, base_version.split('.')) + rc_num = int(rc_part) + else: + major, minor, patch = map(int, version.split('.')) + rc_num = None + + if part == 'major': + major += 1 + minor = 0 + patch = 0 + rc_num = None + elif part == 'minor': + minor += 1 + patch = 0 + rc_num = None + elif part == 'patch': + patch += 1 + rc_num = None + elif part == 'rc': + if rc_num is not None: + rc_num += 1 + else: + rc_num = 0 + elif part == 'release': + rc_num = None + else: + raise ValueError("Part must be one of 'major', 'minor', 'patch', 'rc', or 'release'") + + return f"{major}.{minor}.{patch}" if rc_num is None else f"{major}.{minor}.{patch}.rc{rc_num}" + + def update_file(file_path, old_version, new_version): + with open(file_path, 'r') as file: + content = file.read() + + content = re.sub(old_version, new_version, content) + + with open(file_path, 'w') as file: + file.write(content) + + part = "${{ github.event.inputs.version_part }}" + + with open('pyproject.toml', 'r') as file: + content = file.read() + current_version = re.search( + r'version\s*=\s*"(\d+\.\d+\.\d+(?:\.?rc\d+)?)', content).group(1) + + new_version = increment_version(current_version, part) + + for file_path in files_to_update: + update_file(file_path, current_version, new_version) + + print(f"::set-output name=new_version::{new_version}") + shell: python + + - name: Create Fork + id: create_fork + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + result-encoding: string + script: | + const { owner, repo } = context.repo; + try { + const fork = await github.rest.repos.createFork({ + owner, + repo, + }); + return fork.data.full_name; + } catch (error) { + if (error.message.includes('fork exists')) { + console.log('Fork already exists, proceeding.'); + // The authenticated user is the owner of the fork + const user = await github.rest.users.getAuthenticated(); + return `${user.data.login}/${repo}`; + } + throw error; + } + + - name: Commit and Push Changes to Fork + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git remote add fork "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ steps.create_fork.outputs.result }}.git" + git checkout -b chore/version-bump-${{ steps.version.outputs.new_version }} + git add pyproject.toml src/fabric_cli/__init__.py src/fabric_cli/core/fab_constant.py + git commit -m "chore(version): bump version to ${{ steps.version.outputs.new_version }}" + git push --set-upstream fork chore/version-bump-${{ steps.version.outputs.new_version }} + + - name: Create Pull Request + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { repo, owner: upstream_owner } = context.repo; + const new_version = "${{ steps.version.outputs.new_version }}"; + const branch = `chore/version-bump-${new_version}`; + const fork_full_name = "${{ steps.create_fork.outputs.result }}"; + const fork_owner = fork_full_name.split('/')[0]; + const create_pr_in_fork = ${{ github.event.inputs.create_pr_in_fork }}; + + const pr_owner = create_pr_in_fork ? fork_owner : upstream_owner; + + await github.rest.pulls.create({ + owner: pr_owner, + repo, + title: `chore(version): bump version to ${new_version}`, + head: `${fork_owner}:${branch}`, + base: 'main', + body: `This PR bumps the version to ${new_version}`, + draft: true + }); \ No newline at end of file From fd4b656ce87a0af0b5f602e0e44b073aa251cf6a Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Wed, 17 Sep 2025 13:39:16 +0000 Subject: [PATCH 02/31] semantic pr --- .github/workflows/semantic-pr.yml | 116 ++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .github/workflows/semantic-pr.yml diff --git a/.github/workflows/semantic-pr.yml b/.github/workflows/semantic-pr.yml new file mode 100644 index 00000000..26b2dec0 --- /dev/null +++ b/.github/workflows/semantic-pr.yml @@ -0,0 +1,116 @@ +# Linter to enforce semantic pull request titles (see https://www.conventionalcommits.org/) +--- +name: 🔍 Semantic PR Validation + +on: + pull_request: + branches: + - main + types: + - opened + - edited + - reopened + - ready_for_review + +permissions: + pull-requests: write + +jobs: + check_pr_title: + name: Check Pull Request Title + runs-on: ubuntu-latest + steps: + - name: Run Semantic PR Validation + id: validation + uses: actions/github-script@v6 + with: + script: | + const prTitle = context.payload.pull_request.title; + const regex = /^(feat|fix|docs|style|refactor|perf|test|chore|build|ci|revert)(\([^)]+\))?(!?): .+/; + + if (!regex.test(prTitle)) { + core.setFailed('Pull request title does not follow Conventional Commits specification. See PR comment for details.'); + } + - name: Handle Invalid Title + if: failure() + uses: actions/github-script@v6 + with: + script: | + const commentMarker = ''; + + const { data: comments } = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const existingComment = comments.find(comment => comment.body.includes(commentMarker)); + + if (!existingComment) { + const message = ` + + Hey there and thank you for your contribution! 👋🏼 + + We require pull request titles to follow the [Conventional Commits](https://www.conventionalcommits.org/) specification and it looks like your proposed title needs to be adjusted. + + A valid title has the format: \`type(scope): subject\` + + **type**: Must be one of the following: + - \`feat\`: A new feature + - \`fix\`: A bug fix + - \`docs\`: Documentation only changes + - \`style\`: Changes that do not affect the meaning of the code (e.g., formatting) + - \`refactor\`: A code change that neither fixes a bug nor adds a feature + - \`perf\`: A code change that improves performance + - \`test\`: Adding missing tests or correcting existing tests + - \`chore\`: Changes to the build process or auxiliary tools + - \`build\`: Changes that affect the build system or external dependencies + - \`ci\`: Changes to CI configuration files and scripts + - \`revert\`: Reverts a previous commit + + **scope** (optional): A noun describing a section of the codebase. + + **subject**: A short description of the code changes. + + Examples: + - \`feat(api): add new endpoint for users\` + - \`fix: correct a typo in the documentation\` + - \`docs(readme): update installation instructions\` + + Please update your pull request title to match this format.`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: message + }); + } + + await github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['invalid'] + }); + - name: Handle Valid Title + if: success() + uses: actions/github-script@v6 + with: + script: | + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const invalidLabel = labels.find(label => label.name === 'invalid'); + + if (invalidLabel) { + await github.rest.issues.removeLabel({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + name: 'invalid', + }); + } \ No newline at end of file From 7531caead1cd0710b77250c821597c61d805c067 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Wed, 17 Sep 2025 14:03:26 +0000 Subject: [PATCH 03/31] Fix semantic pr --- .github/workflows/semantic-pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml index 26b2dec0..3c6b6d11 100644 --- a/.github/workflows/semantic-pull-request.yml +++ b/.github/workflows/semantic-pull-request.yml @@ -13,6 +13,7 @@ on: - ready_for_review permissions: + issues: write pull-requests: write jobs: From 4eaa84bc12f081524ade4ab26095d42efc0ecd54 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Fri, 19 Sep 2025 09:13:18 +0000 Subject: [PATCH 04/31] Dry run and test --- .github/workflows/version-bump.yml | 43 +++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 0d6a6698..52bcde50 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -5,7 +5,7 @@ on: inputs: version_part: description: 'The part of the version to bump' - required: true + required: false type: choice default: 'patch' options: @@ -20,6 +20,17 @@ on: required: false type: boolean default: false + dry_run: + description: 'Run without creating a commit or PR to test version calculation.' + required: false + type: boolean + default: false + + # NOTE: The 'push' trigger is for testing in a fork. + # Please remove it before creating a pull request to the main repository. + push: + branches: + - test-workflow jobs: bump-version: @@ -40,6 +51,7 @@ jobs: run: | import re import os + import subprocess files_to_update = [ 'pyproject.toml', @@ -47,6 +59,26 @@ jobs: 'src/fabric_cli/core/fab_constant.py' ] + def get_version_part_from_commits(): + try: + last_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode().strip() + except subprocess.CalledProcessError: + last_tag = None + + if last_tag: + commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--oneline']).decode().strip() + else: + commits = subprocess.check_output(['git', 'log', '--oneline']).decode().strip() + + if any(commit.startswith('feat!:') or commit.startswith('feat!(') for commit in commits.split('\n')): + return 'major' + elif any(commit.startswith('feat:') or commit.startswith('feat(') for commit in commits.split('\n')): + return 'minor' + elif any(commit.startswith('fix:') or commit.startswith('fix(') for commit in commits.split('\n')): + return 'patch' + else: + return None + def increment_version(version, part): if 'rc' in version: if '.rc' in version: @@ -93,6 +125,12 @@ jobs: file.write(content) part = "${{ github.event.inputs.version_part }}" + if not part: + part = get_version_part_from_commits() + + if not part: + print("No version bump needed based on commit messages.") + exit() with open('pyproject.toml', 'r') as file: content = file.read() @@ -108,6 +146,7 @@ jobs: shell: python - name: Create Fork + if: github.event.inputs.dry_run == false id: create_fork uses: actions/github-script@v6 with: @@ -132,6 +171,7 @@ jobs: } - name: Commit and Push Changes to Fork + if: github.event.inputs.dry_run == false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -144,6 +184,7 @@ jobs: git push --set-upstream fork chore/version-bump-${{ steps.version.outputs.new_version }} - name: Create Pull Request + if: github.event.inputs.dry_run == false uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 4e110435206a7e03270a09702dd60f66742b124b Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Fri, 19 Sep 2025 09:16:28 +0000 Subject: [PATCH 05/31] Add commit --- .github/workflows/version-bump.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 52bcde50..adc17887 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -1,4 +1,4 @@ -name: Bump Version +name: Bump Version test on: workflow_dispatch: From 8f8fc76e6a38f84ad1bcde8b424aaa9efda52cbc Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Fri, 19 Sep 2025 09:17:34 +0000 Subject: [PATCH 06/31] Add commit 2 --- .github/workflows/version-bump.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index adc17887..e71c580f 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -30,7 +30,7 @@ on: # Please remove it before creating a pull request to the main repository. push: branches: - - test-workflow + - test-version-bump-workflow jobs: bump-version: From ebcc8f2388f753073c39294ef22b29930d7a3bdb Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Fri, 19 Sep 2025 09:19:22 +0000 Subject: [PATCH 07/31] Add commit 3 --- .github/workflows/version-bump.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index e71c580f..a61349ea 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -24,7 +24,7 @@ on: description: 'Run without creating a commit or PR to test version calculation.' required: false type: boolean - default: false + default: true # NOTE: The 'push' trigger is for testing in a fork. # Please remove it before creating a pull request to the main repository. From e972a1d2eb207b1ae4a635f4fa871962a197476b Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Fri, 19 Sep 2025 09:24:42 +0000 Subject: [PATCH 08/31] Fix workflow --- .github/workflows/version-bump.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index a61349ea..5c058fb2 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -35,6 +35,8 @@ on: jobs: bump-version: runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Check out code uses: actions/checkout@v3 @@ -146,7 +148,7 @@ jobs: shell: python - name: Create Fork - if: github.event.inputs.dry_run == false + if: '${{ github.event.inputs.dry_run }}' == 'false' id: create_fork uses: actions/github-script@v6 with: @@ -171,7 +173,7 @@ jobs: } - name: Commit and Push Changes to Fork - if: github.event.inputs.dry_run == false + if: '${{ github.event.inputs.dry_run }}' == 'false' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -184,7 +186,7 @@ jobs: git push --set-upstream fork chore/version-bump-${{ steps.version.outputs.new_version }} - name: Create Pull Request - if: github.event.inputs.dry_run == false + if: '${{ github.event.inputs.dry_run }}' == 'false' uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 7c561a489055d147861c0e9fefe3a6e8286e9f36 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Fri, 19 Sep 2025 09:25:32 +0000 Subject: [PATCH 09/31] Fix workflow 2 --- .github/workflows/version-bump.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 5c058fb2..ca7cc032 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -148,7 +148,7 @@ jobs: shell: python - name: Create Fork - if: '${{ github.event.inputs.dry_run }}' == 'false' + if: ${{ github.event.inputs.dry_run }} == false id: create_fork uses: actions/github-script@v6 with: @@ -173,7 +173,7 @@ jobs: } - name: Commit and Push Changes to Fork - if: '${{ github.event.inputs.dry_run }}' == 'false' + if: ${{ github.event.inputs.dry_run }} == false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -186,7 +186,7 @@ jobs: git push --set-upstream fork chore/version-bump-${{ steps.version.outputs.new_version }} - name: Create Pull Request - if: '${{ github.event.inputs.dry_run }}' == 'false' + if: ${{ github.event.inputs.dry_run }} == false uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 5894755e31eba608e92753caf3846aaf3048a5d9 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 07:22:20 +0000 Subject: [PATCH 10/31] Fix tests --- .github/workflows/version-bump.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index ca7cc032..34fcb9ff 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -37,6 +37,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + pull-requests: write steps: - name: Check out code uses: actions/checkout@v3 @@ -148,7 +149,7 @@ jobs: shell: python - name: Create Fork - if: ${{ github.event.inputs.dry_run }} == false + if: github.event.inputs.dry_run == 'false' id: create_fork uses: actions/github-script@v6 with: @@ -173,7 +174,7 @@ jobs: } - name: Commit and Push Changes to Fork - if: ${{ github.event.inputs.dry_run }} == false + if: github.event.inputs.dry_run == 'false' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -186,7 +187,7 @@ jobs: git push --set-upstream fork chore/version-bump-${{ steps.version.outputs.new_version }} - name: Create Pull Request - if: ${{ github.event.inputs.dry_run }} == false + if: github.event.inputs.dry_run == 'false' uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} From aeebbbea61080060e08449ea30a41f25155f79fc Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 07:39:54 +0000 Subject: [PATCH 11/31] Fix test --- .github/workflows/version-bump.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 34fcb9ff..28567861 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -65,13 +65,18 @@ jobs: def get_version_part_from_commits(): try: last_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode().strip() - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as exc: + print(f"Error getting last tag: {exc}") last_tag = None - if last_tag: - commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--oneline']).decode().strip() - else: - commits = subprocess.check_output(['git', 'log', '--oneline']).decode().strip() + try: + if last_tag: + commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--oneline']).decode().strip() + else: + commits = subprocess.check_output(['git', 'log', '--oneline']).decode().strip() + except subprocess.CalledProcessError as exc: + print(f"Error getting commits: {exc}") + commits = [] if any(commit.startswith('feat!:') or commit.startswith('feat!(') for commit in commits.split('\n')): return 'major' From 5ebfc4453294ce706fe079a5f47612da7ec97067 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 07:42:38 +0000 Subject: [PATCH 12/31] test --- .github/workflows/version-bump.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 28567861..e4555f99 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -65,16 +65,17 @@ jobs: def get_version_part_from_commits(): try: last_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode().strip() - except subprocess.CalledProcessError as exc: + except Exception as exc: print(f"Error getting last tag: {exc}") last_tag = None + try: if last_tag: commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--oneline']).decode().strip() else: commits = subprocess.check_output(['git', 'log', '--oneline']).decode().strip() - except subprocess.CalledProcessError as exc: + except Exception as exc: print(f"Error getting commits: {exc}") commits = [] From 3892906524e65ea39b45ee96afd31733c7f37966 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 07:49:56 +0000 Subject: [PATCH 13/31] test --- .github/workflows/version-bump.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index e4555f99..b0fe9555 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -65,11 +65,10 @@ jobs: def get_version_part_from_commits(): try: last_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode().strip() - except Exception as exc: - print(f"Error getting last tag: {exc}") + except subprocess.CalledProcessError as exc: + print(f"Could not get last tag, probably because there are no tags yet. Error: {exc}") last_tag = None - try: if last_tag: commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--oneline']).decode().strip() @@ -77,7 +76,10 @@ jobs: commits = subprocess.check_output(['git', 'log', '--oneline']).decode().strip() except Exception as exc: print(f"Error getting commits: {exc}") - commits = [] + commits = "" + + if not commits: + return None if any(commit.startswith('feat!:') or commit.startswith('feat!(') for commit in commits.split('\n')): return 'major' From cb867fccd7e62d68398379adc4932a80a1aad8ab Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 07:51:58 +0000 Subject: [PATCH 14/31] prints --- .github/workflows/version-bump.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index b0fe9555..54178090 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -69,6 +69,7 @@ jobs: print(f"Could not get last tag, probably because there are no tags yet. Error: {exc}") last_tag = None + print(f"Last tag: {last_tag}") try: if last_tag: commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--oneline']).decode().strip() @@ -78,6 +79,7 @@ jobs: print(f"Error getting commits: {exc}") commits = "" + print(f"Commits: {commits}") if not commits: return None From 6ed8ce4440db52d0a9b5b887a5f3a1d364988e5f Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 07:55:21 +0000 Subject: [PATCH 15/31] print --- .github/workflows/version-bump.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 54178090..e4498279 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -83,6 +83,9 @@ jobs: if not commits: return None + # print for each commit in the log + for commit in commits.split('\n'): + print(f">>> this is a commit: '{commit}' <<<") if any(commit.startswith('feat!:') or commit.startswith('feat!(') for commit in commits.split('\n')): return 'major' elif any(commit.startswith('feat:') or commit.startswith('feat(') for commit in commits.split('\n')): From 82e40e35c5fcd7cebaf7bf650018be46ca78629b Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 08:36:03 +0000 Subject: [PATCH 16/31] enhance --- .github/workflows/version-bump.yml | 38 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index e4498279..1eed3ae8 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -62,6 +62,11 @@ jobs: 'src/fabric_cli/core/fab_constant.py' ] + # Regex patterns for Conventional Commits + feat_pattern = re.compile(r"^feat(\([^)]+\))?:", re.IGNORECASE) + feat_breaking_pattern = re.compile(r"^feat!|^feat!\([^)]*\):", re.IGNORECASE) + fix_pattern = re.compile(r"^fix(\([^)]+\))?:", re.IGNORECASE) + def get_version_part_from_commits(): try: last_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode().strip() @@ -72,9 +77,9 @@ jobs: print(f"Last tag: {last_tag}") try: if last_tag: - commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--oneline']).decode().strip() + commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--merges', '--pretty=format:%B'], text=True).strip() else: - commits = subprocess.check_output(['git', 'log', '--oneline']).decode().strip() + commits = subprocess.check_output(['git', 'log', '--merges', '--pretty=format:%B'], text=True).strip() except Exception as exc: print(f"Error getting commits: {exc}") commits = "" @@ -83,17 +88,26 @@ jobs: if not commits: return None - # print for each commit in the log - for commit in commits.split('\n'): - print(f">>> this is a commit: '{commit}' <<<") - if any(commit.startswith('feat!:') or commit.startswith('feat!(') for commit in commits.split('\n')): - return 'major' - elif any(commit.startswith('feat:') or commit.startswith('feat(') for commit in commits.split('\n')): - return 'minor' - elif any(commit.startswith('fix:') or commit.startswith('fix(') for commit in commits.split('\n')): - return 'patch' + bump_type = get_version_bump(commits) + print(f"Version bump type: {bump_type}") + + # Determine version bump + def get_version_bump(commit_messages: str) -> str | None: + # Split commits by line and strip whitespace + commit_lines = [c.strip() for c in commits.splitlines() if c.strip()] + + # Determine version bump + if any(feat_breaking_pattern.match(c) for c in commit_lines): + bump_type = "major" + elif any(feat_pattern.match(c) for c in commit_lines): + bump_type = "minor" + elif any(fix_pattern.match(c) for c in commit_lines): + bump_type = "patch" else: - return None + bump_type = None + + print(f"bump_type: {bump_type}") + return bump_type def increment_version(version, part): if 'rc' in version: From f1a4c2e4d5d3650f42cb78a1c74a5a6c9d248eed Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 08:39:14 +0000 Subject: [PATCH 17/31] Fix --- .github/workflows/version-bump.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 1eed3ae8..6ec7672d 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -92,7 +92,7 @@ jobs: print(f"Version bump type: {bump_type}") # Determine version bump - def get_version_bump(commit_messages: str) -> str | None: + def get_version_bump(commits: str) -> str | None: # Split commits by line and strip whitespace commit_lines = [c.strip() for c in commits.splitlines() if c.strip()] From 28b8d9f000e7601fbf4cc786032f00e16dc29e85 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 08:44:59 +0000 Subject: [PATCH 18/31] enhance --- .github/workflows/version-bump.yml | 41 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 6ec7672d..8f6cf996 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -55,6 +55,7 @@ jobs: import re import os import subprocess + from collections import defaultdict files_to_update = [ 'pyproject.toml', @@ -93,21 +94,35 @@ jobs: # Determine version bump def get_version_bump(commits: str) -> str | None: - # Split commits by line and strip whitespace - commit_lines = [c.strip() for c in commits.splitlines() if c.strip()] - - # Determine version bump - if any(feat_breaking_pattern.match(c) for c in commit_lines): - bump_type = "major" - elif any(feat_pattern.match(c) for c in commit_lines): - bump_type = "minor" - elif any(fix_pattern.match(c) for c in commit_lines): - bump_type = "patch" + # Collect commits by bump type + bump_commits = defaultdict(list) + + for c in commit_lines: + if feat_breaking_pattern.match(c): + bump_commits['major'].append(c) + elif feat_pattern.match(c): + bump_commits['minor'].append(c) + elif fix_pattern.match(c): + bump_commits['patch'].append(c) + + # Determine bump type: major > minor > patch + if bump_commits['major']: + bump_type = 'major' + elif bump_commits['minor']: + bump_type = 'minor' + elif bump_commits['patch']: + bump_type = 'patch' else: bump_type = None - - print(f"bump_type: {bump_type}") - return bump_type + + # Output results + print(f"Version bump type: {bump_type}") + + for bt in ['major', 'minor', 'patch']: + if bump_commits[bt]: + print(f"\n{bt.upper()} commits ({len(bump_commits[bt])}):") + for commit in bump_commits[bt]: + print(f" {commit}") def increment_version(version, part): if 'rc' in version: From 6e58233e7529a1b31761ef3a68cc64497c1ce11a Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 08:46:14 +0000 Subject: [PATCH 19/31] enhance 2 --- .github/workflows/version-bump.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 8f6cf996..ea9c4489 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -94,7 +94,8 @@ jobs: # Determine version bump def get_version_bump(commits: str) -> str | None: - # Collect commits by bump type + + commit_lines = [c.strip() for c in commits.splitlines() if c.strip()] bump_commits = defaultdict(list) for c in commit_lines: @@ -105,7 +106,6 @@ jobs: elif fix_pattern.match(c): bump_commits['patch'].append(c) - # Determine bump type: major > minor > patch if bump_commits['major']: bump_type = 'major' elif bump_commits['minor']: From 792af63c95a62f5fa5bb644a333b21aa73ee7183 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 09:03:04 +0000 Subject: [PATCH 20/31] Enhance --- .github/scripts/get_version_info.py | 97 +++++++++++++++ .github/scripts/increment_version.py | 66 ++++++++++ .github/scripts/update_files.py | 33 +++++ .github/workflows/version-bump.yml | 174 ++++----------------------- 4 files changed, 222 insertions(+), 148 deletions(-) create mode 100644 .github/scripts/get_version_info.py create mode 100644 .github/scripts/increment_version.py create mode 100644 .github/scripts/update_files.py diff --git a/.github/scripts/get_version_info.py b/.github/scripts/get_version_info.py new file mode 100644 index 00000000..cf6bc7f0 --- /dev/null +++ b/.github/scripts/get_version_info.py @@ -0,0 +1,97 @@ +import os +import re +import subprocess +from collections import defaultdict + +# Regex patterns for Conventional Commits +feat_pattern = re.compile(r"^feat(\([^)]+\))?:", re.IGNORECASE) +feat_breaking_pattern = re.compile(r"^feat!|^feat!\([^)]*\):", re.IGNORECASE) +fix_pattern = re.compile(r"^fix(\([^)]+\))?:", re.IGNORECASE) + + +def get_version_bump_from_commits(last_tag: str | None) -> str | None: + """ + Determines the version bump type ('major', 'minor', 'patch') from commit messages. + """ + try: + if last_tag: + commits = subprocess.check_output( + ["git", "log", f"{last_tag}..HEAD", "--merges", "--pretty=format:%B"], + text=True, + ).strip() + else: + commits = subprocess.check_output( + ["git", "log", "--merges", "--pretty=format:%B"], text=True + ).strip() + except Exception as exc: + print(f"Error getting commits: {exc}") + commits = "" + + if not commits: + return None + + commit_lines = [c.strip() for c in commits.splitlines() if c.strip()] + bump_commits = defaultdict(list) + + for c in commit_lines: + if feat_breaking_pattern.match(c): + bump_commits["major"].append(c) + elif feat_pattern.match(c): + bump_commits["minor"].append(c) + elif fix_pattern.match(c): + bump_commits["patch"].append(c) + + if bump_commits["major"]: + bump_type = "major" + elif bump_commits["minor"]: + bump_type = "minor" + elif bump_commits["patch"]: + bump_type = "patch" + else: + bump_type = None + + print(f"\nVersion bump type from commits: {bump_type}") + for bt in ["major", "minor", "patch"]: + if bump_commits[bt]: + print(f"\n{bt.upper()} commits ({len(bump_commits[bt])}):") + for commit in bump_commits[bt]: + print(f" {commit}") + + return bump_type + + +def main(): + """ + Main function to determine version bump part and current version. + """ + # Determine version part + part = os.environ.get("VERSION_PART_INPUT") + if not part: + try: + last_tag = ( + subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]) + .decode() + .strip() + ) + except subprocess.CalledProcessError as exc: + print( + f"Could not get last tag, probably because there are no tags yet. Error: {exc}" + ) + last_tag = None + print(f"Last tag: {last_tag}") + part = get_version_bump_from_commits(last_tag) + else: + print(f"Got version bump part from input: {part}") + + # Set outputs + with open(os.environ["GITHUB_OUTPUT"], "a") as f: + if part: + f.write(f"part={part}\n") + f.write("bump_needed=true\n") + else: + f.write("bump_needed=false\n") + print("No version bump needed.") + + +if __name__ == "__main__": + main() diff --git a/.github/scripts/increment_version.py b/.github/scripts/increment_version.py new file mode 100644 index 00000000..cf75f742 --- /dev/null +++ b/.github/scripts/increment_version.py @@ -0,0 +1,66 @@ +import os +import re + + +def increment_version(version, part): + if "rc" in version: + if ".rc" in version: + base_version, rc_part = version.split(".rc") + else: + base_version, rc_part = version.split("rc") + major, minor, patch = map(int, base_version.split(".")) + rc_num = int(rc_part) + else: + major, minor, patch = map(int, version.split(".")) + rc_num = None + + if part == "major": + major += 1 + minor = 0 + patch = 0 + rc_num = None + elif part == "minor": + minor += 1 + patch = 0 + rc_num = None + elif part == "patch": + patch += 1 + rc_num = None + elif part == "rc": + if rc_num is not None: + rc_num += 1 + else: + rc_num = 0 + elif part == "release": + rc_num = None + else: + raise ValueError( + "Part must be one of 'major', 'minor', 'patch', 'rc', or 'release'" + ) + + return ( + f"{major}.{minor}.{patch}" + if rc_num is None + else f"{major}.{minor}.{patch}.rc{rc_num}" + ) + + +def main(): + part = os.environ["PART"] + # Get current version from pyproject.toml + with open("pyproject.toml", "r") as file: + content = file.read() + current_version_match = re.search( + r'version\s*=\s*"(\d+\.\d+\.\d+(?:\.?rc\d+)?)', content + ) + if not current_version_match: + raise RuntimeError("Could not find version in pyproject.toml") + current_version = current_version_match.group(1) + new_version = increment_version(current_version, part) + + with open(os.environ["GITHUB_OUTPUT"], "a") as f: + f.write(f"new_version={new_version}\n") + + +if __name__ == "__main__": + main() diff --git a/.github/scripts/update_files.py b/.github/scripts/update_files.py new file mode 100644 index 00000000..a7659799 --- /dev/null +++ b/.github/scripts/update_files.py @@ -0,0 +1,33 @@ +import os +import re + + +def update_file(file_path, old_version, new_version): + with open(file_path, "r") as file: + content = file.read() + + # Use word boundaries to avoid replacing parts of other strings + old_version_pattern = r"\b" + re.escape(old_version) + r"\b" + content = re.sub(old_version_pattern, new_version, content) + + with open(file_path, "w") as file: + file.write(content) + + +def main(): + files_to_update = [ + "pyproject.toml", + "src/fabric_cli/__init__.py", + "src/fabric_cli/core/fab_constant.py", + ] + + old_version = os.environ["OLD_VERSION"] + new_version = os.environ["NEW_VERSION"] + + for file_path in files_to_update: + update_file(file_path, old_version, new_version) + print(f"Updated {file_path} from {old_version} to {new_version}") + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index ea9c4489..3eafc1ca 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -49,149 +49,14 @@ jobs: with: python-version: '3.12' - - name: Bump version - id: version - run: | - import re - import os - import subprocess - from collections import defaultdict - - files_to_update = [ - 'pyproject.toml', - 'src/fabric_cli/__init__.py', - 'src/fabric_cli/core/fab_constant.py' - ] - - # Regex patterns for Conventional Commits - feat_pattern = re.compile(r"^feat(\([^)]+\))?:", re.IGNORECASE) - feat_breaking_pattern = re.compile(r"^feat!|^feat!\([^)]*\):", re.IGNORECASE) - fix_pattern = re.compile(r"^fix(\([^)]+\))?:", re.IGNORECASE) - - def get_version_part_from_commits(): - try: - last_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode().strip() - except subprocess.CalledProcessError as exc: - print(f"Could not get last tag, probably because there are no tags yet. Error: {exc}") - last_tag = None - - print(f"Last tag: {last_tag}") - try: - if last_tag: - commits = subprocess.check_output(['git', 'log', f'{last_tag}..HEAD', '--merges', '--pretty=format:%B'], text=True).strip() - else: - commits = subprocess.check_output(['git', 'log', '--merges', '--pretty=format:%B'], text=True).strip() - except Exception as exc: - print(f"Error getting commits: {exc}") - commits = "" - - print(f"Commits: {commits}") - if not commits: - return None - - bump_type = get_version_bump(commits) - print(f"Version bump type: {bump_type}") - - # Determine version bump - def get_version_bump(commits: str) -> str | None: - - commit_lines = [c.strip() for c in commits.splitlines() if c.strip()] - bump_commits = defaultdict(list) - - for c in commit_lines: - if feat_breaking_pattern.match(c): - bump_commits['major'].append(c) - elif feat_pattern.match(c): - bump_commits['minor'].append(c) - elif fix_pattern.match(c): - bump_commits['patch'].append(c) - - if bump_commits['major']: - bump_type = 'major' - elif bump_commits['minor']: - bump_type = 'minor' - elif bump_commits['patch']: - bump_type = 'patch' - else: - bump_type = None - - # Output results - print(f"Version bump type: {bump_type}") - - for bt in ['major', 'minor', 'patch']: - if bump_commits[bt]: - print(f"\n{bt.upper()} commits ({len(bump_commits[bt])}):") - for commit in bump_commits[bt]: - print(f" {commit}") - - def increment_version(version, part): - if 'rc' in version: - if '.rc' in version: - base_version, rc_part = version.split('.rc') - else: - base_version, rc_part = version.split('rc') - major, minor, patch = map(int, base_version.split('.')) - rc_num = int(rc_part) - else: - major, minor, patch = map(int, version.split('.')) - rc_num = None - - if part == 'major': - major += 1 - minor = 0 - patch = 0 - rc_num = None - elif part == 'minor': - minor += 1 - patch = 0 - rc_num = None - elif part == 'patch': - patch += 1 - rc_num = None - elif part == 'rc': - if rc_num is not None: - rc_num += 1 - else: - rc_num = 0 - elif part == 'release': - rc_num = None - else: - raise ValueError("Part must be one of 'major', 'minor', 'patch', 'rc', or 'release'") - - return f"{major}.{minor}.{patch}" if rc_num is None else f"{major}.{minor}.{patch}.rc{rc_num}" - - def update_file(file_path, old_version, new_version): - with open(file_path, 'r') as file: - content = file.read() - - content = re.sub(old_version, new_version, content) - - with open(file_path, 'w') as file: - file.write(content) - - part = "${{ github.event.inputs.version_part }}" - if not part: - part = get_version_part_from_commits() - - if not part: - print("No version bump needed based on commit messages.") - exit() - - with open('pyproject.toml', 'r') as file: - content = file.read() - current_version = re.search( - r'version\s*=\s*"(\d+\.\d+\.\d+(?:\.?rc\d+)?)', content).group(1) - - new_version = increment_version(current_version, part) - - for file_path in files_to_update: - update_file(file_path, current_version, new_version) - - print(f"::set-output name=new_version::{new_version}") - shell: python + - name: Get version info + id: version_info + run: python .github/scripts/get_version_info.py + env: + VERSION_PART_INPUT: ${{ github.event.inputs.version_part }} - name: Create Fork - if: github.event.inputs.dry_run == 'false' + if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: create_fork uses: actions/github-script@v6 with: @@ -208,34 +73,47 @@ jobs: } catch (error) { if (error.message.includes('fork exists')) { console.log('Fork already exists, proceeding.'); - // The authenticated user is the owner of the fork const user = await github.rest.users.getAuthenticated(); return `${user.data.login}/${repo}`; } throw error; } + - name: Increment version + if: steps.version_info.outputs.bump_needed == 'true' + id: increment_version + run: python .github/scripts/increment_version.py + env: + PART: ${{ steps.version_info.outputs.part }} + + - name: Update files + if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + run: python .github/scripts/update_files.py + env: + OLD_VERSION: ${{ steps.version_info.outputs.current_version }} + NEW_VERSION: ${{ steps.increment_version.outputs.new_version }} + - name: Commit and Push Changes to Fork - if: github.event.inputs.dry_run == 'false' + if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' git remote add fork "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ steps.create_fork.outputs.result }}.git" - git checkout -b chore/version-bump-${{ steps.version.outputs.new_version }} + git checkout -b chore/version-bump-${{ steps.increment_version.outputs.new_version }} git add pyproject.toml src/fabric_cli/__init__.py src/fabric_cli/core/fab_constant.py - git commit -m "chore(version): bump version to ${{ steps.version.outputs.new_version }}" - git push --set-upstream fork chore/version-bump-${{ steps.version.outputs.new_version }} + git commit -m "chore(version): bump version to ${{ steps.increment_version.outputs.new_version }}" + git push --set-upstream fork chore/version-bump-${{ steps.increment_version.outputs.new_version }} - name: Create Pull Request - if: github.event.inputs.dry_run == 'false' + if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const { repo, owner: upstream_owner } = context.repo; - const new_version = "${{ steps.version.outputs.new_version }}"; + const new_version = "${{ steps.increment_version.outputs.new_version }}"; const branch = `chore/version-bump-${new_version}`; const fork_full_name = "${{ steps.create_fork.outputs.result }}"; const fork_owner = fork_full_name.split('/')[0]; From 86d7d14648779e3cc4504a196fafdf645c457c94 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 09:35:19 +0000 Subject: [PATCH 21/31] add print --- .github/scripts/increment_version.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/scripts/increment_version.py b/.github/scripts/increment_version.py index cf75f742..ba173a67 100644 --- a/.github/scripts/increment_version.py +++ b/.github/scripts/increment_version.py @@ -59,8 +59,11 @@ def main(): new_version = increment_version(current_version, part) with open(os.environ["GITHUB_OUTPUT"], "a") as f: + f.write(f"current_version={current_version}\n") f.write(f"new_version={new_version}\n") + print(f"new_version: {new_version}") + if __name__ == "__main__": main() From d9ab836012d1fcd16359b36ab7a5299ccf5ba689 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 10:27:16 +0000 Subject: [PATCH 22/31] test --- .github/workflows/version-bump.yml | 38 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 3eafc1ca..dbf7d0d3 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -61,23 +61,27 @@ jobs: uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} - result-encoding: string script: | + // When running in a fork, we can't fork it again. + // We'll just use the current repo as the 'fork' for testing purposes. const { owner, repo } = context.repo; - try { - const fork = await github.rest.repos.createFork({ - owner, - repo, - }); - return fork.data.full_name; - } catch (error) { - if (error.message.includes('fork exists')) { - console.log('Fork already exists, proceeding.'); - const user = await github.rest.users.getAuthenticated(); - return `${user.data.login}/${repo}`; - } - throw error; - } + console.log(`Forking ${owner}/${repo}...`); + // return `${owner}/${repo}`; + /* try { + const fork = await github.rest.repos.createFork({ + owner, + repo, + }); + return fork.data.full_name; + } catch (error) { + if (error.message.includes('fork exists')) { + console.log('Fork already exists, proceeding.'); + const user = await github.rest.users.getAuthenticated(); + return `${user.data.login}/${repo}`; + } + throw error; + } + */ - name: Increment version if: steps.version_info.outputs.bump_needed == 'true' @@ -100,11 +104,11 @@ jobs: run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git remote add fork "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ steps.create_fork.outputs.result }}.git" git checkout -b chore/version-bump-${{ steps.increment_version.outputs.new_version }} git add pyproject.toml src/fabric_cli/__init__.py src/fabric_cli/core/fab_constant.py git commit -m "chore(version): bump version to ${{ steps.increment_version.outputs.new_version }}" - git push --set-upstream fork chore/version-bump-${{ steps.increment_version.outputs.new_version }} + # git push --set-upstream fork chore/version-bump-${{ steps.increment_version.outputs.new_version }} + git push --set-upstream origin chore/version-bump-${{ steps.increment_version.outputs.new_version }} - name: Create Pull Request if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' From b59e4b939858db3a30c2d469101d8761fc355de2 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 10:28:50 +0000 Subject: [PATCH 23/31] test --- .github/workflows/version-bump.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index dbf7d0d3..debd0f66 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -19,12 +19,12 @@ on: description: 'Create PR in fork' required: false type: boolean - default: false + default: true dry_run: description: 'Run without creating a commit or PR to test version calculation.' required: false type: boolean - default: true + default: false # NOTE: The 'push' trigger is for testing in a fork. # Please remove it before creating a pull request to the main repository. @@ -122,9 +122,10 @@ jobs: const fork_full_name = "${{ steps.create_fork.outputs.result }}"; const fork_owner = fork_full_name.split('/')[0]; const create_pr_in_fork = ${{ github.event.inputs.create_pr_in_fork }}; - + console.log(`Fork full name ${fork_full_name}...`); const pr_owner = create_pr_in_fork ? fork_owner : upstream_owner; - + console.log(`Creating PR in ${pr_owner}/${repo}...`); + /* await github.rest.pulls.create({ owner: pr_owner, repo, @@ -133,4 +134,5 @@ jobs: base: 'main', body: `This PR bumps the version to ${new_version}`, draft: true - }); \ No newline at end of file + }); + */ \ No newline at end of file From 95062b264facb4023af5aa3f766c965dd405f78c Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 10:32:12 +0000 Subject: [PATCH 24/31] test --- .github/scripts/get_version_info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/get_version_info.py b/.github/scripts/get_version_info.py index cf6bc7f0..27508645 100644 --- a/.github/scripts/get_version_info.py +++ b/.github/scripts/get_version_info.py @@ -88,6 +88,7 @@ def main(): if part: f.write(f"part={part}\n") f.write("bump_needed=true\n") + print(f"Version bump part: {part} and bump_needed=true") else: f.write("bump_needed=false\n") print("No version bump needed.") From a6db375c9b4531992380446e092ef8ed0fef4bc1 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 10:35:43 +0000 Subject: [PATCH 25/31] needs --- .github/workflows/version-bump.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index debd0f66..91b2e686 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -58,6 +58,7 @@ jobs: - name: Create Fork if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: create_fork + needs: version_info uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -86,19 +87,24 @@ jobs: - name: Increment version if: steps.version_info.outputs.bump_needed == 'true' id: increment_version + needs: [version_info, create_fork] run: python .github/scripts/increment_version.py env: PART: ${{ steps.version_info.outputs.part }} - name: Update files if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + id: update_files run: python .github/scripts/update_files.py + needs: [version_info, create_fork, increment_version] env: OLD_VERSION: ${{ steps.version_info.outputs.current_version }} NEW_VERSION: ${{ steps.increment_version.outputs.new_version }} - name: Commit and Push Changes to Fork if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + id: commit_and_push + needs: [version_info, create_fork, increment_version, update_files] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -112,6 +118,7 @@ jobs: - name: Create Pull Request if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + needs: [version_info, create_fork, increment_version, update_files, commit_and_push] uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 0c11abdde4df46df5154854d0c31f944b3020883 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 10:56:39 +0000 Subject: [PATCH 26/31] test --- .github/workflows/version-bump.yml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 91b2e686..319ba515 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -31,6 +31,28 @@ on: push: branches: - test-version-bump-workflow + inputs: + version_part: + description: 'The part of the version to bump' + required: false + type: choice + default: 'patch' + options: + - major + - minor + - patch + - rc + - release + create_pr_in_fork: + description: 'Create PR in fork' + required: false + type: boolean + default: true + dry_run: + description: 'Run without creating a commit or PR to test version calculation.' + required: false + type: boolean + default: false jobs: bump-version: @@ -58,7 +80,6 @@ jobs: - name: Create Fork if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: create_fork - needs: version_info uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -87,7 +108,6 @@ jobs: - name: Increment version if: steps.version_info.outputs.bump_needed == 'true' id: increment_version - needs: [version_info, create_fork] run: python .github/scripts/increment_version.py env: PART: ${{ steps.version_info.outputs.part }} @@ -96,15 +116,13 @@ jobs: if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: update_files run: python .github/scripts/update_files.py - needs: [version_info, create_fork, increment_version] env: OLD_VERSION: ${{ steps.version_info.outputs.current_version }} NEW_VERSION: ${{ steps.increment_version.outputs.new_version }} - name: Commit and Push Changes to Fork - if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + if: steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: commit_and_push - needs: [version_info, create_fork, increment_version, update_files] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -118,7 +136,6 @@ jobs: - name: Create Pull Request if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' - needs: [version_info, create_fork, increment_version, update_files, commit_and_push] uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} From dde433e932d81dad917873f67cc4738afb911356 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 12:52:46 +0000 Subject: [PATCH 27/31] fix --- .github/workflows/version-bump.yml | 51 ++++++++++++++---------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 319ba515..306dea58 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -31,28 +31,7 @@ on: push: branches: - test-version-bump-workflow - inputs: - version_part: - description: 'The part of the version to bump' - required: false - type: choice - default: 'patch' - options: - - major - - minor - - patch - - rc - - release - create_pr_in_fork: - description: 'Create PR in fork' - required: false - type: boolean - default: true - dry_run: - description: 'Run without creating a commit or PR to test version calculation.' - required: false - type: boolean - default: false + jobs: bump-version: @@ -77,8 +56,22 @@ jobs: env: VERSION_PART_INPUT: ${{ github.event.inputs.version_part }} + - name: Prepare Inputs + id: prep_inputs + run: | + # For push events, github.event.inputs is empty. We need to provide default values. + # For workflow_dispatch, we'll use the provided inputs or the defaults. + VERSION_PART="${{ github.event.inputs.version_part || 'patch' }}" + DRY_RUN="${{ github.event.inputs.dry_run || 'false' }}" + CREATE_PR_IN_FORK="${{ github.event.inputs.create_pr_in_fork || 'true' }}" + + echo "version_part=${VERSION_PART}" >> $GITHUB_OUTPUT + echo "dry_run=${DRY_RUN}" >> $GITHUB_OUTPUT + echo "create_pr_in_fork=${CREATE_PR_IN_FORK}" >> $GITHUB_OUTPUT + - name: Create Fork - if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + if: steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: create_fork uses: actions/github-script@v6 with: @@ -113,7 +106,8 @@ jobs: PART: ${{ steps.version_info.outputs.part }} - name: Update files - if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + if: steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: update_files run: python .github/scripts/update_files.py env: @@ -131,11 +125,12 @@ jobs: git checkout -b chore/version-bump-${{ steps.increment_version.outputs.new_version }} git add pyproject.toml src/fabric_cli/__init__.py src/fabric_cli/core/fab_constant.py git commit -m "chore(version): bump version to ${{ steps.increment_version.outputs.new_version }}" - # git push --set-upstream fork chore/version-bump-${{ steps.increment_version.outputs.new_version }} - git push --set-upstream origin chore/version-bump-${{ steps.increment_version.outputs.new_version }} + git remote add fork https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ steps.create_fork.outputs.result }}.git + git push --set-upstream fork chore/version-bump-${{ steps.increment_version.outputs.new_version }} - name: Create Pull Request - if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + if: steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -145,7 +140,7 @@ jobs: const branch = `chore/version-bump-${new_version}`; const fork_full_name = "${{ steps.create_fork.outputs.result }}"; const fork_owner = fork_full_name.split('/')[0]; - const create_pr_in_fork = ${{ github.event.inputs.create_pr_in_fork }}; + const create_pr_in_fork = ${{ steps.prep_inputs.outputs.create_pr_in_fork }}; console.log(`Fork full name ${fork_full_name}...`); const pr_owner = create_pr_in_fork ? fork_owner : upstream_owner; console.log(`Creating PR in ${pr_owner}/${repo}...`); From 4a887c44c5c288819a4efd24713b8abcdff6d0c7 Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 13:03:17 +0000 Subject: [PATCH 28/31] test --- .github/workflows/version-bump.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 306dea58..3eeb838d 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -69,6 +69,13 @@ jobs: echo "dry_run=${DRY_RUN}" >> $GITHUB_OUTPUT echo "create_pr_in_fork=${CREATE_PR_IN_FORK}" >> $GITHUB_OUTPUT + - name: Increment version + if: steps.version_info.outputs.bump_needed == 'true' + id: increment_version + run: python .github/scripts/increment_version.py + env: + PART: ${{ steps.version_info.outputs.part }} + - name: Create Fork # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' if: steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' @@ -81,11 +88,12 @@ jobs: // We'll just use the current repo as the 'fork' for testing purposes. const { owner, repo } = context.repo; console.log(`Forking ${owner}/${repo}...`); - // return `${owner}/${repo}`; - /* try { + const new_version = "${{ steps.increment_version.outputs.new_version }}"; + try { const fork = await github.rest.repos.createFork({ owner, repo, + name: `version-bump-${new_version}` }); return fork.data.full_name; } catch (error) { @@ -96,14 +104,6 @@ jobs: } throw error; } - */ - - - name: Increment version - if: steps.version_info.outputs.bump_needed == 'true' - id: increment_version - run: python .github/scripts/increment_version.py - env: - PART: ${{ steps.version_info.outputs.part }} - name: Update files # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' @@ -111,7 +111,7 @@ jobs: id: update_files run: python .github/scripts/update_files.py env: - OLD_VERSION: ${{ steps.version_info.outputs.current_version }} + OLD_VERSION: ${{ steps.increment_version.outputs.current_version }} NEW_VERSION: ${{ steps.increment_version.outputs.new_version }} - name: Commit and Push Changes to Fork @@ -124,7 +124,7 @@ jobs: git config --global user.email 'github-actions[bot]@users.noreply.github.com' git checkout -b chore/version-bump-${{ steps.increment_version.outputs.new_version }} git add pyproject.toml src/fabric_cli/__init__.py src/fabric_cli/core/fab_constant.py - git commit -m "chore(version): bump version to ${{ steps.increment_version.outputs.new_version }}" + git commit -m "chore(version): bump '${{ steps.version_info.outputs.part }}' version to ${{ steps.increment_version.outputs.new_version }}" git remote add fork https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ steps.create_fork.outputs.result }}.git git push --set-upstream fork chore/version-bump-${{ steps.increment_version.outputs.new_version }} @@ -144,7 +144,7 @@ jobs: console.log(`Fork full name ${fork_full_name}...`); const pr_owner = create_pr_in_fork ? fork_owner : upstream_owner; console.log(`Creating PR in ${pr_owner}/${repo}...`); - /* + await github.rest.pulls.create({ owner: pr_owner, repo, @@ -154,4 +154,4 @@ jobs: body: `This PR bumps the version to ${new_version}`, draft: true }); - */ \ No newline at end of file + \ No newline at end of file From 155cefaebb62ba946c98d4cb6b05cfa30562b06a Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 13:14:19 +0000 Subject: [PATCH 29/31] test --- .github/workflows/version-bump.yml | 55 ++++-------------------------- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 3eeb838d..2421ec62 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -15,11 +15,6 @@ on: - rc - release - create_pr_in_fork: - description: 'Create PR in fork' - required: false - type: boolean - default: true dry_run: description: 'Run without creating a commit or PR to test version calculation.' required: false @@ -63,11 +58,8 @@ jobs: # For workflow_dispatch, we'll use the provided inputs or the defaults. VERSION_PART="${{ github.event.inputs.version_part || 'patch' }}" DRY_RUN="${{ github.event.inputs.dry_run || 'false' }}" - CREATE_PR_IN_FORK="${{ github.event.inputs.create_pr_in_fork || 'true' }}" - echo "version_part=${VERSION_PART}" >> $GITHUB_OUTPUT echo "dry_run=${DRY_RUN}" >> $GITHUB_OUTPUT - echo "create_pr_in_fork=${CREATE_PR_IN_FORK}" >> $GITHUB_OUTPUT - name: Increment version if: steps.version_info.outputs.bump_needed == 'true' @@ -76,34 +68,6 @@ jobs: env: PART: ${{ steps.version_info.outputs.part }} - - name: Create Fork - # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' - if: steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' - id: create_fork - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - // When running in a fork, we can't fork it again. - // We'll just use the current repo as the 'fork' for testing purposes. - const { owner, repo } = context.repo; - console.log(`Forking ${owner}/${repo}...`); - const new_version = "${{ steps.increment_version.outputs.new_version }}"; - try { - const fork = await github.rest.repos.createFork({ - owner, - repo, - name: `version-bump-${new_version}` - }); - return fork.data.full_name; - } catch (error) { - if (error.message.includes('fork exists')) { - console.log('Fork already exists, proceeding.'); - const user = await github.rest.users.getAuthenticated(); - return `${user.data.login}/${repo}`; - } - throw error; - } - name: Update files # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' @@ -114,7 +78,7 @@ jobs: OLD_VERSION: ${{ steps.increment_version.outputs.current_version }} NEW_VERSION: ${{ steps.increment_version.outputs.new_version }} - - name: Commit and Push Changes to Fork + - name: Commit and Push Changes if: steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' id: commit_and_push env: @@ -125,8 +89,7 @@ jobs: git checkout -b chore/version-bump-${{ steps.increment_version.outputs.new_version }} git add pyproject.toml src/fabric_cli/__init__.py src/fabric_cli/core/fab_constant.py git commit -m "chore(version): bump '${{ steps.version_info.outputs.part }}' version to ${{ steps.increment_version.outputs.new_version }}" - git remote add fork https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ steps.create_fork.outputs.result }}.git - git push --set-upstream fork chore/version-bump-${{ steps.increment_version.outputs.new_version }} + git push --set-upstream origin chore/version-bump-${{ steps.increment_version.outputs.new_version }} - name: Create Pull Request # if: github.event.inputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' @@ -135,21 +98,15 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const { repo, owner: upstream_owner } = context.repo; + const { owner, repo } = context.repo; const new_version = "${{ steps.increment_version.outputs.new_version }}"; const branch = `chore/version-bump-${new_version}`; - const fork_full_name = "${{ steps.create_fork.outputs.result }}"; - const fork_owner = fork_full_name.split('/')[0]; - const create_pr_in_fork = ${{ steps.prep_inputs.outputs.create_pr_in_fork }}; - console.log(`Fork full name ${fork_full_name}...`); - const pr_owner = create_pr_in_fork ? fork_owner : upstream_owner; - console.log(`Creating PR in ${pr_owner}/${repo}...`); - + await github.rest.pulls.create({ - owner: pr_owner, + owner, repo, title: `chore(version): bump version to ${new_version}`, - head: `${fork_owner}:${branch}`, + head: branch, base: 'main', body: `This PR bumps the version to ${new_version}`, draft: true From 02a1e7966220d55bf470f67f504215fb2379e5ed Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 13:42:18 +0000 Subject: [PATCH 30/31] test --- .github/workflows/version-bump.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 2421ec62..8954ca86 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -111,4 +111,18 @@ jobs: body: `This PR bumps the version to ${new_version}`, draft: true }); - \ No newline at end of file + + - name: Tag new version + if: false || steps.prep_inputs.outputs.dry_run == 'false' && steps.version_info.outputs.bump_needed == 'true' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const new_version = "v${{ steps.increment_version.outputs.new_version }}"; + await github.rest.git.createRef({ + owner, + repo, + ref: `refs/tags/${new_version}`, + sha: context.sha + }); \ No newline at end of file From f5eb726797ae4e06a54a8cfc04dffba73243c83e Mon Sep 17 00:00:00 2001 From: Alon Yeshurun Date: Sun, 21 Sep 2025 14:18:14 +0000 Subject: [PATCH 31/31] test --- azure-pipelines.yml | 103 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..c025af29 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,103 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: none # This pipeline is manually triggered + +parameters: +- name: version_part + displayName: 'The part of the version to bump' + type: string + default: 'patch' + values: + - major + - minor + - patch + - rc + - release +- name: dry_run + displayName: 'Run without creating a commit or PR to test version calculation.' + type: boolean + default: false + +pool: + vmImage: 'ubuntu-latest' + +variables: + # For push events, github.event.inputs is empty. We need to provide default values. + # For workflow_dispatch, we'll use the provided inputs or the defaults. + VERSION_PART: ${{ parameters.version_part }} + DRY_RUN: ${{ parameters.dry_run }} + +jobs: +- job: BumpVersion + displayName: 'Bump Version' + steps: + - checkout: self + persistCredentials: true # Needed to push changes back to the repo + fetchDepth: 0 # Equivalent to fetch-depth: 0 in GitHub Actions + + - task: UsePythonVersion@0 + displayName: 'Set up Python 3.12' + inputs: + versionSpec: '3.12' + + - script: python .github/scripts/get_version_info.py + displayName: 'Get version info' + name: version_info + env: + VERSION_PART_INPUT: $(VERSION_PART) + + - script: python .github/scripts/increment_version.py + displayName: 'Increment version' + name: increment_version + condition: and(succeeded(), eq(variables['version_info.bump_needed'], 'true')) + env: + PART: $(version_info.part) + + - script: python .github/scripts/update_files.py + displayName: 'Update files' + name: update_files + condition: and(succeeded(), eq(variables.DRY_RUN, 'false'), eq(variables['version_info.bump_needed'], 'true')) + env: + OLD_VERSION: $(increment_version.current_version) + NEW_VERSION: $(increment_version.new_version) + + - bash: | + git config --global user.name "fabric-cli-bot" + git config --global user.email "fabric-cli-bot@users.noreply.github.com" + BRANCH_NAME="chore/version-bump-$(increment_version.new_version)" + git checkout -b $BRANCH_NAME + git add pyproject.toml src/fabric_cli/__init__.py src/fabric_cli/core/fab_constant.py + git commit -m "chore(version): bump '$(version_info.part)' version to $(increment_version.new_version)" + git push --set-upstream origin $BRANCH_NAME + echo "##vso[task.setvariable variable=branchName;isOutput=true]$BRANCH_NAME" + displayName: 'Commit and Push Changes' + name: commit_and_push + condition: and(succeeded(), eq(variables.DRY_RUN, 'false'), eq(variables['version_info.bump_needed'], 'true')) + env: + # The System.AccessToken is a special variable that provides a token for the build service + # Ensure the "Project Collection Build Service" has "Contribute" and "Create branch" permissions on the repository + GIT_HTTP_USER_AGENT: "git/2.22.0 (linux)" + GIT_AUTHORIZATION_HEADER: "Authorization: Bearer $(System.AccessToken)" + + + - bash: | + echo "Creating PR for branch $(commit_and_push.branchName)" + curl -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $(System.AccessToken)" \ + -d '{ + "sourceRefName": "refs/heads/$(commit_and_push.branchName)", + "targetRefName": "refs/heads/main", + "title": "chore(version): bump version to $(increment_version.new_version)", + "description": "This PR bumps the version to $(increment_version.new_version)", + "isDraft": true + }' \ + "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.ID)/pullrequests?api-version=6.0" + displayName: 'Create Pull Request' + condition: and(succeeded(), eq(variables.DRY_RUN, 'false'), eq(variables['version_info.bump_needed'], 'true')) + env: + # Ensure the "Project Collection Build Service" has "Contribute to pull requests" permission + SYSTEM_ACCESSTOKEN: $(System.AccessToken) \ No newline at end of file