From 50586526cb43cc9020cee58323b7b5f52920a080 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:21:24 -0400 Subject: [PATCH 01/51] .github --- .github/workflows/dev_version_script.py | 1 - .github/workflows/update_dev_version.yml | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 14acb3bd6f..184f458efa 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -13,7 +13,6 @@ # limitations under the License. import argparse from pathlib import Path -import importlib import re diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 160d9e1e18..444e84d275 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -1,6 +1,8 @@ name: Update dev version automatically on: - pull_request: + pull_request_target: + branches: + - master jobs: update-dev-version: @@ -22,22 +24,21 @@ jobs: - name: Checkout PennyLane-Lightning PR uses: actions/checkout@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} - ref: ${{ github.head_ref }} path: pr - name: Run version update script run: > - python3 pr/.github/workflows/dev_version_script.py + python3 main/.github/workflows/dev_version_script.py --pr-path "./pr" --master-path "./main" - name: Commit and push changes - if: + env: + GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: | cd ./pr if [[ -n $(git status -s) ]]; then - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git config --global user.name "Dev version update bot" + git config --global user.email 'github-ringo-but-quantum@xanadu.ai' + git config --global user.name "ringo-but-quantum" git add . git commit -m 'Auto update version' git push From 3e4b16341dd77da25df3c87c348b960d81cef911 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:24:58 -0400 Subject: [PATCH 02/51] Try with other event --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 444e84d275..fdee1ca54d 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -1,6 +1,6 @@ name: Update dev version automatically on: - pull_request_target: + pull_request: branches: - master From a910ed1632484b31bb1d1b85c2c43838443db962 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:36:59 -0400 Subject: [PATCH 03/51] Try with other event --- .github/workflows/update_dev_version.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index fdee1ca54d..6aecd30502 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -33,6 +33,7 @@ jobs: - name: Commit and push changes env: + PULL_REQUEST_BRANCH_NAME: ${{ github.event.pull_request.head.ref }} GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: | cd ./pr @@ -41,5 +42,5 @@ jobs: git config --global user.name "ringo-but-quantum" git add . git commit -m 'Auto update version' - git push + git push origin "$PULL_REQUEST_BRANCH_NAME" fi From d39c06d00977a5b5baa1273f8c3d27421513d7f9 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:41:29 -0400 Subject: [PATCH 04/51] Try with other event --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 6aecd30502..25b8b2b5c5 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -42,5 +42,5 @@ jobs: git config --global user.name "ringo-but-quantum" git add . git commit -m 'Auto update version' - git push origin "$PULL_REQUEST_BRANCH_NAME" + git push --set-upstream origin "$PULL_REQUEST_BRANCH_NAME" fi From 1bdf2faa14bf541a69fd0bedb54304bf353c8a98 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:42:48 -0400 Subject: [PATCH 05/51] Try with other event --- .github/workflows/update_dev_version.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 25b8b2b5c5..bbe36833df 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -24,6 +24,7 @@ jobs: - name: Checkout PennyLane-Lightning PR uses: actions/checkout@v4 with: + ref: ${{ github.event.pull_request.head.ref }} path: pr - name: Run version update script @@ -33,7 +34,6 @@ jobs: - name: Commit and push changes env: - PULL_REQUEST_BRANCH_NAME: ${{ github.event.pull_request.head.ref }} GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: | cd ./pr @@ -42,5 +42,5 @@ jobs: git config --global user.name "ringo-but-quantum" git add . git commit -m 'Auto update version' - git push --set-upstream origin "$PULL_REQUEST_BRANCH_NAME" + git push fi From 7d79434ae19fead5dfc962686e17612d24afa972 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 18:43:05 +0000 Subject: [PATCH 06/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 3da22800fb..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev28" +__version__ = "0.36.0-dev29" From b34ae52c85c3537871469dcc064d45d827ae1a65 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:52:13 -0400 Subject: [PATCH 07/51] Try invalid token --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index bbe36833df..286a0226d4 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -34,7 +34,7 @@ jobs: - name: Commit and push changes env: - GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} + GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKENa }} run: | cd ./pr if [[ -n $(git status -s) ]]; then From 7916bddd4a74e89bc43c156bc6c9a027bf2e77a0 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:58:21 -0400 Subject: [PATCH 08/51] Try new method --- .github/workflows/update_dev_version.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 286a0226d4..72c7534984 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -24,9 +24,13 @@ jobs: - name: Checkout PennyLane-Lightning PR uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.head.ref }} path: pr + - name: Checkout PR branch + env: + GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} + run: cd pr && gh pr checkout ${{ github.event.pull_request.number }} + - name: Run version update script run: > python3 main/.github/workflows/dev_version_script.py From b58204a412d3fb8ed092c0b1d76485f3e8cfbd13 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:59:46 -0400 Subject: [PATCH 09/51] Revert version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..3da22800fb 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev28" From b44aaa82c5dafa3cecef8009ad032be6cc6858ba Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:05:23 -0400 Subject: [PATCH 10/51] Try persist creds --- .github/workflows/update_dev_version.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 72c7534984..36cbaaba5e 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -25,6 +25,7 @@ jobs: uses: actions/checkout@v4 with: path: pr + persist-credentials: false - name: Checkout PR branch env: From 92db27f68049afc6fe4bce69e757c7f0c0763d7b Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:06:09 -0400 Subject: [PATCH 11/51] Fix token name --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 36cbaaba5e..54e4c9f58c 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -39,7 +39,7 @@ jobs: - name: Commit and push changes env: - GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKENa }} + GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: | cd ./pr if [[ -n $(git status -s) ]]; then From 6d2472c469dfe2ad14a8892de00c5eafe197e271 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:08:02 -0400 Subject: [PATCH 12/51] Fix token name --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 54e4c9f58c..97c055cc94 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -24,8 +24,8 @@ jobs: - name: Checkout PennyLane-Lightning PR uses: actions/checkout@v4 with: + token: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} path: pr - persist-credentials: false - name: Checkout PR branch env: From a2ca5cf5fce1c1d34600af41bba1c3d313f630f4 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 19:08:19 +0000 Subject: [PATCH 13/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 3da22800fb..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev28" +__version__ = "0.36.0-dev29" From 7f2e046804d792bb61a6d291884ec9f67ccf7ee4 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:18:51 -0400 Subject: [PATCH 14/51] Fix token name --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..58da0aa862 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev20" From 8f3c885495d87445c7faf928a9f30abb0d42571b Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:19:56 -0400 Subject: [PATCH 15/51] Try new method --- .github/workflows/dev_version_script.py | 86 +++++++++++------------- .github/workflows/update_dev_version.yml | 3 + 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 184f458efa..80d52f4fde 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -11,73 +11,67 @@ # 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 re import argparse from pathlib import Path -import re +try: + import semver +except ImportError: + raise ImportError("Unable to import semver. Install semver by running `pip install semver`") -VERSION_FILE_PATH = "pennylane_lightning/core/_version.py" +VERSION_FILE_PATH = Path("pennylane_lightning/core/_version.py") -rgx_ver = re.compile('^__version__ = "(.*?)"$') +rgx_ver = re.compile(pattern=r"^__version__ = \"(.*)\"$", flags=re.MULTILINE) -rgx_dev_ver = re.compile("^(\d*\.\d*\.\d*)-dev(\d*)$") +def extract_version(repo_root_path: Path) -> semver.Version: + version_file_path = repo_root_path / VERSION_FILE_PATH + if not version_file_path.exists(): + raise FileNotFoundError(f"Unable to find version file at location {version_file_path}") -def extract_version(package_path): - with package_path.joinpath(VERSION_FILE_PATH).open("r") as f: - for line in f.readlines(): + with version_file_path.open() as f: + for line in f: if line.startswith("__version__"): - line = line.strip() - m = rgx_ver.match(line) - return m.group(1) + if (m := rgx_ver.match(line.strip())) is not None: + return semver.Version.parse(m.group(1)) + raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'") raise ValueError("Cannot parse version") -def is_dev(version_str): - m = rgx_dev_ver.fullmatch(version_str) - return m is not None - +def update_prerelease_version(repo_root_path: Path, new_version: semver.Version): + version_file_path = repo_root_path / VERSION_FILE_PATH + if not version_file_path.exists(): + raise FileNotFoundError(f"Unable to find version file at location {version_file_path}") -def update_dev_version(package_path, version_str): - m = rgx_dev_ver.fullmatch(version_str) - if m.group(2) == "": - curr_dev_ver = 0 - else: - curr_dev_ver = int(m.group(2)) + with version_file_path.open() as f: + lines = [ + rgx_ver.sub(f"__version__ = \"{str(new_version)}\"", line) + for line in f + ] - new_version_str = "{}-dev{}".format(m.group(1), str(curr_dev_ver + 1)) - - lines = [] - with package_path.joinpath(VERSION_FILE_PATH).open("r") as f: - for line in f.readlines(): - if not line.startswith("__version__"): - lines.append(line) - else: - lines.append(f'__version__ = "{new_version_str}"\n') - - with package_path.joinpath(VERSION_FILE_PATH).open("w") as f: + with version_file_path.open("w") as f: f.write("".join(lines)) if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--pr-path", dest="pr", type=str, required=True, help="Path to the PR dir") + parser.add_argument("--pr-path", dest="pr", type=Path, required=True, help="Path to the PR dir") parser.add_argument( - "--master-path", dest="master", type=str, required=True, help="Path to the master dir" + "--master-path", dest="master", type=Path, required=True, help="Path to the master dir" ) args = parser.parse_args() - pr_version = extract_version(Path(args.pr)) - master_version = extract_version(Path(args.master)) - - if pr_version == master_version: - if is_dev(pr_version): - print("Automatically update version string.") - update_dev_version(Path(args.pr), pr_version) - else: - print( - "Even though version of this PR is different from the master, as the PR is not dev, we do nothing." - ) - else: - print("Version of this PR is already different from master. Do nothing.") + pr_version = extract_version(args.pr) + master_version = extract_version(args.master) + + print("Got Package Version from 'master' ->", str(master_version)) + print("Got Package Version from 'pr' ->", str(pr_version)) + + if pr_version <= master_version and pr_version.prerelease: + # This is a prelease and the version needs to be bumped + new_version = master_version.new_prerelease("prerelease") + print("Updating pr package version to ->", str(new_version)) + update_prerelease_version(args.pr, new_version) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 97c055cc94..3fb262690f 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -21,6 +21,9 @@ jobs: with: python-version: '3.9' + - name: Install Python Dependencies + run: pip install semver + - name: Checkout PennyLane-Lightning PR uses: actions/checkout@v4 with: From fe1e1aa5c514f79cb2d02f5c0536ddfcb8404cc4 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:20:45 -0400 Subject: [PATCH 16/51] try pr script --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 3fb262690f..28c48550ab 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -37,7 +37,7 @@ jobs: - name: Run version update script run: > - python3 main/.github/workflows/dev_version_script.py + python3 pr/.github/workflows/dev_version_script.py --pr-path "./pr" --master-path "./main" - name: Commit and push changes From aecbbeb0b7c6516651aa90bac7709164eb6d2c81 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:21:30 -0400 Subject: [PATCH 17/51] Fix bug --- .github/workflows/dev_version_script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 80d52f4fde..1b2063a8aa 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -72,6 +72,6 @@ def update_prerelease_version(repo_root_path: Path, new_version: semver.Version) if pr_version <= master_version and pr_version.prerelease: # This is a prelease and the version needs to be bumped - new_version = master_version.new_prerelease("prerelease") + new_version = master_version.next_version("prerelease") print("Updating pr package version to ->", str(new_version)) update_prerelease_version(args.pr, new_version) From af5c8caefc77a551d820978e9a7012d581acf5df Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 21:22:03 +0000 Subject: [PATCH 18/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 58da0aa862..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev20" +__version__ = "0.36.0-dev29" From ebd7546e0f09eee9384f73c67e3aa05f49e5b624 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:22:42 -0400 Subject: [PATCH 19/51] Trigger CI From 69e5167ebb8615676e58f10a0b36c542b62fb5f7 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:31:30 -0400 Subject: [PATCH 20/51] Add some error handling --- .github/workflows/dev_version_script.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 1b2063a8aa..07964c7a8f 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -35,19 +35,24 @@ def extract_version(repo_root_path: Path) -> semver.Version: for line in f: if line.startswith("__version__"): if (m := rgx_ver.match(line.strip())) is not None: - return semver.Version.parse(m.group(1)) + if not len(m.groups()): + raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'") + parsed_semver = m.group(1) + if not semver.Version.is_valid(parsed_semver): + raise ValueError(f"Invalid semver for __version__. Got: '{parsed_semver}' from line '{line}'") + return semver.Version.parse(parsed_semver) raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'") raise ValueError("Cannot parse version") -def update_prerelease_version(repo_root_path: Path, new_version: semver.Version): +def update_prerelease_version(repo_root_path: Path, version: semver.Version): version_file_path = repo_root_path / VERSION_FILE_PATH if not version_file_path.exists(): raise FileNotFoundError(f"Unable to find version file at location {version_file_path}") with version_file_path.open() as f: lines = [ - rgx_ver.sub(f"__version__ = \"{str(new_version)}\"", line) + rgx_ver.sub(f"__version__ = \"{str(version)}\"", line) for line in f ] @@ -75,3 +80,5 @@ def update_prerelease_version(repo_root_path: Path, new_version: semver.Version) new_version = master_version.next_version("prerelease") print("Updating pr package version to ->", str(new_version)) update_prerelease_version(args.pr, new_version) + else: + print("pr is either not a prerelase, or on a newer prerelease than master ... Nothing to do!") From 524b7a1373439608afebbc99c0c053261e0a0838 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:33:05 -0400 Subject: [PATCH 21/51] Cleanup --- .github/workflows/update_dev_version.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 28c48550ab..d010a892fb 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -31,8 +31,6 @@ jobs: path: pr - name: Checkout PR branch - env: - GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: cd pr && gh pr checkout ${{ github.event.pull_request.number }} - name: Run version update script @@ -41,8 +39,6 @@ jobs: --pr-path "./pr" --master-path "./main" - name: Commit and push changes - env: - GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: | cd ./pr if [[ -n $(git status -s) ]]; then From af523b02af839320830c0483cf6c19f8c29067e5 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:33:56 -0400 Subject: [PATCH 22/51] Cleanup --- .github/workflows/update_dev_version.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index d010a892fb..4dfb200cc8 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -31,6 +31,8 @@ jobs: path: pr - name: Checkout PR branch + env: + GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: cd pr && gh pr checkout ${{ github.event.pull_request.number }} - name: Run version update script From 2485df6de30e3e5934000d728c5c71325488733f Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:34:41 -0400 Subject: [PATCH 23/51] Cleanup --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..6242b80765 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev6" From c805e42e23b9471d89f6520983c58065212c7b8d Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:36:35 -0400 Subject: [PATCH 24/51] Cleanup --- .github/workflows/dev_version_script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 07964c7a8f..edf48cba78 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -75,7 +75,7 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): print("Got Package Version from 'master' ->", str(master_version)) print("Got Package Version from 'pr' ->", str(pr_version)) - if pr_version <= master_version and pr_version.prerelease: + if (pr_version <= master_version) and pr_version.prerelease: # This is a prelease and the version needs to be bumped new_version = master_version.next_version("prerelease") print("Updating pr package version to ->", str(new_version)) From c535d174b82f732a6609d7e711d8058e0bf8f7af Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:38:35 -0400 Subject: [PATCH 25/51] Cleanup --- .github/workflows/dev_version_script.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index edf48cba78..1ba9a1f280 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -75,6 +75,9 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): print("Got Package Version from 'master' ->", str(master_version)) print("Got Package Version from 'pr' ->", str(pr_version)) + print("is pr older?", pr_version <= master_version) + print("is prerelease?", pr_version.prerelease) + if (pr_version <= master_version) and pr_version.prerelease: # This is a prelease and the version needs to be bumped new_version = master_version.next_version("prerelease") From a2f40ff4aeae047d4d39b289e7f84a0fa27037b8 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:45:46 -0400 Subject: [PATCH 26/51] Cleanup --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 6242b80765..58da0aa862 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev6" +__version__ = "0.36.0-dev20" From 4a6e3fcb865a6d3d547fbed9484e99508f4cbbf4 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 21:46:09 +0000 Subject: [PATCH 27/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 58da0aa862..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev20" +__version__ = "0.36.0-dev29" From dd723ea7748927b40b7852658359020d09afdde9 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:52:55 -0400 Subject: [PATCH 28/51] Cleanup --- .github/workflows/dev_version_script.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 1ba9a1f280..b5ed747ea2 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -78,10 +78,13 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): print("is pr older?", pr_version <= master_version) print("is prerelease?", pr_version.prerelease) - if (pr_version <= master_version) and pr_version.prerelease: + if pr_version.prerelease and pr_version.prerelease.startswith("dev"): # This is a prelease and the version needs to be bumped new_version = master_version.next_version("prerelease") - print("Updating pr package version to ->", str(new_version)) - update_prerelease_version(args.pr, new_version) + if pr_version != new_version: + print("Updating pr package version to ->", str(new_version)) + update_prerelease_version(args.pr, new_version) + else: + print("pr is on a newer prerelease than master ... Nothing to do!") else: - print("pr is either not a prerelase, or on a newer prerelease than master ... Nothing to do!") + print("pr is not a dev prerelease ... Nothing to do!") From 6da69bfe308c87ff7335971f4ca7ef7faee251ff Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:53:12 -0400 Subject: [PATCH 29/51] Cleanup --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..512bfe6499 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev1" From ad4bc842bc80359eae05248b0ea0cdcd58cc882f Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 21:54:44 +0000 Subject: [PATCH 30/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 512bfe6499..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev1" +__version__ = "0.36.0-dev29" From ae74bd087db9ea55303cc4d4a5d33c0a523a0136 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:55:57 -0400 Subject: [PATCH 31/51] Cleanup --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..6242b80765 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev6" From 15f88e11d32a50f0f6ec6a0f6b7a30a732d8f821 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 21:56:20 +0000 Subject: [PATCH 32/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 6242b80765..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev6" +__version__ = "0.36.0-dev29" From 5f6c649b15ffed6253d5c3d6be146a5f867cc508 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:07:51 -0400 Subject: [PATCH 33/51] Try new method --- .github/workflows/dev_version_script.py | 10 ++++++++-- pennylane_lightning/core/_version.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index b5ed747ea2..8cc43be9a9 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -79,8 +79,14 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): print("is prerelease?", pr_version.prerelease) if pr_version.prerelease and pr_version.prerelease.startswith("dev"): - # This is a prelease and the version needs to be bumped - new_version = master_version.next_version("prerelease") + # This PR is a dev prelease and the version needs to be bumped + if not master_version.prerelease: + next_prerelease_version = "dev" + elif master_version.prerelease == "dev": + next_prerelease_version = "dev1" + else: + next_prerelease_version = master_version.next_version("prerelease") + new_version = master_version.replace(prerelease=next_prerelease_version) if pr_version != new_version: print("Updating pr package version to ->", str(new_version)) update_prerelease_version(args.pr, new_version) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..52924b52a7 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.1.0-dev" From 5256f8db8e9e18eae798f6689aa866f0726232d3 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 22:08:21 +0000 Subject: [PATCH 34/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 52924b52a7..8e12c73f55 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.1.0-dev" +__version__ = "0.36.0-0.36.0-dev29" From 16e4e3af712a363a3a5cc8f30467e55c1af3d9a7 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:11:07 -0400 Subject: [PATCH 35/51] Try new method --- .github/workflows/dev_version_script.py | 5 +---- pennylane_lightning/core/_version.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 8cc43be9a9..0578ccb2d1 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -75,9 +75,6 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): print("Got Package Version from 'master' ->", str(master_version)) print("Got Package Version from 'pr' ->", str(pr_version)) - print("is pr older?", pr_version <= master_version) - print("is prerelease?", pr_version.prerelease) - if pr_version.prerelease and pr_version.prerelease.startswith("dev"): # This PR is a dev prelease and the version needs to be bumped if not master_version.prerelease: @@ -85,7 +82,7 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): elif master_version.prerelease == "dev": next_prerelease_version = "dev1" else: - next_prerelease_version = master_version.next_version("prerelease") + next_prerelease_version = master_version.next_version("prerelease").prerelease new_version = master_version.replace(prerelease=next_prerelease_version) if pr_version != new_version: print("Updating pr package version to ->", str(new_version)) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 8e12c73f55..52924b52a7 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-0.36.0-dev29" +__version__ = "0.1.0-dev" From eead49469bcf5c114ee53433a4430e61c54d3a7f Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Tue, 16 Apr 2024 22:11:25 +0000 Subject: [PATCH 36/51] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 52924b52a7..547a79e452 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.1.0-dev" +__version__ = "0.36.0-dev29" From 3e849b6fe72d765d081ac6fa973efc5082765bab Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:16:04 -0400 Subject: [PATCH 37/51] Cleanup --- .github/workflows/update_dev_version.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 4dfb200cc8..fd5068d3ae 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -1,6 +1,6 @@ name: Update dev version automatically on: - pull_request: + pull_request_target: branches: - master @@ -37,7 +37,7 @@ jobs: - name: Run version update script run: > - python3 pr/.github/workflows/dev_version_script.py + python3 main/.github/workflows/dev_version_script.py --pr-path "./pr" --master-path "./main" - name: Commit and push changes From adaf7506544345e9688a4049d3de60ecd6857bb5 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:44:40 -0400 Subject: [PATCH 38/51] Try new code --- .github/workflows/dev_version_script.py | 21 +++++++----- .github/workflows/update_dev_version.yml | 41 ++++++++++++++++-------- pennylane_lightning/core/_version.py | 2 +- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 0578ccb2d1..4c2c01de65 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -21,6 +21,8 @@ except ImportError: raise ImportError("Unable to import semver. Install semver by running `pip install semver`") +DEV_PRERELEASE_TAG_PREFIX = "dev" +DEFAULT_PRERELEASE_TAG = "dev1" VERSION_FILE_PATH = Path("pennylane_lightning/core/_version.py") rgx_ver = re.compile(pattern=r"^__version__ = \"(.*)\"$", flags=re.MULTILINE) @@ -75,19 +77,22 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): print("Got Package Version from 'master' ->", str(master_version)) print("Got Package Version from 'pr' ->", str(pr_version)) - if pr_version.prerelease and pr_version.prerelease.startswith("dev"): - # This PR is a dev prelease and the version needs to be bumped - if not master_version.prerelease: - next_prerelease_version = "dev" - elif master_version.prerelease == "dev": - next_prerelease_version = "dev1" + # Only attempt to bump the version if the pull_request is: + # - A prerelease, has `X.Y.Z-prerelease` in _version.py + # - The prerelease startswith `dev`. We do not want to auto bump for non-dev prerelease. + if pr_version.prerelease and pr_version.prerelease.startswith(DEV_PRERELEASE_TAG_PREFIX): + # If master branch does not have a prerelease (for any reason) OR does not have an ending number + # Then default to the starting tag + if not master_version.prerelease or master_version.prerelease == DEV_PRERELEASE_TAG_PREFIX: + next_prerelease_version = DEFAULT_PRERELEASE_TAG else: + # Generate the next prerelease version (eg: dev1 -> dev2) next_prerelease_version = master_version.next_version("prerelease").prerelease new_version = master_version.replace(prerelease=next_prerelease_version) if pr_version != new_version: - print("Updating pr package version to ->", str(new_version)) + print(f"Updating pr package version from -> '{pr_version}', to -> {new_version}") update_prerelease_version(args.pr, new_version) else: - print("pr is on a newer prerelease than master ... Nothing to do!") + print(f"pr is on the expected version '{new_version}' ... Nothing to do!") else: print("pr is not a dev prerelease ... Nothing to do!") diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index fd5068d3ae..2c3edce582 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -1,6 +1,7 @@ name: Update dev version automatically on: - pull_request_target: + # TODO: Change this to `pull_request_target` prior to merging + pull_request: branches: - master @@ -16,14 +17,6 @@ jobs: ref: master path: main - - uses: actions/setup-python@v5 - name: Install Python - with: - python-version: '3.9' - - - name: Install Python Dependencies - run: pip install semver - - name: Checkout PennyLane-Lightning PR uses: actions/checkout@v4 with: @@ -35,18 +28,40 @@ jobs: GITHUB_TOKEN: ${{ secrets.AUTO_UPDATE_VERSION_RINGO_TOKEN }} run: cd pr && gh pr checkout ${{ github.event.pull_request.number }} + - uses: actions/setup-python@v5 + name: Install Python + with: + python-version: '3.9' + + - name: Install Python Dependencies + run: pip install semver + + - name: Capture Current Version in Pull Request + id: old_version + run: echo "version=$(grep -o '"[^"]\+[0-9]\+"' pr/pennylane_lightning/core/_version.py | sed 's/"//g')" >> $GITHUB_OUTPUT + + # TODO: Change this to run from main folder prior to merging - name: Run version update script - run: > - python3 main/.github/workflows/dev_version_script.py - --pr-path "./pr" --master-path "./main" + run: | + python3 \ + pr/.github/workflows/dev_version_script.py \ + --pr-path "${{ github.workspace }}/pr" \ + --master-path "${{ github.workspace }}/main" + + - name: Capture Changed version + id: new_version + run: echo "version=$(grep -o '"[^"]\+[0-9]\+"' pr/pennylane_lightning/core/_version.py | sed 's/"//g')" >> $GITHUB_OUTPUT - name: Commit and push changes + env: + OLD_VERSION: ${{ steps.old_version.outputs.version }} + NEW_VERSION: ${{ steps.new_version.outputs.version }} run: | cd ./pr if [[ -n $(git status -s) ]]; then git config --global user.email 'github-ringo-but-quantum@xanadu.ai' git config --global user.name "ringo-but-quantum" git add . - git commit -m 'Auto update version' + git commit -m "Auto update version from '$OLD_VERSION' to '$NEW_VERSION'" git push fi diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..89f11c0a16 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev" From eeed29204cb70792e3a8b216477d6014d69a41d4 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Wed, 17 Apr 2024 14:47:12 +0000 Subject: [PATCH 39/51] Auto update version from '0.36.0-dev29' to '0.36.0-dev30' --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 547a79e452..7fbbc4aee8 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev29" +__version__ = "0.36.0-dev30" From a961b34622335375071037d8286a7f7022a33b43 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:43:01 -0400 Subject: [PATCH 40/51] Trigger CI From 79d0c8dcac93adfef8481e7d26eb7e8534789433 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:43:08 -0400 Subject: [PATCH 41/51] Trigger CI From 8af044967aaf49f03bd249efea90d1f6b7fc67c6 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:47:09 -0400 Subject: [PATCH 42/51] Add comments. Try high dev version num --- .github/workflows/dev_version_script.py | 6 +++--- pennylane_lightning/core/_version.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 4c2c01de65..d155460031 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -22,7 +22,7 @@ raise ImportError("Unable to import semver. Install semver by running `pip install semver`") DEV_PRERELEASE_TAG_PREFIX = "dev" -DEFAULT_PRERELEASE_TAG = "dev1" +DEV_PRERELEASE_TAG_START = "dev1" VERSION_FILE_PATH = Path("pennylane_lightning/core/_version.py") rgx_ver = re.compile(pattern=r"^__version__ = \"(.*)\"$", flags=re.MULTILINE) @@ -84,9 +84,9 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): # If master branch does not have a prerelease (for any reason) OR does not have an ending number # Then default to the starting tag if not master_version.prerelease or master_version.prerelease == DEV_PRERELEASE_TAG_PREFIX: - next_prerelease_version = DEFAULT_PRERELEASE_TAG + next_prerelease_version = DEV_PRERELEASE_TAG_START else: - # Generate the next prerelease version (eg: dev1 -> dev2) + # Generate the next prerelease version (eg: dev1 -> dev2). Sourcing from master version. next_prerelease_version = master_version.next_version("prerelease").prerelease new_version = master_version.replace(prerelease=next_prerelease_version) if pr_version != new_version: diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 7fbbc4aee8..b7f1855ba7 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev30" +__version__ = "0.36.0-dev99" From 02f6c3e2469973be3a3e097f4a37238e065f5536 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Wed, 17 Apr 2024 15:52:59 +0000 Subject: [PATCH 43/51] Auto update version from '0.36.0-dev99' to '0.36.0-dev30' --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index b7f1855ba7..7fbbc4aee8 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev99" +__version__ = "0.36.0-dev30" From 413aa36f6aa5e2ee0cd7b7b941b3c2a3dc66ef29 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:01:18 -0400 Subject: [PATCH 44/51] Address codefactor annotations --- .github/workflows/dev_version_script.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index d155460031..4fc6aeb4a2 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -18,8 +18,8 @@ try: import semver -except ImportError: - raise ImportError("Unable to import semver. Install semver by running `pip install semver`") +except ImportError as exc: + raise ImportError("Unable to import semver. Install semver by running `pip install semver`") from exc DEV_PRERELEASE_TAG_PREFIX = "dev" DEV_PRERELEASE_TAG_START = "dev1" @@ -29,6 +29,13 @@ def extract_version(repo_root_path: Path) -> semver.Version: + """ + Given the repository root for pennylane-lightning, this function extracts the semver version from + pennylane_lightning/core/_version.py. + + :param repo_root_path: Path to the repository root. + :return: Extracted version a semver.Version object. + """ version_file_path = repo_root_path / VERSION_FILE_PATH if not version_file_path.exists(): raise FileNotFoundError(f"Unable to find version file at location {version_file_path}") From 60d28bfcec8c0abbbde6faf8c558d76e5e543664 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:07:09 -0400 Subject: [PATCH 45/51] Address codefactor annotations --- .github/workflows/dev_version_script.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 4fc6aeb4a2..8592192f79 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -44,7 +44,7 @@ def extract_version(repo_root_path: Path) -> semver.Version: for line in f: if line.startswith("__version__"): if (m := rgx_ver.match(line.strip())) is not None: - if not len(m.groups()): + if not m.groups(): raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'") parsed_semver = m.group(1) if not semver.Version.is_valid(parsed_semver): @@ -55,6 +55,13 @@ def extract_version(repo_root_path: Path) -> semver.Version: def update_prerelease_version(repo_root_path: Path, version: semver.Version): + """ + Updates the version file within pennylane_lightning/core/_version.py. + + :param repo_root_path: Path to the repository root. + :param version: The new version to use within the file. + :return: + """ version_file_path = repo_root_path / VERSION_FILE_PATH if not version_file_path.exists(): raise FileNotFoundError(f"Unable to find version file at location {version_file_path}") From 9570f99b62d361ae508efe9cae5a64441262e644 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:20:57 -0400 Subject: [PATCH 46/51] Undo TODOs --- .github/workflows/update_dev_version.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 2c3edce582..b4f2afb5c0 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -1,7 +1,6 @@ name: Update dev version automatically on: - # TODO: Change this to `pull_request_target` prior to merging - pull_request: + pull_request_target: branches: - master @@ -40,11 +39,10 @@ jobs: id: old_version run: echo "version=$(grep -o '"[^"]\+[0-9]\+"' pr/pennylane_lightning/core/_version.py | sed 's/"//g')" >> $GITHUB_OUTPUT - # TODO: Change this to run from main folder prior to merging - name: Run version update script run: | python3 \ - pr/.github/workflows/dev_version_script.py \ + main/.github/workflows/dev_version_script.py \ --pr-path "${{ github.workspace }}/pr" \ --master-path "${{ github.workspace }}/main" From 270b5255d6a8c1044e22dc26f16707fbc2765541 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:07:27 -0400 Subject: [PATCH 47/51] Address PR comments. Test the new changes --- .github/workflows/dev_version_script.py | 20 ++++++++++---------- .github/workflows/update_dev_version.yml | 4 ++-- pennylane_lightning/core/_version.py | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 8592192f79..033296e33f 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -17,18 +17,18 @@ from pathlib import Path try: - import semver + from semver import Version except ImportError as exc: raise ImportError("Unable to import semver. Install semver by running `pip install semver`") from exc DEV_PRERELEASE_TAG_PREFIX = "dev" -DEV_PRERELEASE_TAG_START = "dev1" +DEV_PRERELEASE_TAG_START = "dev0" VERSION_FILE_PATH = Path("pennylane_lightning/core/_version.py") rgx_ver = re.compile(pattern=r"^__version__ = \"(.*)\"$", flags=re.MULTILINE) -def extract_version(repo_root_path: Path) -> semver.Version: +def extract_version(repo_root_path: Path) -> Version: """ Given the repository root for pennylane-lightning, this function extracts the semver version from pennylane_lightning/core/_version.py. @@ -47,14 +47,14 @@ def extract_version(repo_root_path: Path) -> semver.Version: if not m.groups(): raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'") parsed_semver = m.group(1) - if not semver.Version.is_valid(parsed_semver): + if not Version.is_valid(parsed_semver): raise ValueError(f"Invalid semver for __version__. Got: '{parsed_semver}' from line '{line}'") - return semver.Version.parse(parsed_semver) + return Version.parse(parsed_semver) raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'") raise ValueError("Cannot parse version") -def update_prerelease_version(repo_root_path: Path, version: semver.Version): +def update_prerelease_version(repo_root_path: Path, version: Version): """ Updates the version file within pennylane_lightning/core/_version.py. @@ -89,7 +89,7 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): master_version = extract_version(args.master) print("Got Package Version from 'master' ->", str(master_version)) - print("Got Package Version from 'pr' ->", str(pr_version)) + print("Got Package Version from 'PR' ->", str(pr_version)) # Only attempt to bump the version if the pull_request is: # - A prerelease, has `X.Y.Z-prerelease` in _version.py @@ -104,9 +104,9 @@ def update_prerelease_version(repo_root_path: Path, version: semver.Version): next_prerelease_version = master_version.next_version("prerelease").prerelease new_version = master_version.replace(prerelease=next_prerelease_version) if pr_version != new_version: - print(f"Updating pr package version from -> '{pr_version}', to -> {new_version}") + print(f"Updating PR package version from -> '{pr_version}', to -> {new_version}") update_prerelease_version(args.pr, new_version) else: - print(f"pr is on the expected version '{new_version}' ... Nothing to do!") + print(f"PR is on the expected version '{new_version}' ... Nothing to do!") else: - print("pr is not a dev prerelease ... Nothing to do!") + print("PR is not a dev prerelease ... Nothing to do!") diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index b4f2afb5c0..f644dff740 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -1,6 +1,6 @@ name: Update dev version automatically on: - pull_request_target: + pull_request: branches: - master @@ -42,7 +42,7 @@ jobs: - name: Run version update script run: | python3 \ - main/.github/workflows/dev_version_script.py \ + pr/.github/workflows/dev_version_script.py \ --pr-path "${{ github.workspace }}/pr" \ --master-path "${{ github.workspace }}/main" diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 7fbbc4aee8..134b71b540 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev30" +__version__ = "0.36.0-dev15" From 02aae794c3f25c51257f4e9f27450a6f1729a4d7 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Thu, 18 Apr 2024 15:26:24 +0000 Subject: [PATCH 48/51] Auto update version from '0.36.0-dev31' to '0.36.0-dev32' --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 22ae5e03f5..60d8f6e108 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev31" +__version__ = "0.36.0-dev32" From 40a84e8733cef93ccb3b75e0958c831e40489adf Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:47:14 -0400 Subject: [PATCH 49/51] Set ringo email as secret --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index f644dff740..03cf9d2f48 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -57,7 +57,7 @@ jobs: run: | cd ./pr if [[ -n $(git status -s) ]]; then - git config --global user.email 'github-ringo-but-quantum@xanadu.ai' + git config --global user.email '${{ secrets.AUTO_UPDATE_VERSION_RINGO_EMAIL }}' git config --global user.name "ringo-but-quantum" git add . git commit -m "Auto update version from '$OLD_VERSION' to '$NEW_VERSION'" From 35b9759b49271c563e3c80f572fbb18f649536ea Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:13:17 -0400 Subject: [PATCH 50/51] Update regex to capture new/old version to be more specific. Added if condition to skip push if the output of both match --- .github/workflows/update_dev_version.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 03cf9d2f48..09d08beb52 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -37,20 +37,21 @@ jobs: - name: Capture Current Version in Pull Request id: old_version - run: echo "version=$(grep -o '"[^"]\+[0-9]\+"' pr/pennylane_lightning/core/_version.py | sed 's/"//g')" >> $GITHUB_OUTPUT + run: echo "version=$(grep -o '__version__ = "[^"]\+[0-9]\+"' pr/pennylane_lightning/core/_version.py | cut -d '"' -f 2)" >> $GITHUB_OUTPUT - name: Run version update script run: | python3 \ - pr/.github/workflows/dev_version_script.py \ + main/.github/workflows/dev_version_script.py \ --pr-path "${{ github.workspace }}/pr" \ --master-path "${{ github.workspace }}/main" - name: Capture Changed version id: new_version - run: echo "version=$(grep -o '"[^"]\+[0-9]\+"' pr/pennylane_lightning/core/_version.py | sed 's/"//g')" >> $GITHUB_OUTPUT + run: echo "version=$(grep -o '__version__ = "[^"]\+[0-9]\+"' pr/pennylane_lightning/core/_version.py | cut -d '"' -f 2)" >> $GITHUB_OUTPUT - name: Commit and push changes + if: steps.old_version.outputs.version != steps.new_version.outputs.version env: OLD_VERSION: ${{ steps.old_version.outputs.version }} NEW_VERSION: ${{ steps.new_version.outputs.version }} From 49bdd184164c5ed109455fa1cdc4901cc85b97e2 Mon Sep 17 00:00:00 2001 From: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Date: Thu, 18 Apr 2024 12:14:22 -0400 Subject: [PATCH 51/51] Swap trigger event back to pr_target --- .github/workflows/update_dev_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_dev_version.yml b/.github/workflows/update_dev_version.yml index 09d08beb52..a7c08fb40f 100644 --- a/.github/workflows/update_dev_version.yml +++ b/.github/workflows/update_dev_version.yml @@ -1,6 +1,6 @@ name: Update dev version automatically on: - pull_request: + pull_request_target: branches: - master