From e14549a4c7a68deebaa5ac4c77665f0895538559 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 12 Oct 2023 12:41:23 +0100 Subject: [PATCH] CICD: Nightly build first steps --- .github/workflows/EVENT_release.yml | 18 ++++++++---- deploy/change_package_name.py | 30 -------------------- deploy/nightly_package_setup.py | 44 +++++++++++++++++++++++++++++ deploy/revert_nightly_setup.py | 41 +++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 36 deletions(-) delete mode 100644 deploy/change_package_name.py create mode 100644 deploy/nightly_package_setup.py create mode 100644 deploy/revert_nightly_setup.py diff --git a/.github/workflows/EVENT_release.yml b/.github/workflows/EVENT_release.yml index 1281cda0e..b35b55c14 100644 --- a/.github/workflows/EVENT_release.yml +++ b/.github/workflows/EVENT_release.yml @@ -91,23 +91,29 @@ jobs: uses: abatilo/actions-poetry@v2 with: poetry-version: "1.3.1" + - name: Check secrets are set + run: | + if [[ -z "${{ secrets.TEST_PYPI_USERNAME }}" || -z "${{ secrets.TEST_PYPI_PASSWORD }}" ]]; then + echo "TEST_PYPI_USERNAME and TEST_PYPI_PASSWORD must be set" + exit 1 + fi - name: Publish on test.pypi.org env: POETRY_HTTP_BASIC_PYPI_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} run: | - python ./deploy/change_package_name.py darwin-nightly + python ./deploy/nightly_package_setup.py poetry config repositories.test-pypi https://test.pypi.org/legacy/ poetry config http-basic.test-pypi ${{ secrets.TEST_PYPI_USERNAME }} ${{ secrets.TEST_PYPI_PASSWORD }} poetry publish --build --repository test-pypi - python ./deploy/change_package_name.py darwin-py + python ./deploy/revert_nightly_setup.py # Linear tickets update notify_release: - needs: [release, test_release] - if: always() && contains(needs.*.result, 'success') + needs: [release] + if: success() uses: ./.github/workflows/JOB_slack_message.yml secrets: inherit with: @@ -120,8 +126,8 @@ jobs: - ${{ github.event.release.html_url }} notify_failed_release: - needs: [release, test_release] - if: always() && contains(needs.*.result, 'failure') + needs: [release] + if: failure() uses: ./.github/workflows/JOB_slack_message.yml secrets: inherit with: diff --git a/deploy/change_package_name.py b/deploy/change_package_name.py deleted file mode 100644 index e24785952..000000000 --- a/deploy/change_package_name.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Require a single string argument, the new package name -# Example: python change_package_name.py com.example.newname - -from argparse import ArgumentParser - -parser = ArgumentParser(description="Change package name in pyproject.toml") -parser.add_argument("new_package_name", type=str, help="New package name") - - -def main() -> None: - args = parser.parse_args() - new_package_name = args.new_package_name - - with open("pyproject.toml", "r") as f: - lines = f.readlines() - - with open("pyproject.toml", "w") as f: - for line in lines: - if line.startswith("name ="): - line = f'name = "{new_package_name}"\n' - f.write(line) - - print(f"Changed package name to {new_package_name} in pyproject.toml") - - -if __name__ == "__main__": - main() diff --git a/deploy/nightly_package_setup.py b/deploy/nightly_package_setup.py new file mode 100644 index 000000000..216251ecd --- /dev/null +++ b/deploy/nightly_package_setup.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Require a single string argument, the new package name +# Example: python change_package_name.py com.example.newname + +from datetime import datetime +from os import linesep +from pathlib import Path + + +def main() -> None: + epoch_timestring = datetime.now().strftime("%s") + + this_file_path = Path(__file__).parent.resolve() + path_to_pyproject = this_file_path / ".." / "pyproject.toml" + path_to_version = this_file_path / ".." / "version.txt" + + try: + assert path_to_pyproject.exists() + except AssertionError: + print("No pyproject.toml found.") + exit(1) + + lines = path_to_pyproject.read_text().splitlines() + lines_to_write = [] + + for line in lines: + if line.startswith("name ="): + lines_to_write.append('name = "darwin-nightly"\n') + elif line.startswith("version ="): + version = line.split("=")[1].strip() + path_to_version.write_text(version) + lines_to_write.append(f'version = "{epoch_timestring}"\n') + else: + lines_to_write.append(line) + + path_to_pyproject.write_text(linesep.join(lines_to_write)) + + print(f"Set build to a nightly in pyproject.toml - darwin-nightly@{epoch_timestring}") + + +if __name__ == "__main__": + main() diff --git a/deploy/revert_nightly_setup.py b/deploy/revert_nightly_setup.py new file mode 100644 index 000000000..12737b6aa --- /dev/null +++ b/deploy/revert_nightly_setup.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from datetime import datetime +from os import path +from pathlib import Path + + +def main() -> None: + new_package_name = "darwin-py" + + this_file_path = Path(__file__).parent.resolve() + path_to_pyproject = this_file_path / ".." / "pyproject.toml" + path_to_version = this_file_path / ".." / "version.txt" + + try: + assert path_to_pyproject.exists() + assert path_to_version.exists() + except AssertionError: + print("No nightly build in place to revert") + exit(1) + + lines = path_to_pyproject.read_text().splitlines() + new_version = path_to_version.read_text().strip() + + lines_to_write = [] + + for line in lines: + if line.startswith("name ="): + line = f'name = "{new_package_name}"\n' + if line.startswith("version ="): + line = f'version = {new_version}\n' + lines_to_write.append(line) + + path_to_pyproject.write_text("\n".join(lines_to_write)) + + print(f"Changed package name to {new_package_name}@{new_version} in pyproject.toml") + + +if __name__ == "__main__": + main()