-
Notifications
You must be signed in to change notification settings - Fork 0
Added auto version bump workflow to this plugin #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jaybsoni
wants to merge
24
commits into
main
Choose a base branch
from
auto_vb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6a1d26a
Added auto version bump workflow to this plugin
Jaybsoni 9d72df8
Apply suggestions from code review
Jaybsoni 0dc2da8
Update .github/workflows/pre_release_version_bump.yml
Jaybsoni 598d0f2
removed decompose_hamiltonian from orquestra device
Jaybsoni a6710af
update python version to 3.7
Jaybsoni 201718c
update pl_version in requirements
Jaybsoni 486a0e4
use pl 0.27
Jaybsoni eba4ec8
update import
Jaybsoni 41ec5c2
print pennylane version
Jaybsoni bf18244
fix version in requirements
Jaybsoni 6ea2065
Merge branch 'main' into auto_vb
antalszava 379ccae
update imports
Jaybsoni 4c4e43d
Update steps/expval.py
Jaybsoni c1cefdb
pin sphinx related package versions
antalszava 4f6f717
pin other package
antalszava 5ccd9e8
Merge branch 'update_decompose_h' of github.com:PennyLaneAI/pennylane…
antalszava e72d493
revert version pinning
antalszava 5a6c0fd
Revert "revert version pinning"
antalszava 06995f5
Update requirements.txt
Jaybsoni 05afdfd
Update requirements.txt
Jaybsoni ddd624e
Update docs URL (#29)
josh146 42d4784
Update setup.py
antalszava 43615d4
Update requirements.txt
antalszava 3e40f2e
Merge branch 'update_decompose_h' into auto_vb
antalszava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Release x.x.x-dev | ||
|
|
||
| ### New features since last release | ||
|
|
||
| ### Breaking changes | ||
|
|
||
| ### Improvements | ||
|
|
||
| ### Documentation | ||
|
|
||
| ### Bug fixes | ||
|
|
||
| ### Contributors | ||
|
|
||
| This release contains contributions from (in alphabetical order): | ||
|
|
||
| --- | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| name: Automated Release Version Bumps | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| post_release_version_bump: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Clone repository | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Install Python | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: '3.9' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install pennylane | ||
|
|
||
| - name: Run version bump | ||
| run: > | ||
| python .github/workflows/vb_script.py | ||
| --version_path "./pennylane_orquestra/_version.py" | ||
| --changelog_path "./CHANGELOG.md" --post_release | ||
|
|
||
| - name: Create Pull Request | ||
| uses: peter-evans/create-pull-request@v3 | ||
| with: | ||
| commit-message: post release version bump | ||
| title: Version Bump | ||
| body: updated changelog and _version.py | ||
| branch: post-release-version-bump | ||
| reviewers: antalszava | ||
| base: master | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Manually Triggered Version Bumps | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
Jaybsoni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| jobs: | ||
| pre_release_version_bump: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Clone repository | ||
| uses: actions/checkout@v2 | ||
| - name: Install Python | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: '3.9' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install pennylane | ||
|
|
||
| - name: Run version bump | ||
| run: > | ||
| python .github/workflows/vb_script.py | ||
| --version_path "./pennylane_orquestra/_version.py" | ||
| --changelog_path "./CHANGELOG.md" --pre_release | ||
|
|
||
| - name: Create Pull Request | ||
| uses: peter-evans/create-pull-request@v3 | ||
| with: | ||
| commit-message: pre release version bump | ||
| title: Version Bump | ||
| body: updated changelog and _version.py | ||
| branch: pre-release-version-bump | ||
| reviewers: antalszava | ||
Jaybsoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| base: master | ||
Jaybsoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| # Copyright 2018-2021 Xanadu Quantum Technologies Inc. | ||
|
|
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import argparse | ||
| import pennylane as qml | ||
| pl_version = '"' + qml.version() + '"' | ||
|
|
||
|
|
||
| def remove_quotes(my_str): | ||
| """ A helper function to remove the quote chars (',") | ||
| from the provided str. | ||
| """ | ||
| clean_str = my_str.replace('"', '') # remove " | ||
| clean_str = clean_str.replace("'", "") # remove ' | ||
| return clean_str | ||
|
|
||
|
|
||
| def bump_version(version_line, pre_release): | ||
| """ A helper function which takes the current version string and | ||
| replaces it with the bumped version depending on the pre/post | ||
| release flag. | ||
|
|
||
| Args: | ||
| version_line (string): The string containing the current | ||
| version of the plugin. | ||
| pre_release (bool): A flag which determines if this is a | ||
| pre-release or post-release version bump. | ||
|
|
||
| Returns: | ||
| resultant_line (string): A string of the same form as the version line | ||
| with the version number replaced with the bumped version. | ||
| bumped_version (string): The bumped version string. | ||
| """ | ||
| data = version_line.split(" ") | ||
| curr_version = data[-1].replace('\n', '') # remove any newline characters | ||
|
|
||
| if pre_release: | ||
| curr_version = pl_version # get current Pennylane version | ||
|
|
||
| split_version = curr_version.split(".") # "0.17.0" --> ["0,17,0"] | ||
| split_version[1] = str(int(split_version[1]) + 1) # take middle value and cast as int and bump it by 1 | ||
|
|
||
| if not pre_release: | ||
| split_version[2] = split_version[2].replace('"', '-dev"') # add -dev, ["0,18,0"] --> ["0,18,0-dev"] | ||
|
|
||
| bumped_version = ".".join(split_version) | ||
| data[-1] = bumped_version | ||
| clean_bumped_version = remove_quotes(bumped_version) | ||
|
|
||
| return " ".join(data), clean_bumped_version | ||
|
|
||
|
|
||
| def update_version_file(path, pre_release=True): | ||
| """ Updates the __version__ attribute in a specific version file. | ||
|
|
||
| Args: | ||
| path (str): The path to the version file. | ||
| pre_release (bool): A flag which determines if this is a | ||
| pre-release or post-release version bump. | ||
|
|
||
| Return: | ||
| new_version (str): The bumped version string. | ||
| """ | ||
| with open(path, 'r', encoding="utf8") as f: | ||
| lines = f.readlines() | ||
|
|
||
| with open(path, 'w', encoding="utf8") as f: | ||
| for line in lines: | ||
| if "__version__" in line.split(' '): | ||
| new_line, new_version = bump_version(line, pre_release) | ||
| f.write(new_line + '\n') | ||
| else: | ||
| f.write(line) | ||
| return new_version | ||
|
|
||
|
|
||
| def remove_empty_headers(lines): | ||
| """ Takes a paragraph (list of strings) and removes sections which are empty. | ||
| Where a section begins with a header (### Header_Title). | ||
|
|
||
| Args: | ||
| lines (list[string]): The paragraph containing the changelog sections. | ||
|
|
||
| Returns: | ||
| cleaned_lines (list[string]): The paragraph with empty sections removed. | ||
| """ | ||
| cleaned_lines = [] | ||
| pntr1 = 0 | ||
|
|
||
| while pntr1 < len(lines): | ||
| is_empty = True | ||
| for pntr2 in range(pntr1 + 1, len(lines)): | ||
| line2 = lines[pntr2] | ||
|
|
||
| if (len(line2) >= 4) and (line2[:4] == "### "): | ||
| if (pntr1 == 0) or (not is_empty): | ||
| cleaned_lines.extend(lines[pntr1:pntr2]) # keep these sections! | ||
|
|
||
| pntr1 = pntr2 | ||
| is_empty = True # reset the empty flag | ||
|
|
||
| elif line2 == '\n': | ||
| pass | ||
|
|
||
| else: | ||
| is_empty = False | ||
|
|
||
| cleaned_lines.extend(lines[pntr1:pntr1+1]) | ||
| pntr1 += 1 | ||
|
|
||
| return cleaned_lines | ||
|
|
||
|
|
||
| def update_changelog(path, new_version, pre_release=True): | ||
| """ Updates the Changelog file depending on whether it's a pre-release | ||
| or post-release version bump. | ||
|
|
||
| Args: | ||
| path (str): The path to the changelog file. | ||
| new_version (str): The bumped version string. | ||
| pre_release (bool): A flag which determines if this is a | ||
| pre-release or post-release version bump. | ||
| """ | ||
| with open(path, 'r', encoding="utf8") as f: | ||
| lines = f.readlines() | ||
| end_of_section_index = 0 | ||
| for index, line in enumerate(lines): | ||
| if (len(line) >= 3) and (line[:3] == "---"): | ||
| end_of_section_index = index | ||
| break | ||
|
|
||
| with open(path, 'w', encoding="utf8") as f: | ||
| if not pre_release: # post_release append template to top of the changelog | ||
| with open("./.github/workflows/changelog_template.txt", 'r', encoding="utf8") as template_f: | ||
| template_lines = template_f.readlines() | ||
| template_lines[0] = template_lines[0].replace('x.x.x-dev', new_version) | ||
| f.writelines(template_lines) | ||
| f.writelines(lines) | ||
|
|
||
| else: # pre_release update the release header and remove any empty headers | ||
| # update release header | ||
| line = lines[0] | ||
| split_line = line.split(" ") | ||
| split_line[-1] = new_version # replace version (split_line = [#, Release, 0.17.0-dev]) | ||
| new_line = " ".join(split_line) + '\n' | ||
| f.write(new_line) | ||
|
|
||
| # remover empty headers | ||
| cleaned_lines = remove_empty_headers(lines[1:end_of_section_index]) | ||
| f.writelines(cleaned_lines) | ||
|
|
||
| # keep the rest of the changelog | ||
| rest_of_changelog_lines = lines[end_of_section_index:] | ||
| f.writelines(rest_of_changelog_lines) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--version_path", type=str, required=True, help="Path to the _version.py file") | ||
| parser.add_argument("--changelog_path", type=str, required=True, help="Path to the changelog") | ||
| parser.add_argument("--pre_release", dest="release_status", action="store_true", | ||
| help="True if this is a pre-release version bump, False if it is post release") | ||
| parser.add_argument("--post_release", dest="release_status", action="store_false", | ||
| help="True if this is a pre-release version bump, False if it is post release") | ||
|
|
||
| args = parser.parse_args() | ||
| updated_version = update_version_file(args.version_path, args.release_status) | ||
| update_changelog(args.changelog_path, updated_version, args.release_status) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.