From 8074c0d04518c82b91c457d76ca2f4c7073c30ed Mon Sep 17 00:00:00 2001 From: Valentin Gauthier Date: Wed, 3 Apr 2024 15:16:50 +0200 Subject: [PATCH] ci --- .github/actions/prepare-poetry/action.yml | 57 +++++++++ LICENSE | 2 +- .../ci-energyml-utils-pull-request.yml | 112 ++++++++++++++++++ ...tils.yml => ci-energyml-utils-release.yml} | 0 energyml-utils/LICENSE | 2 +- 5 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 .github/actions/prepare-poetry/action.yml create mode 100644 energyml-utils/.github/workflow/ci-energyml-utils-pull-request.yml rename energyml-utils/.github/workflow/{ci-energyml-utils.yml => ci-energyml-utils-release.yml} (100%) diff --git a/.github/actions/prepare-poetry/action.yml b/.github/actions/prepare-poetry/action.yml new file mode 100644 index 0000000..e8302ee --- /dev/null +++ b/.github/actions/prepare-poetry/action.yml @@ -0,0 +1,57 @@ +## +## Copyright (c) 2022-2023 Geosiris. +## SPDX-License-Identifier: Apache-2.0 +## +--- + +name: Prepare Python and Poetry +Description: Install Python, Poetry and dev dependencies, cached for speed + +inputs: + python-version: + description: 'Python version to use' + required: true + default: '3.x' + +runs: + using: "composite" + steps: + - name: Set up Python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Load cached Poetry installation + uses: actions/cache@v4 + with: + path: ~/.local # the path depends on the OS + key: poetry-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-4 # increment to reset cache + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.5.1 + virtualenvs-create: true + virtualenvs-in-project: false + + - name: Install Poetry Plugins + run: | + python -m pip install --upgrade pip + pip install poetry-dynamic-versioning + shell: bash + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-1 + + - name: Install dependencies and library + # if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction + shell: bash + + - name: Install Poetry Plugins + run: poetry self add "poetry-dynamic-versioning[plugin]" + shell: bash diff --git a/LICENSE b/LICENSE index 261eeb9..9e54d36 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2023 GEOSIRIS Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/energyml-utils/.github/workflow/ci-energyml-utils-pull-request.yml b/energyml-utils/.github/workflow/ci-energyml-utils-pull-request.yml new file mode 100644 index 0000000..432f123 --- /dev/null +++ b/energyml-utils/.github/workflow/ci-energyml-utils-pull-request.yml @@ -0,0 +1,112 @@ +## +## Copyright (c) 2023-2024 Geosiris. +## SPDX-License-Identifier: Apache-2.0 +## +--- + +name: Publish (pypiTest) + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + name: Build distribution + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.9' + + - name: Install poetry + uses: ../.github/actions/prepare-poetry + with: + python-version: 3.9 + + - name: Build + run: | + poetry install + poetry self add "poetry-dynamic-versioning[plugin]" + poetry build + + - name: Save build artifacts + uses: actions/upload-artifact@v2 + with: + name: dist-artifact + path: dist/ + + test: + name: Test + needs: build + runs-on: ubuntu-latest + steps: + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get build artifacts + uses: actions/download-artifact@v3 + with: + name: dist-artifact + path: dist/ + + - name: Install from build + run: | + python -m pip install --upgrade pip + pip install pytest-mock + pip install etpproto --pre --target=dist --find-links=dist/ + + - name: Copy tests and example data to dist folder for testing against artifacts + run: | + cp -R tests dist/ + # cp -R example_data dist/ + + - name: Run tests + run: pytest dist/tests + + publish: + name: Publish to PyPI + needs: [build, test] + runs-on: ubuntu-latest + steps: + + # Retrieve the code and GIT history so that poetry-dynamic-versioning knows which version to upload + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get build artifacts + uses: actions/download-artifact@v3 + with: + name: dist-artifact + path: dist/ + + - name: Install poetry + uses: ../.github/actions/prepare-poetry + with: + python-version: 3.9 + + - name: Upload to PyPI TEST + run: | + poetry self add "poetry-dynamic-versioning[plugin]" + poetry config repositories.test-pypi https://test.pypi.org/legacy/ + poetry config pypi-token.test-pypi ${{ secrets.POETRY_PYPI_TEST_TOKEN_VALUE }} + poetry publish --repository test-pypi diff --git a/energyml-utils/.github/workflow/ci-energyml-utils.yml b/energyml-utils/.github/workflow/ci-energyml-utils-release.yml similarity index 100% rename from energyml-utils/.github/workflow/ci-energyml-utils.yml rename to energyml-utils/.github/workflow/ci-energyml-utils-release.yml diff --git a/energyml-utils/LICENSE b/energyml-utils/LICENSE index cc44078..9e54d36 100644 --- a/energyml-utils/LICENSE +++ b/energyml-utils/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2020 GEOSIRIS + Copyright 2023 GEOSIRIS Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.