From dbea784721aae3a66b66124830a60b19b4773016 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Mon, 24 Aug 2026 09:24:29 +0200 Subject: [PATCH] Feat: Add GitHub token verification script and integrate it into workflow --- .gitea/workflows/test-python.yml | 3 +++ .github/workflows/test-python.yml | 3 +++ python/check_github_token.py | 35 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 python/check_github_token.py diff --git a/.gitea/workflows/test-python.yml b/.gitea/workflows/test-python.yml index 4f7ef1d..c648449 100644 --- a/.gitea/workflows/test-python.yml +++ b/.gitea/workflows/test-python.yml @@ -19,6 +19,9 @@ jobs: with: python-version: '3.14' + - name: Check Authentication + run: python3 python/check_github_token.py "${{ secrets.GH_TOKEN }}" + - name: Go ACME Setup run: python3 python/install_github_release.py go-acme/lego -t archive -k "${{ secrets.GH_TOKEN }}" -p /tmp/python-cli-test diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 825ed99..a77add2 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -19,6 +19,9 @@ jobs: with: python-version: '3.14' + - name: Check Authentication + run: python3 python/check_github_token.py "${{ github.token }}" + - name: Go ACME Setup run: python3 python/install_github_release.py go-acme/lego -t archive -k "${{ github.token }}" -p /tmp/python-cli-test diff --git a/python/check_github_token.py b/python/check_github_token.py new file mode 100644 index 0000000..8f1c0b1 --- /dev/null +++ b/python/check_github_token.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import argparse +import os +import sys + +from install_github_release import fetch_latest_release + + +def main(): + """Parse command-line arguments and verify a GitHub token, reporting errors via the exit code.""" + parser = argparse.ArgumentParser( + usage='%(prog)s [token]', + allow_abbrev=False, + ) + parser.add_argument('token', nargs='?', help='The GitHub token to verify') + args = parser.parse_args() + + token = args.token or os.environ.get('GITHUB_TOKEN') + if not token: + print('Error: No GitHub token provided as an argument or found in GITHUB_TOKEN environment variable.', file=sys.stderr) + sys.exit(1) + + print('Verifying GitHub token...') + try: + fetch_latest_release('actions/checkout', token) + print('\x1b[32mSuccess: The provided GitHub token is valid and has sufficient permissions to access public repositories.\x1b[0m') + except Exception as error: + print('\x1b[31mError: GitHub token verification failed.\x1b[0m', file=sys.stderr) + print(f'Reason: {error}', file=sys.stderr) + sys.exit(1) + + +if __name__ == '__main__': + main()