Refactor: Replace GitHub token verification script and update workflow steps
Test Python CLI / test-python (push) Successful in 11s

This commit is contained in:
2026-08-24 10:02:15 +02:00
parent fbe4fab4e7
commit bc753ba00a
4 changed files with 24 additions and 38 deletions
+22 -1
View File
@@ -79,6 +79,13 @@ def fetch_latest_release(repository, token=None):
raise RuntimeError(f'Failed to fetch latest release for {repository}: {error.reason}. {body}') from error
def check_github_token(token):
"""Verify a GitHub token by fetching the latest release of actions/checkout."""
print('Verifying GitHub token...')
fetch_latest_release('actions/checkout', token)
print('Success: The provided GitHub token is valid and has sufficient permissions to access public repositories.')
def download_asset(url, dest_path, token=None):
"""Download a release asset from url and write it to dest_path."""
headers = {'User-Agent': 'install-github-release-cli'}
@@ -333,7 +340,7 @@ _install_github_release_complete() {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--dry-run -l --list -a --app-name -f --file-name -b --binary-name -t --file-type -p --install-path -o --output-directory -j --releases-json --system --arch -k --token -d --debug --completion -h --help"
opts="--dry-run -l --list -a --app-name -f --file-name -b --binary-name -t --file-type -p --install-path -o --output-directory -j --releases-json --system --arch -k --token -d --debug --completion --check-token -h --help"
case "$prev" in
-t|--file-type)
@@ -376,6 +383,7 @@ _install_github_release() {
'(-d --debug)'{-d,--debug}'[Enable debug logging]'
'--dry-run[Run in test mode]'
'--completion[Print shell completion script]:shell:(bash zsh)'
'--check-token[Verify the GitHub token against actions/checkout and exit]'
'(-h --help)'{-h,--help}'[Show help message]'
'1:repository:'
)
@@ -413,12 +421,25 @@ def main():
parser.add_argument('-k', '--token', metavar='token', help='GitHub token')
parser.add_argument('-d', '--debug', action='store_true', help='Enable debug logging')
parser.add_argument('--completion', choices=['bash', 'zsh'], help='Print a shell completion script and exit')
parser.add_argument('--check-token', action='store_true', help='Verify the GitHub token against actions/checkout and exit')
args = parser.parse_args()
if args.completion:
print(BASH_COMPLETION if args.completion == 'bash' else ZSH_COMPLETION, end='')
sys.exit(0)
if args.check_token:
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)
try:
check_github_token(token)
except Exception as error:
print(f'Error: {error}', file=sys.stderr)
sys.exit(1)
sys.exit(0)
list_repo = args.list if isinstance(args.list, str) else None
repository = list_repo or args.repository
if not repository: