Skip to content

Commit

Permalink
CICD: Nightly build first steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen committed Oct 12, 2023
1 parent 9a8a5d9 commit e14549a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 36 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/EVENT_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
30 changes: 0 additions & 30 deletions deploy/change_package_name.py

This file was deleted.

44 changes: 44 additions & 0 deletions deploy/nightly_package_setup.py
Original file line number Diff line number Diff line change
@@ -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()
41 changes: 41 additions & 0 deletions deploy/revert_nightly_setup.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit e14549a

Please sign in to comment.