From 0c54e739a60d26b4ed9d413a4d54a384885abc78 Mon Sep 17 00:00:00 2001 From: Torsten Kilias Date: Mon, 20 Mar 2023 13:25:52 +0100 Subject: [PATCH] #180: Prepare release on pypi (#181) * Add a exaslct script to pyproject.toml which gets installed during package install * Change release trigger from release_droid to creating a tag --- .github/workflows/release.yml | 34 +++++++- ...ase_droid_upload_github_release_assets.yml | 86 ------------------- doc/changes/changes_0.16.0.md | 5 +- doc/developer_guide/developer_guide.md | 54 +++++++++++- .../main.py | 6 +- pyproject.toml | 4 + setup.py | 5 ++ test/test_console_script.py | 11 +++ 8 files changed, 111 insertions(+), 94 deletions(-) delete mode 100644 .github/workflows/release_droid_upload_github_release_assets.yml create mode 100644 test/test_console_script.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60cc17c8..c366b406 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,22 +1,48 @@ -name: Release +name: Build & Publish on: - release: - types: [published] + push: + tags: '**' jobs: publish-release: runs-on: ubuntu-latest environment: publish + steps: - - uses: actions/checkout@v3 + + - name: SCM Checkout + uses: actions/checkout@v3 + + - name: Setup Python & Poetry Environment + uses: ./.github/actions/prepare_poetry_env + + - name: Build Artifacts + run: poetry build + - name: Build new Docker image run: "bash scripts/build/build_docker_runner_image.sh" + - name: Docker login run: echo "$SECRET_DOCKER_TOKEN" | docker login --username "$SECRET_DOCKER_USER_NAME" --password-stdin env: # Set the secret as an input SECRET_DOCKER_USER_NAME: ${{ secrets.DOCKER_USER_NAME }} SECRET_DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + - name: Push new Docker images run: bash scripts/build/push_docker_runner_image.sh latest "${{ github.event.release.tag_name }}" + + - name: PyPi Release + env: + POETRY_HTTP_BASIC_PYPI_USERNAME: "__token__" + POETRY_HTTP_BASIC_PYPI_PASSWORD: "${{ secrets.PYPI_TOKEN }}" + run: poetry publish + + - name: GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: > + gh release create ${GITHUB_REF_NAME} + --title ${GITHUB_REF_NAME} -F "./doc/changes/changes_${GITHUB_REF_NAME}.md" + dist/* \ No newline at end of file diff --git a/.github/workflows/release_droid_upload_github_release_assets.yml b/.github/workflows/release_droid_upload_github_release_assets.yml deleted file mode 100644 index 45861838..00000000 --- a/.github/workflows/release_droid_upload_github_release_assets.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: Release Droid - Upload GitHub Release Assets - -on: - workflow_dispatch: - inputs: - upload_url: - description: 'Upload URL' - required: true - -jobs: - check-release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: ./.github/actions/prepare_poetry_env - - name: Check Release - run: ./scripts/build/check_release.sh - - test-docker-starter: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Test ./exaslct - run: ./exaslct --help - - prep-testbed: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - id: set-matrix - run: | - sudo apt-get install jq - echo "::set-output name=matrix::$(bash ./scripts/test/get_all_tests.sh)" - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - - test-all: - needs: prep-testbed - environment: ci_test - strategy: - fail-fast: false - matrix: - exasol_version: - - "default" - python_version: - - 3.8 - test-path: ${{fromJson(needs.prep-testbed.outputs.matrix)}} - runs-on: ubuntu-latest - name: ${{ matrix.test-path.name }} - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/prepare_poetry_env - with: - python-version: 3.8 - - name: Test exaslct_with_poetry - run: ./scripts/test/exaslct_with_poetry.sh --help - - - name: Run all tests - run: ./scripts/test/run_test.sh ${{ matrix.test-path.path }} - env: # Set the secret as an input - DOCKER_USER: ${{ secrets.DOCKER_USER }} - DOCKER_PASSWD: ${{ secrets.DOCKER_PASSWD }} - - upload: - needs: test-all - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/prepare_poetry_env - - - name: Build Release - run: | - bash ./scripts/build/build_release.sh - - name: Generate sha512sum files - run: find ./dist -maxdepth 1 -type f -exec bash -c 'sha512sum {} > {}.sha512' \; - shell: bash - - name: Upload assets to the GitHub release draft - uses: shogo82148/actions-upload-release-asset@v1 - with: - upload_url: ${{ github.event.inputs.upload_url }} - asset_path: dist/* \ No newline at end of file diff --git a/doc/changes/changes_0.16.0.md b/doc/changes/changes_0.16.0.md index cbe553a8..a4c8af68 100644 --- a/doc/changes/changes_0.16.0.md +++ b/doc/changes/changes_0.16.0.md @@ -1,15 +1,16 @@ # Script-Languages-Container-Tool 0.16.0, released 2023-03-17 -Code name: Add missing PYTHON3 to the add_missing_builtin option for the LanguageDefinition class +Code name: Bugfix in LanguageDefinition class and prepare for pypi release. ## Summary -This release fix a bug where PYTHON3 was missing when the LanguageDefinition class was called with add_missing_builtin. +This release fix a bug where PYTHON3 was missing when the LanguageDefinition class was called with add_missing_builtin. It also prepares the project for the pypi release. ## Features / Enhancements - #175: Update vagrant environment - #178: Install exasol-integration-test-docker-environment from pypi + - #180: Prepare for pypi release ## Refactorings diff --git a/doc/developer_guide/developer_guide.md b/doc/developer_guide/developer_guide.md index 651ffe9b..da0f4c1f 100644 --- a/doc/developer_guide/developer_guide.md +++ b/doc/developer_guide/developer_guide.md @@ -219,4 +219,56 @@ Other build arguments which only influence the resources which are used to build the image are not part of the final hash. The `BuildContextHasher` hashes the execution rights of files, because these are the only rights which get saved in git and -can be important for the images. \ No newline at end of file +can be important for the images. + +## Creating a release + +### Prerequisites + +* Change log needs to be up to date +* Latest change log version needs to match project and package version +* Release tag needs to match package, changelog and project version + * For Example: + * Tag: 0.4.0 + * Changelog: changes_0.4.0.md + * \`poetry version -s\`: 0.4.0 + +### Triggering the Release +In order to trigger a release a new tag must be pushed to Github. +For further details see: `.github/workflows/release.yml`. + + +1. Create a local tag with the appropriate version number + + git tag x.y.z + +2. Push the tag to Github + + git push origin x.y.z + +### What to do if the release failed? + +#### The release failed during pre-release checks + +1. Delete the local tag + + git tag -d x.y.z + +2. Delete the remote tag + + git push --delete origin x.y.z + +3. Fix the issue(s) which lead to the failing checks +4. Start the release process from the beginning + + +#### One of the release steps failed (Partial Release) + +1. Check the Github action/workflow to see which steps failed +2. Finish or redo the failed release steps manually + +**Example**: + +_Scenario_: Publishing of the release on Github was successfully but during the PyPi release, the upload step got interrupted. + +_Solution_: Manually push the package to PyPi \ No newline at end of file diff --git a/exasol_script_languages_container_tool/main.py b/exasol_script_languages_container_tool/main.py index b91d2e05..bb56283b 100755 --- a/exasol_script_languages_container_tool/main.py +++ b/exasol_script_languages_container_tool/main.py @@ -5,5 +5,9 @@ import exasol_script_languages_container_tool.cli.commands -if __name__ == '__main__': +def main(): cli() + + +if __name__ == '__main__': + main() diff --git a/pyproject.toml b/pyproject.toml index d083c1f3..12737e00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,3 +29,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry.dev-dependencies] toml = ">=0.10.2" + + +[tool.poetry.scripts] +exaslct = 'exasol_script_languages_container_tool.main:main' \ No newline at end of file diff --git a/setup.py b/setup.py index 5ac1cfaa..208eb486 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,10 @@ 'networkx==2.8.2', 'typeguard<3.0.0'] +entry_points = \ +{'console_scripts': ['exaslct = ' + 'exasol_script_languages_container_tool.main:main']} + setup_kwargs = { 'name': 'exasol-script-languages-container-tool', 'version': '0.16.0', @@ -43,6 +47,7 @@ 'packages': packages, 'package_data': package_data, 'install_requires': install_requires, + 'entry_points': entry_points, 'python_requires': '>=3.8,<4', } diff --git a/test/test_console_script.py b/test/test_console_script.py new file mode 100644 index 00000000..bc91c2a6 --- /dev/null +++ b/test/test_console_script.py @@ -0,0 +1,11 @@ +import subprocess +import unittest + + +class ConsoleScriptTest(unittest.TestCase): + + def test_console_script(self): + return_code = subprocess.call("poetry install", shell=True) + self.assertEqual(0, return_code, "Poetry install failed") + return_code = subprocess.call("poetry run exaslct --help", shell=True) + self.assertEqual(0, return_code)