diff --git a/.github/workflows/manual-debug.yml b/.github/workflows/manual-debug.yml index d113b58..feb1d6b 100644 --- a/.github/workflows/manual-debug.yml +++ b/.github/workflows/manual-debug.yml @@ -1,71 +1,61 @@ -name: manual-debug - -on: - workflow_dispatch: - inputs: - path: - description: | - Path to the R package root, if the package is not at the top level of - the repository. - default: "." - required: false - type: string - package: - description: | - Package to check. If provided, it would have priority over the - package on the repo. - required: false - default: "" - type: string - statuses: - description: | - Create an issue if one or more of the following statuses are - reported on the check report. This is a comma-separated string of - statuses. Default value is ''WARN,ERROR'. Allowed statuses are - 'NOTE', 'WARN', and 'ERROR'. - default: "WARN,ERROR" - required: false - type: string - fail-on-error: - description: | - Logical, should the action error if CRAN checks are not ok? - default: "false" - required: false - type: boolean - create-issue: - description: | - Logical, create an issue on CRAN failed checks - default: "true" - required: false - type: boolean - issue-assignees: - description: | - Whom should the issue be assigned to if errors are - encountered in the CRAN status checks? - This is a comma-separated string of GitHub usernames. - If undefined or empty, no assignments are made. - default: "" - required: false - type: string - -jobs: - check: - runs-on: ubuntu-latest - permissions: write-all - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - name: Checkout - uses: actions/checkout@v5 - - - name: Check - uses: dieghernan/cran-status-check@main - with: - path: ${{ inputs.path }} - package: ${{ inputs.package }} - statuses: ${{ inputs.statuses }} - fail-on-error: ${{ inputs.fail-on-error }} - create-issue: ${{ inputs.create-issue }} - issue-assignees: ${{ inputs.issue-assignees }} - +name: manual-debug + +on: + workflow_dispatch: + inputs: + path: + description: | + Path to the R package root, if the package is not at the top level of + the repository. + default: "." + required: false + type: string + package: + description: | + Package to check. If provided, it would have priority over the + package on the repo. + required: false + default: "" + type: string + fail-on-error: + description: | + Logical, should the action error if CRAN checks are not ok? + default: "false" + required: false + type: boolean + create-issue: + description: | + Logical, create an issue on CRAN failed checks + default: "true" + required: false + type: boolean + issue-assignees: + description: | + Whom should the issue be assigned to if errors are + encountered in the CRAN status checks? + This is a comma-separated string of GitHub usernames. + If undefined or empty, no assignments are made. + default: "" + required: false + type: string + +jobs: + check: + runs-on: ubuntu-latest + permissions: write-all + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Check + uses: dieghernan/cran-status-check@main + with: + path: ${{ inputs.path }} + package: ${{ inputs.package }} + fail-on-error: ${{ inputs.fail-on-error }} + create-issue: ${{ inputs.create-issue }} + issue-assignees: ${{ inputs.issue-assignees }} + diff --git a/action.yml b/action.yml index d9e765e..46d31fd 100644 --- a/action.yml +++ b/action.yml @@ -19,14 +19,6 @@ inputs: required: false default: "" type: string - statuses: - description: | - CRAN status to check. This is a comma-separated string of - statuses. Default value is ''WARN,ERROR'. Allowed statuses are - 'NOTE', 'WARN', and 'ERROR'. - default: "WARN,ERROR" - required: false - type: string fail-on-error: description: | Logical, should the action error if CRAN checks are not ok? @@ -48,7 +40,12 @@ inputs: default: "" required: false type: string - + statuses: + description: | + DEPRECATED + default: "" + required: false + type: string # Workflow derived from pharmaverse/admiralci # See for the original work from which this workflow is derived # https://github.com/pharmaverse/admiralci/blob/61347fe11955297818b3ca7814fc7328f2ad7840/.github/workflows/cran-status.yml @@ -85,7 +82,6 @@ runs: - name: Compute Cran Status codes uses: dieghernan/cran-status-check/docker@main with: - statuses: "${{ inputs.statuses }}" package: "${{ steps.pkg.outputs.package_name }}" # Report check @@ -116,9 +112,9 @@ runs: - name: Report Status if: steps.err.outputs.error == 'true' && inputs.create-issue == 'true' - uses: peter-evans/create-issue-from-file@v5 + uses: peter-evans/create-issue-from-file@v6 with: - title: "URGENT! Failed CRAN Checks for ${{ steps.pkg.outputs.package_name }}: ${{ steps.today.outputs.date }}" + title: "URGENT! ${{ steps.pkg.outputs.package_name }} at risk on CRAN: ${{ steps.today.outputs.date }}" content-filepath: ././cran-status.md assignees: ${{ inputs.issue-assignees }} @@ -127,6 +123,6 @@ runs: shell: bash run: | # Stop action - echo "::error::CRAN checks are not OK, see Job Summary of this GH action for details" + echo "::error::Package at risk, see Job Summary of this GH action for details" exit 1 diff --git a/docker/action.yml b/docker/action.yml index f69f295..6fae692 100644 --- a/docker/action.yml +++ b/docker/action.yml @@ -1,28 +1,16 @@ -# Workflow derived from https://github.com/pharmaverse/admiralci - -name: CRAN Status Check -description: Creates a summary of issues reported on the CRAN status check page for a given R package - -inputs: - package: - description: | - Package name of the current R package deployed to CRAN - required: true - type: string - statuses: - description: | - Create an issue if one or more of the following - statuses are reported on the check report. - This is a comma-separated string of statuses. - Allowed statuses are 'NOTE', 'WARN', and 'ERROR' - default: 'ERROR' - required: false - type: string - -runs: - using: 'docker' - image: './Dockerfile' - args: - - ${{ inputs.package }} - - ${{ inputs.statuses }} - +# Workflow derived from https://github.com/pharmaverse/admiralci + +name: CRAN Status Check +description: Creates a summary of issues reported on the CRAN status check page for a given R package + +inputs: + package: + description: | + Package name of the current R package deployed to CRAN + required: true + type: string +runs: + using: 'docker' + image: './Dockerfile' + args: + - ${{ inputs.package }} diff --git a/docker/check-status.R b/docker/check-status.R index 3e0b46d..3bcf861 100644 --- a/docker/check-status.R +++ b/docker/check-status.R @@ -26,11 +26,6 @@ option_list <- list( type = "character", help = "package name (REQUIRED)", metavar = "character" - ), - make_option(c("-s", "--statuses"), - type = "character", default = "ERROR,WARN,NOTE", - help = "status types (comma separated list, e.g. ERROR,WARN,NOTE", - metavar = "character" ) ) opt_parser <- OptionParser(option_list = option_list) @@ -43,17 +38,21 @@ cran_status <- function(x) { # 2. Get Inputs ---- pkg <- opt$package # paste(desc::desc_get(keys = "Package")) -# Get input status -status_types <- opt$statuses -statuses <- unlist(strsplit(status_types, split = ",")) - url <- sprintf("https://cran.r-project.org/web/checks/check_results_%s.html", pkg) # 3. Tests ----- cat("Testing package:", pkg, "\n-----\n") -## a. Url not reachable ---- -if (httr::http_error(url)) { +# Getting database +options(repos = c(CRAN = "https://cloud.r-project.org")) +pkg_db <- tools::CRAN_package_db() %>% + as_tibble() %>% + filter(Package == pkg) + + +## a. Not in database ---- + +if (nrow(pkg_db) == 0) { cat( paste0("::warning::Package ", pkg, " not found on CRAN.") ) @@ -62,15 +61,17 @@ if (httr::http_error(url)) { paste0(":x: **Package ", pkg, " not found on CRAN**:\n\n") ) - cran_status(paste0("Error accessing url:\n", url)) + cran_status(paste0("Check url:\n", url)) # Copy to issue file.copy("cran-status.md", "issue.md") } -## b. Found on CRAN, check issues ---- +## b. Found on CRAN, check deadline ---- if (!file.exists("cran-status.md")) { + deadline <- pkg_db %>% pull(Deadline) + scrap <- url %>% read_html() @@ -78,25 +79,39 @@ if (!file.exists("cran-status.md")) { html_element("table") %>% html_table() - any_error <- any(cranchecks$Status %in% statuses) additional <- grepl("Additional", html_text(scrap), ignore.case = TRUE) - ### i. Has issues ---- - if (any_error) { + # Is on deadline? + is_deadline <- !is.na(deadline) + + if (is_deadline) { + # Notify cran_status(sprintf( - ":x: **CRAN checks for %s resulted in one or more (`%s`)s**:\n\n", + ":x: **Package %s at risk for removal by `%s`**:\n\n", pkg, - status_types + deadline )) - cran_status("\nSee the table below for a summary of the checks run by CRAN:\n\n") - cran_status(knitr::kable(cranchecks)) + + cat("::warning::Package at risk for removal") + } else { cran_status(sprintf( - "\n\nAll details and logs are available here: %s\n\n", url + ":white_check_mark: **Package %s is not at risk for removal", + pkg )) - cat("::warning::One or more CRAN checks resulted in an invalid status\n") + + cat("Package is not at risk for removal") } - ### ii. Has additional issues ---- + # Additional info + + # Add checks + cran_status("\nSee the table below for a summary of the checks run by CRAN:\n\n") + cran_status(knitr::kable(cranchecks)) + cran_status(sprintf( + "\n\nAll details and logs are available here: %s", url + )) + + # Additional issues if (additional) { cran_status(sprintf( @@ -109,27 +124,7 @@ if (!file.exists("cran-status.md")) { cat(paste0("::warning::", pkg, " has Additional issues\n")) } - ## So far if cran-status.md exists, generate issue - if (file.exists("cran-status.md")) file.copy("cran-status.md", "issue.md") - - ### iii. All OK ---- - # If no issue has been generated - if (!file.exists("cran-status.md")) { - cat( - sprintf("None of this status found in the CRAN table. (status=%s)", status_types) - ) - - cran_status(sprintf( - ":white_check_mark: **CRAN error for %s not found with (`%s`)s**:\n\n", - pkg, - status_types - )) - - cran_status("\nSee the table below for a summary of the checks run by CRAN:\n\n") - cran_status(knitr::kable(cranchecks)) - cran_status(sprintf( - "\n\nAll details and logs are available here: %s", url - )) - } + # Prepare the issue + if (is_deadline) file.copy("cran-status.md", "issue.md") } diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d32c288..dc16670 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -Rscript /app/check-status.R -p "${INPUT_PACKAGE}" -s "${INPUT_STATUSES}" +Rscript /app/check-status.R -p "${INPUT_PACKAGE}"