From f57ee8470fde5cde66d069c6062dc12927f97dc0 Mon Sep 17 00:00:00 2001 From: "sebastien.heurtematte" Date: Tue, 13 May 2025 10:23:40 +0200 Subject: [PATCH] feat: add renovate bot creation Signed-off-by: sebastien.heurtematte --- github/playwright/gh_create_renovate_token.py | 89 +++++++++++++++++++ github/setup_token.sh | 50 +++++++++++ 2 files changed, 139 insertions(+) create mode 100644 github/playwright/gh_create_renovate_token.py create mode 100755 github/setup_token.sh diff --git a/github/playwright/gh_create_renovate_token.py b/github/playwright/gh_create_renovate_token.py new file mode 100644 index 0000000..71c2b1d --- /dev/null +++ b/github/playwright/gh_create_renovate_token.py @@ -0,0 +1,89 @@ +import sys +import common +import pyperclip +from playwright.sync_api import sync_playwright, Error, expect + + +def setup_token(page, project_name): + common.nav_to_token_settings(page) + + # Check if token has already been added + page.get_by_role("heading", name="Personal access tokens (classic)").click() # This click is required, otherwise the next elements are not found!? + token_name = "renovate" + if page.get_by_role("link", name=token_name).is_visible(): + print("Renovate token has been added already") + if common.ask_to_continue("Do you want to regenerate it? (yes/no):"): + print("Regenerate Renovate token") + + # token list page + page.get_by_role("link", name=token_name).click() + page.get_by_role("link", name="Regenerate token").click() + + # Regenerate personal access token page + page.get_by_role("button", name="30 days").click() + page.get_by_role("menuitemradio", name="No expiration").click() + page.get_by_role("button", name="Regenerate token").click() + page.get_by_role("button", name="Copy token").click() + + else: + return + else: + print("Create Renovate token") + page.get_by_role("button", name="Generate new token").click() + page.get_by_role("menuitem", name="Generate new token (classic) For general use").click() + page.get_by_label("Note").fill(token_name) + page.get_by_role("button", name="30 days").click() + page.get_by_role("menuitemradio", name="No expiration").click() + page.get_by_label("repo\n \n\n \n \n Full control of private repositories").check() + page.get_by_label("workflow\n \n\n \n \n Update GitHub Action workflows").check() + page.get_by_role("button", name="Generate token").click() + page.get_by_role("button", name="Copy token").click() + + print("Register Renovate token") + renovate_token = pyperclip.paste() + print("Renovate token: " + renovate_token) + if renovate_token == "": + print("ERROR: Renovate token is empty") + sys.exit(1) + + # add token to pass + common.add_to_pass(project_name, renovate_token, "renovate-token") + + +def main(): + _DEFAULT_TIMEOUT = 10000 + + if len(sys.argv) < 2: + print("ERROR: project name must be set") + sys.exit(1) + else: + project_name = sys.argv[1] + print("Project name: " + project_name) + + print("opening browser window") + with sync_playwright() as playwright: + browser = playwright.firefox.launch(headless=False) + context = browser.new_context(no_viewport=True) + + page = context.new_page() + page.set_default_timeout(_DEFAULT_TIMEOUT) + + username = common.get_pass_creds(project_name, "username") + password = common.get_pass_creds(project_name, "password") + + common.login(page, project_name, username, password) + + expect(page.get_by_role("heading", name="Home", exact=True)).to_be_visible(timeout=30000) + + setup_token(page, project_name) + + # input('Press any key to continue\n') + common.signout(page) + + page.close() + context.close() + browser.close() + + +if __name__ == "__main__": + main() diff --git a/github/setup_token.sh b/github/setup_token.sh new file mode 100755 index 0000000..b60990d --- /dev/null +++ b/github/setup_token.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +#******************************************************************************* +# Copyright (c) 2024 Eclipse Foundation and others. +# This program and the accompanying materials are made available +# under the terms of the Eclipse Public License 2.0 +# which is available at http://www.eclipse.org/legal/epl-v20.html, +# or the MIT License which is available at https://opensource.org/licenses/MIT. +# SPDX-License-Identifier: EPL-2.0 OR MIT +#******************************************************************************* + +# Bash strict-mode +set -o errexit +set -o nounset +set -o pipefail + +IFS=$'\n\t' +SCRIPT_FOLDER="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" + +#shellcheck disable=SC1091 +source "${SCRIPT_FOLDER}/../utils/common.sh" + +# Create a GitHub token for the Renovate bot +# This token is used to authenticate the Renovate bot with GitHub +renovate() { + local project_name="${1:-}" + + # check that project name is not empty + if [[ -z "${project_name}" ]]; then + printf "ERROR: a project name must be given.\n" + exit 1 + fi + + printf "\n# Create renovate token...\n" + if _check_pw_does_not_exist "${project_name}" "github.com/renovate-token"; then + python "${SCRIPT_FOLDER}/playwright/gh_create_renovate_token.py" "${project_name}" + fi + + printf "\n# TODO Create renovate token in otterdog...\n" + cat <