diff --git a/.github/workflows/EVENT_pull_request.yml b/.github/workflows/EVENT_pull_request.yml index 4c4c1df46..de477c3e6 100644 --- a/.github/workflows/EVENT_pull_request.yml +++ b/.github/workflows/EVENT_pull_request.yml @@ -31,15 +31,15 @@ jobs: with: files: ${{ needs.get_changed_files.outputs.python_changed_files }} - typecheck: - name: Analyse types in python - needs: get_changed_files - uses: ./.github/workflows/JOB_typecheck.yml - with: - files: ${{ needs.get_changed_files.outputs.python_changed_files }} + # typecheck: + # name: Analyse types in python + # needs: get_changed_files + # uses: ./.github/workflows/JOB_typecheck.yml + # with: + # files: ${{ needs.get_changed_files.outputs.python_changed_files }} run_tests: - needs: [format, lint, typecheck] + needs: [format, lint] name: Run tests uses: ./.github/workflows/JOB_tests.yml diff --git a/.github/workflows/EVENT_release.yml b/.github/workflows/EVENT_release.yml index 75a685289..b35b55c14 100644 --- a/.github/workflows/EVENT_release.yml +++ b/.github/workflows/EVENT_release.yml @@ -47,8 +47,9 @@ jobs: needs: validate_tag uses: ./.github/workflows/JOB_tests.yml - build: - needs: validate_tag + release: + needs: [run_tests] + if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -65,80 +66,77 @@ jobs: uses: abatilo/actions-poetry@v2 with: poetry-version: "1.3.1" - - - name: Install dependencies - run: | - poetry install --no-interaction --no-root --all-extras -vvv - poetry build - - - name: Add build to release - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dist/* - asset_name: ${{ env.release_id }}.tar.gz - asset_content_type: application/gzip - - release: - needs: [run_tests, build] - if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - steps: - name: Publish on pypi.org env: POETRY_HTTP_BASIC_PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - # poetry publish - echo "Publishing to pypi.org - Emulated" + poetry publish --build test_release: - needs: [run_tests, build] + needs: [run_tests] if: startsWith(github.ref, 'refs/tags/test-') runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.ref }} + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.9" + - run: pip install pip --upgrade + - name: Setup Poetry + 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: | - poetry publish - echo "Publishing to test.pypi.org - Emulated" + 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/revert_nightly_setup.py # Linear tickets update notify_release: - needs: [release, test_release] - if: always() && contains(needs.*.result, 'success') - runs-on: ubuntu-latest - steps: - - name: Notify Slack - uses: ./.github/workflows/JOB_slack_message.yml - with: - icon: ":rocket:" - at_team: ${{ env.is_scheduled || !env.is_draft }} - secrets: inherit - message: | - :tada: *${{ env.release_tag }}* has been released! - :link: - - https://pypi.org/project/darwin-py - - ${{ github.event.release.html_url }} + needs: [release] + if: success() + uses: ./.github/workflows/JOB_slack_message.yml + secrets: inherit + with: + icon: ":rocket:" + at_team: true + message: | + :tada: *${{ inputs.release_tag || github.event.release.tag_name }}* has been released! + :link: + - https://pypi.org/project/darwin-py + - ${{ github.event.release.html_url }} notify_failed_release: - needs: [release, test_release] - if: always() && contains(needs.*.result, 'failure') - runs-on: ubuntu-latest - steps: - - name: Notify Slack - uses: ./.github/workflows/JOB_slack_message.yml - with: - secrets: inherit - icon: ":warning:" - at_team: true - message: | - :warning: *${{ env.release_tag }}* has failed to be released! - - *An error occurred performing release, and you may need to release manually.* - - :link: - - ${{ github.event.release.html_url }} + needs: [release] + if: failure() + uses: ./.github/workflows/JOB_slack_message.yml + secrets: inherit + with: + icon: ":warning:" + at_team: true + message: | + :warning: *${{ inputs.release_tag || github.event.release.tag_name }}* Release has failed to be released! + + *An error occurred performing release, and you may need to release manually.* + + :link: + - ${{ github.event.release.html_url }} diff --git a/.github/workflows/JOB_e2e.yml b/.github/workflows/JOB_e2e.yml index 41ff46cda..b3e231841 100644 --- a/.github/workflows/JOB_e2e.yml +++ b/.github/workflows/JOB_e2e.yml @@ -58,17 +58,5 @@ jobs: :link: - https://github.com/v7labs/darwin-py/actions/runs/${{ github.run_id }} - :warning: ${{ github.workflow }} failed + :warning: ${{ github.workflow }} failed. - - name: Send Slack Notification - run: | - PAYLOAD=$(cat < None: if file_extension.startswith("."): file_extension = file_extension[1:] - files_out = [file for file in files_in if file.endswith(f".{file_extension}") if "darwin/future" in file] + files_out = [file for file in files_in if file.endswith(f".{file_extension}") and "darwin/future" in file] print(" ".join(files_out)) 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()