From d39cc8c1c782a361601d37fc2a1babed9d395b72 Mon Sep 17 00:00:00 2001 From: Oskar Manhart <52569953+oskardotglobal@users.noreply.github.com> Date: Sat, 17 May 2025 13:59:43 +0200 Subject: [PATCH] feat: add check before building --- .forgejo/workflows/check_version_exists.py | 37 ++++++++++++++++++++ .forgejo/workflows/check_version_exists.yaml | 34 ++++++++++++++++++ .forgejo/workflows/pycairo.yaml | 20 +++++++++-- 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 .forgejo/workflows/check_version_exists.py create mode 100644 .forgejo/workflows/check_version_exists.yaml diff --git a/.forgejo/workflows/check_version_exists.py b/.forgejo/workflows/check_version_exists.py new file mode 100644 index 0000000..d6efa40 --- /dev/null +++ b/.forgejo/workflows/check_version_exists.py @@ -0,0 +1,37 @@ +#/usr/bin/env python3 + +import os +import re +import sys +import requests + + +def get_github_version(repository: str) -> str: + res = requests.get(f"https://api.github.com/repos/{repository}/releases/latest").json() + return res["tag_name"].removeprefix("v") + + +def does_pypi_version_exist(base_url: str, package: str, version: str) -> bool: + base_url = base_url.removesuffix("/") + version = version.replace(".", "\\.") + + body = requests.get(f"{base_url}/simple/{package}").text + return len(re.findall(rf"{package}-{version}-.+", body, re.MULTILINE)) > 0 + + +def main(): + repository = os.environ["REPOSITORY"] + package = os.environ["PACKAGE"] + base_url = os.environ["FORGEJO_URL"] + + version = get_github_version(repository) + + if does_pypi_version_exist(base_url, package, version): + sys.exit(0) + + print(f"version=v{version}") + + +if __name__ == "__main__": + main() + diff --git a/.forgejo/workflows/check_version_exists.yaml b/.forgejo/workflows/check_version_exists.yaml new file mode 100644 index 0000000..de78cdc --- /dev/null +++ b/.forgejo/workflows/check_version_exists.yaml @@ -0,0 +1,34 @@ +on: + workflow_call: + inputs: + github-repository: + required: true + type: string + pypi-package: + required: true + type: string + pypi-base-url: + required: true + type: string + outputs: + version: ${{ jobs.check-version-exists.outputs.version }} + +jobs: + check-version-exists: + runs-on: ubuntu-latest + + outputs: + version: ${{ steps.check.outputs.version }} + + steps: + - uses: actions/checkout@v4 + + - id: check + run: | + pip3 install requests + exec python3 check_version_exists.py >> $GITHUB_OUTPUT + env: + REPOSITORY: ${{ inputs.github-repository }} + PACKAGE: ${{ inputs.pypi-package}} + BASE_URL: ${{ inputs.pypi-base-url}} + diff --git a/.forgejo/workflows/pycairo.yaml b/.forgejo/workflows/pycairo.yaml index ebc884a..56e4a4a 100644 --- a/.forgejo/workflows/pycairo.yaml +++ b/.forgejo/workflows/pycairo.yaml @@ -5,16 +5,30 @@ on: schedule: - cron: "0 10 * * 0" +env: + REPOSITORY_URL: https://cmwedding-bot:${{ secrets.FORGEJO_TOKEN }}@git.weddingfactory.eu/api/packages/cmwedding/pypi + jobs: - build_wheels: + check-version-exists: + uses: .forgejo/workflows/check-version-exists.yaml + with: + pypi-base-url: ${{ env.REPOSITORY_URL }} + pypi-package: pycairo + github-repository: "pygobject/pycairo" + + build: name: Build wheels on ${{ matrix.os }} + + needs: check-version-exists + if: needs.check-version-exists.outputs.version != "" + runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest] steps: - - run: git clone --depth=1 https://github.com/pygobject/pycairo --branch v1.28.0 . + - run: git clone --depth=1 https://github.com/pygobject/pycairo --branch ${{ needs.check-version-exists.outputs.version }} . - name: Build wheels uses: https://github.com/pypa/cibuildwheel@v2.23.3 @@ -29,6 +43,6 @@ jobs: pip3 install twine python3 -m twine upload ./wheelhouse/* env: - TWINE_REPOSITORY_URL: https://cmwedding-bot:${{ secrets.FORGEJO_TOKEN }}@git.weddingfactory.eu/api/packages/cmwedding/pypi + TWINE_REPOSITORY_URL: ${{ env.REPOSITORY_URL }} TWINE_NON_INTERACTIVE: 1