diff --git a/.github/workflows/python-publish-scheduled.yml b/.github/workflows/python-publish-scheduled.yml new file mode 100644 index 000000000..c82993dd5 --- /dev/null +++ b/.github/workflows/python-publish-scheduled.yml @@ -0,0 +1,114 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package Scheduled + +on: + schedule: + # At 01:23 on 1st January and every 6 months afterward + - cron: '23 1 1 1/6 *' + +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.11"] + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install tox + run: | + python -m pip install --upgrade pip + pip install tox + - name: Run the Tests + run: | + tox -e tests + tag_and_release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Calculate Tag Name + id: calc_tag + run: | + CURRENT_YEAR=$(date +%Y) + CURRENT_MONTH=$(date +%m) + TAG="${CURRENT_YEAR}${TAG_MONTH}.0.0" + echo "Calculated tag $TAG" + echo "::set-output name=tag::$TAG" + - name: Create and Push Tag + run: | + TAG=${{ steps.calc_tag.outputs.tag }} + git tag $TAG + git push origin $TAG + generate: + name: Generate JSON-Schemas + runs-on: ubuntu-latest + needs: tests + steps: + - name: Check out Git repository + uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install tox + run: | + python -m pip install --upgrade pip + pip install tox + - name: Build JSON Schemas + run: tox -e generate_json_schemas + env: + TARGET_VERSION: ${{ github.ref_name }} + - name: Push schemas to BO4E-Schemas repo + uses: cpina/github-action-push-to-another-repository@v1.7.2 + env: + API_TOKEN_GITHUB: ${{ secrets.BO4E_PYTHON_GENERATE_SCHEMAS }} # this token expires on 2024-10-09 + # token with repo scope + # https://github.com/Hochfrequenz/BO4E-python/settings/secrets/actions/BO4E_PYTHON_GENERATE_SCHEMAS + with: + source-directory: "json_schemas" + target-directory: "src/bo4e_schemas" + destination-github-username: "Hochfrequenz" + destination-repository-name: "BO4E-Schemas" + user-email: bo4e-schemas@hochfrequenz.de + target-branch: main + commit-message: "Update JSON-Schemas - BO4E ${{ github.ref_name }}" + # This step uses the github API to automatically create a release with the same version tag + # in the BO4E-Schemas repo. For this we have to retrieve the commits SHA via the API first. + # For this, we use the lightweight tool jq (https://stedolan.github.io/jq/) to parse the JSON + # response from the API. + - name: Tag and release the new version in BO4E-Schemas + run: python bo4e_schemas_create_release.py + env: + GITHUB_TOKEN: ${{ secrets.BO4E_PYTHON_GENERATE_SCHEMAS }} # this token expires on 2024-10-09 + VERSION: ${{ github.ref_name }} + build-n-publish: + name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI + runs-on: ubuntu-latest + # Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/ + environment: release + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + needs: [tests, generate] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10.x" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r dev_requirements/requirements-packaging.txt + - name: Build wheel and source distributions + run: python -m build + - name: Publish distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags/v') + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 927f7bc52..d19022aff 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -5,7 +5,6 @@ name: Upload Python Package on: release: - branches: main types: [created, edited] jobs: