From 787b1c23fdc39c97bf73eb36b3e7a12e79bdac62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Wed, 14 May 2025 07:39:58 +0200 Subject: [PATCH] Add a check for releases (#3405) * Add a check for releases * remove print --- .github/workflows/checks.yml | 25 +++++++++++++++++++++++++ scripts/check/releases.py | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 scripts/check/releases.py diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index b05799d..a19f602 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -104,6 +104,31 @@ jobs: - name: Run the check run: python3 -m scripts.check.edits + releases: + runs-on: ubuntu-latest + name: Releases + needs: preflight + if: needs.preflight.outputs.removal != 'true' + steps: + - name: Check out repository + uses: actions/checkout@v4.2.2 + + - name: Set up Python + uses: actions/setup-python@v5.6.0 + with: + python-version-file: ".python-version" + cache: "pip" + cache-dependency-path: "requirements.txt" + + - name: Install dependencies if needed + run: scripts/setup + + - name: Run the check + run: python3 -m scripts.check.releases + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPOSITORY: ${{needs.preflight.outputs.repository}} + removed: runs-on: ubuntu-latest name: Removed repository diff --git a/scripts/check/releases.py b/scripts/check/releases.py new file mode 100644 index 0000000..85813a6 --- /dev/null +++ b/scripts/check/releases.py @@ -0,0 +1,25 @@ +import asyncio +import os + +from aiogithubapi import GitHub, AIOGitHubAPIException + +TOKEN = os.getenv("GITHUB_TOKEN") + + +async def check(): + repo = os.environ["REPOSITORY"] + print("Information: https://hacs.xyz/docs/publish/include#check-releases") + try: + async with GitHub(TOKEN) as github: + request = await github.client.get(f"/repos/{repo}/releases", headers={}) + if isinstance(request.data, list) and len(request.data) > 0: + print(f"'{repo}' has releases") + return + + except AIOGitHubAPIException as e: + exit(f"::error::{e}") + + exit(f"::error::'{repo}' has no releases") + +if __name__ == "__main__": + asyncio.get_event_loop().run_until_complete(check())