From 442e55437c411ab3d048c82f38743219a3bd9df3 Mon Sep 17 00:00:00 2001 From: UsamaSadiq Date: Fri, 27 Oct 2023 20:08:47 +0500 Subject: [PATCH] build: remove jenkins repo health job --- devops/jobs/CreateRepoHealthJobs.groovy | 126 ------------- devops/resources/run-repo-health-on-org.sh | 203 --------------------- 2 files changed, 329 deletions(-) delete mode 100644 devops/jobs/CreateRepoHealthJobs.groovy delete mode 100644 devops/resources/run-repo-health-on-org.sh diff --git a/devops/jobs/CreateRepoHealthJobs.groovy b/devops/jobs/CreateRepoHealthJobs.groovy deleted file mode 100644 index d0f53776d..000000000 --- a/devops/jobs/CreateRepoHealthJobs.groovy +++ /dev/null @@ -1,126 +0,0 @@ -package devops.jobs -import static org.edx.jenkins.dsl.Constants.common_logrotator -import static org.edx.jenkins.dsl.Constants.common_wrappers -import static org.edx.jenkins.dsl.DevopsTasks.common_read_permissions - - -class CreateRepoHealthJobs{ - public static def job = { dslFactory, extraVars -> - dslFactory.job(extraVars.get("FOLDER_NAME","RepoHealth") + "/org-repo-health-report") { - - logRotator common_logrotator - wrappers common_wrappers - - def access_control = extraVars.get('ACCESS_CONTROL',[]) - access_control.each { acl -> - common_read_permissions.each { perm -> - authorization { - permission(perm,acl) - } - } - } - - def edx_repo_health_gitURL = 'git@github.com:edx/edx-repo-health.git' - def destination_repo_health_gitURL = "git@github.com:edx/repo-health-data.git" - def testeng_ci_gitURL = 'https://github.com/edx/testeng-ci.git' - def repo_tools_gitURL = 'git@github.com:edx/repo-tools.git' - - description('Generate a report listing repository structure standard compliance accross edX repos') - concurrentBuild(false) - parameters { - stringParam('EDX_REPO_HEALTH_BRANCH', 'master', 'Branch of the edx-repo-health repo to check out.') - stringParam('ONLY_CHECK_THIS_REPOSITORY', '', 'If you only want to run repo health on one repository, set this to org/name of said repository.') - stringParam('REPORT_DATE','','The date for which repo health data is required.(format: YYYY-MM-DD)') - } - multiscm { - git { - remote { - credentials('edx-secure') - url(edx_repo_health_gitURL ) - } - branch('$EDX_REPO_HEALTH_BRANCH') - browser() - extensions { - cleanBeforeCheckout() - relativeTargetDirectory('edx-repo-health') - } - } - git { - remote { - credentials('edx-secure') - url(testeng_ci_gitURL) - } - branch('master') - extensions { - cleanBeforeCheckout() - relativeTargetDirectory('testeng-ci') - } - } - git { - remote { - credentials('edx-secure') - url(repo_tools_gitURL) - } - branch('master') - extensions { - cleanBeforeCheckout() - relativeTargetDirectory('repo_tools') - } - } - git { - remote { - credentials('edx-secure') - url(destination_repo_health_gitURL ) - } - branch('master') - browser() - extensions { - wipeOutWorkspace() - cleanBeforeCheckout() - relativeTargetDirectory('repo-health-data') - } - } - } - triggers { - cron('H H(4-11) * * 1-5') - } - wrappers { - timeout { - absolute(90) - } - credentialsBinding { - string('GITHUB_TOKEN', 'GITHUB_REPOHEALTH_STATUS_BOT_TOKEN') - string('READTHEDOCS_API_KEY', 'READTHEDOCS_API_KEY') - file('REPO_HEALTH_GOOGLE_CREDS_FILE', 'REPO_HEALTH_GOOGLE_CREDS_FILE') - } - timestamps() - sshAgent('edx-secure') - } - environmentVariables { - env('REPO_HEALTH_OWNERSHIP_SPREADSHEET_URL', extraVars.get('SPREADSHEET_URL')) - env('REPO_HEALTH_REPOS_WORKSHEET_ID', extraVars.get('WORKSHEET_ID')) - env('REPORT_DATE', '$REPORT_DATE') - env('EDX_REPO_HEALTH_BRANCH', '$EDX_REPO_HEALTH_BRANCH') - env('ONLY_CHECK_THIS_REPOSITORY', '$ONLY_CHECK_THIS_REPOSITORY') - } - - steps{ - shell(dslFactory.readFileFromWorkspace('devops/resources/run-repo-health-on-org.sh')) - } - - publishers { - archiveArtifacts { - pattern('repo-health-data/dashboards/*.csv') // csv dashboards containing aggregated data - } - if (extraVars.get('NOTIFY_ON_FAILURE')){ - publishers { - mailer(extraVars.get('NOTIFY_ON_FAILURE'), false, false) - } - } - } - - - } - } -} - diff --git a/devops/resources/run-repo-health-on-org.sh b/devops/resources/run-repo-health-on-org.sh deleted file mode 100644 index 4de24158c..000000000 --- a/devops/resources/run-repo-health-on-org.sh +++ /dev/null @@ -1,203 +0,0 @@ -#!/bin/bash -set -e -v - -# Click requires this to work cause it interfaces weirdly with python 3 ASCII default -export LC_ALL=C.UTF-8 -export LANG=C.UTF-8 - -ORG_NAMES=("edx" "openedx") -GITHUB_USER_EMAIL="admin+edxstatusbot@edx.org" -# If the REPORT_DATE variable is set and not an empty string parse the date to standardize it. -if [[ ! -z $REPORT_DATE ]]; then REPORT_DATE=$(date '+%Y-%m-%d' -d "$REPORT_DATE"); fi - -# for unknown reasons, repo-health-data does not come with correct refs -# git checkout master is necessary to get the refs/heads/master -cd "${WORKSPACE}/repo-health-data" -git show-ref -git checkout master -git show-ref - -############################### -# Get list of repos in edx org. -############################### - -cd "${WORKSPACE}" -virtualenv --python=/usr/bin/python3.8 venv -q --clear -source venv/bin/activate - -cd "${WORKSPACE}/repo_tools" -make install -pip install -e . -REPOSIORIES_URLS_FILE="${WORKSPACE}/repositories.txt" -cat /dev/null > $REPOSIORIES_URLS_FILE -for ORG_NAME in ${ORG_NAMES[@]}; do - get_org_repo_urls "${ORG_NAME}" --url_type https --forks --add_archived --output_file "${REPOSIORIES_URLS_FILE}" --username "${GITHUB_USER_EMAIL}" --token "${GITHUB_TOKEN}" --ignore-repo "clamps-ghsa-c4rq-qwgr-pj5h" -done -unset ORG_NAME - -deactivate - -############################ -# Run checks on repositories -############################ - -# Recreate new virtualenv just for testeng-ci script - -cd ${WORKSPACE} -# delete previous venv to make room for new one -rm -rf venv -virtualenv --python=/usr/bin/python3.8 venv -q -source venv/bin/activate - -# Install checks and dashboarding script, this should also install pytest-repo-health -cd edx-repo-health -pip install -r requirements/base.txt -pip install -e . -cd ${WORKSPACE} - -# data destination folder setup - -METADATA_FILE_DIST="${WORKSPACE}/repo-health-data/docs/checks_metadata.yaml" - -failed_repos=() - -OUTPUT_FILE_POSTFIX="_repo_health.yaml" - -echo -echo -# Git clone each repo in org and run checks on it -input="${REPOSIORIES_URLS_FILE}" -while IFS= read -r line -do - cd "$WORKSPACE" - - if [[ "$line" =~ ^(git@github\.com:|https://github\.com/)([a-zA-Z0-9_.-]+?)/([a-zA-Z0-9_.-]+?)\.git$ ]]; then - ORG_NAME="${BASH_REMATCH[2]}" - REPO_NAME="${BASH_REMATCH[3]}" - FULL_NAME="$ORG_NAME/$REPO_NAME" - else - echo "Skipping <$line>: Could not recognize as a GitHub URL in order to extract org and repo name." - continue - fi - - if [[ "$REPO_NAME" = "edx-repo-health" ]]; then - echo "Skipping <$line>: edx-repo health" - continue - fi - - if [[ -n "$ONLY_CHECK_THIS_REPOSITORY" && "$FULL_NAME" != "$ONLY_CHECK_THIS_REPOSITORY" ]]; then - echo "Skipping <$line>: ONLY_CHECK_THIS_REPOSITORY was set, and does not match" - continue - fi - - echo - echo - echo "Processing repo: $FULL_NAME" - - rm -rf target-repo - git clone -- "${line/https:\/\//https:\/\/$GITHUB_TOKEN@}" target-repo || { - failed_repos+=("$FULL_NAME") - continue - } - - cd target-repo - - # If the REPORT_DATE variable is set and not an empty string. - if [[ ! -z $REPORT_DATE ]] - then - # If a specific date is given for report - FIRST_COMMIT=$(git log --reverse --format="format:%ci" | sed -n 1p) - if [[ $REPORT_DATE > ${FIRST_COMMIT:0:10} ]] - then - git checkout `git rev-list -n 1 --before="${REPORT_DATE} 00:00" master` - else - echo "${REPO_NAME} doesn't have any commits prior to ${REPORT_DATE}" - failed_repos+=("$FULL_NAME") - continue - fi - fi - - ORG_DATA_DIR="${WORKSPACE}/repo-health-data/individual_repo_data/${ORG_NAME}" - # make sure destination folder exists - mkdir -p "$ORG_DATA_DIR" - - OUTPUT_FILE_NAME=${REPO_NAME}${OUTPUT_FILE_POSTFIX} - cd ${WORKSPACE} - if pytest --repo-health --repo-health-path edx-repo-health --repo-path target-repo --repo-health-metadata "${METADATA_FILE_DIST}" --output-path "${ORG_DATA_DIR}/${OUTPUT_FILE_NAME}" -o log_cli=true --exitfirst --noconftest -v -c /dev/null - then - true - elif pytest --repo-health --repo-health-path edx-repo-health --repo-path target-repo --repo-health-metadata "${METADATA_FILE_DIST}" --output-path "${ORG_DATA_DIR}/${OUTPUT_FILE_NAME}" -o log_cli=true --exitfirst --noconftest -v -c /dev/null - # rerun the same command if it fails once - then - true - else - failed_repos+=("$FULL_NAME") && continue - fi -done < "$input" - -############################## -# Recalculate aggregated data. -############################## - -# Go into data repo, recalculate aggregate data, and push a PR -IFS=, -failed_repo_names=`echo "${failed_repos[*]}"` - -# Delete existing dashboards(sqlite) to re compile -find "${WORKSPACE}/repo-health-data/dashboards" -type f -iname "dashboard*.sql" -delete - -# Compiling dashboard with latest yml files from both orgs -echo "Pushing data" -cd "${WORKSPACE}/repo-health-data/individual_repo_data" -ls * -repo_health_dashboard --data-dir . --configuration "${WORKSPACE}/edx-repo-health/repo_health_dashboard/configuration.yaml" --output-csv "${WORKSPACE}/repo-health-data/dashboards/dashboard" --output-sqlite "${WORKSPACE}/repo-health-data/dashboards/dashboard" - -deactivate -cd ${WORKSPACE} -rm -rf venv - -# Only commit the data if running with master and no REPORT_DATE is set. -if [[ ${EDX_REPO_HEALTH_BRANCH} == 'master' && -z ${REPORT_DATE} ]] -then - - ########################################### - # Commit files and push to repo-health-data - ########################################### - echo "Commit new files and push to master..." - - commit_message="Update repo health data" - - cd "${WORKSPACE}/repo-health-data" - - if [[ ! "${failed_repos}" ]] - then - commit_message+="\nFollowing repos failed repo health checks\n ${failed_repo_names}" - - for full_name in "${failed_repos[@]}" - do - OUTPUT_FILE_NAME="${full_name}${OUTPUT_FILE_POSTFIX}" - echo "reverting repo health data for ${OUTPUT_FILE_NAME}" - git checkout -- "individual_repo_data/${OUTPUT_FILE_NAME}" - done - fi - - git add --all - git status - git diff-index --quiet HEAD || git commit -m ${commit_message} - git push origin master - -fi - -if [[ ${#failed_repos[@]} -ne 0 ]]; then - echo - echo - echo "TLDR Runbook(More detailed runbook: https://openedx.atlassian.net/wiki/spaces/AT/pages/3229057351/Repo+Health+Runbook ):" - echo " To resolve, search the console output for 'ERRORS' (without the quotes), or search for any" - echo " of the failed repo names listed below." - echo "The following repositories failed while executing pytest repo-health scripts causing the job to fail:" - echo - echo " ${failed_repos[*]}" - echo - echo - exit 1 -fi