Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix paths #5

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ Insights Engineering

_Default_: `""`

* `extra-deps`:

_Description_: List of extra dependencies to check against feature branch existence. Multiple entries in new lines or separated by commas. It allows to control indirect dependencies. This requires an entry in the `lookup-refs` input.

_Required_: `false`

_Default_: `""`

* `dependencies`:

_Description_: Passed to `r-lib/actions/setup-r-dependencies`.
Expand Down
104 changes: 45 additions & 59 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ inputs:
Only GitHub references are supported.
required: false
default: ""
extra-deps:
description: |
List of extra dependencies to check against feature branch existence.
Multiple entries in new lines or separated by commas. It allows to control indirect dependencies.
This requires an entry in the `lookup-refs` input.
required: false
default: ""
dependencies:
description: Passed to `r-lib/actions/setup-r-dependencies`.
required: false
Expand Down Expand Up @@ -69,6 +62,18 @@ runs:
id: branch-names
uses: tj-actions/branch-names@v8

- name: Get current branch or tag 🏷️
id: current-branch-or-tag
run: |
if [ "${{ steps.branch-names.outputs.is_tag }}" == "true" ]; then
echo "Current tag: ${{ steps.branch-names.outputs.tag }}"
echo "ref-name=${{ steps.branch-names.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "Current branch: ${{ steps.branch-names.outputs.current_branch }}"
echo "ref-name=${{ steps.branch-names.outputs.current_branch }}" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Install required packages
uses: r-lib/actions/setup-r-dependencies@v2
with:
Expand All @@ -93,7 +98,7 @@ runs:
d$set_list(key, new_values)
}
desc_field_clear_if_empty <- function(d, key) {
if (d$get_field(key) == "") {
if (d$has_fields(key) && d$get_field(key) == "") {
d$del(key)
}
}
Expand Down Expand Up @@ -135,9 +140,9 @@ runs:
x$solve()
x$get_solution()$status == "OK"
}
new_pkg_deps <- function(path) {
new_pkg_deps <- function(refs) {
pkgdepends::new_pkg_deps(
path,
refs,
config = list(
dependencies = c(
sprintf("Config/Needs/%s", strsplit("${{ inputs.needs }}", "[[:space:],]+")[[1]]),
Expand Down Expand Up @@ -166,7 +171,8 @@ runs:
- name: Prepare DESCRIPTION file (feature branch)
if: >
inputs.skip-desc-branch == 'false' &&
steps.branch-names.outputs.is_default != 'true'
steps.branch-names.outputs.is_default != 'true' &&
inputs.lookup-refs != ''
id: desc-branch
shell: Rscript {0}
run: |
Expand All @@ -175,11 +181,10 @@ runs:
cat("::endgroup::\n")

cat("::group::Parse inputs\n")
lookup_refs <- parse_input("${{ inputs.lookup-refs }}")
extra_deps <- parse_input("${{ inputs.extra-deps }}")
path <- parse_input("${{ inputs.repository-path }}")
current_branch <- parse_input("${{ steps.branch-names.outputs.current_branch }}")
log_vars(lookup_refs, extra_deps, path, current_branch)
lookup_refs <- parse_input("${{ inputs.lookup-refs }}")
current_branch <- parse_input("${{ steps.current-branch-or-tag.outputs.ref-name }}")
log_vars(path, lookup_refs, current_branch)
cat("::endgroup::\n")

cat("::group::Assertions\n")
Expand All @@ -188,11 +193,6 @@ runs:
cat("::endgroup::\n")
q(save = "no")
}
if (length(lookup_refs) == 0 || identical(lookup_refs, "")) {
cli::cli_alert_danger("No lookup refs provided. Skipping.")
cat("::endgroup::\n")
q(save = "no")
}
parsed_lookup_refs <- pkgdepends::parse_pkg_refs(lookup_refs)
if (any(!vapply(parsed_lookup_refs, is, logical(1), "remote_ref_github"))) {
incorrect_idx <- which(!vapply(parsed_lookup_refs, is, logical(1), "remote_ref_github"))
Expand All @@ -203,43 +203,32 @@ runs:
cat("::endgroup::\n")

cat("::group::Modify DESCRIPTION file (feature branch)\n")
x <- new_pkg_deps(path)
x$solve()
d <- x$get_resolution()[1, "extra"][[1]]$description

d <- desc::desc(path)
d$set_list("Config/Needs/DepsBranch", character(0))

deps <- d$get_deps()
if (length(extra_deps) > 0 && !identical(extra_deps, "")) {
cli::cli_alert_info("Adding extra dependencies: {.val {paste(extra_deps, collapse = \", \")}}.")
deps <- rbind(deps, data.frame(type = "Extra", package = extra_deps, version = "*"))
}
x <- new_pkg_deps(sprintf("local::%s", path))
x$resolve()
deps <- x$get_resolution()$package

for (i in seq_len(nrow(deps))) {
x_type <- deps[i, "type"]
x_package <- deps[i, "package"]
x_version_str <- deps[i, "version"]
cli::cli_alert_info("Processing dependent package {.pkg {x_package}}.")
for (i_ref in lookup_refs) {
cli::cli_alert_info("Processing lookup reference {.field {i_ref}}.")

if (x_package %in% c("R", "base", "utils", "stats", "graphics", "grDevices", "datasets", "methods", "tools", "parallel", "compiler")) {
cli::cli_alert_info("Package {.pkg {x_package}} is a base package. Skipping.")
next
}
i_remote_ref <- pkgdepends::parse_pkg_ref(i_ref)
i_package <- i_remote_ref$package

x_remote_ref <- find_ref(x_package, lookup_refs)
if (length(x_remote_ref) == 0) {
cli::cli_alert_info("Package {.pkg {x_package}} not found in the {.code lookup_refs} list. Skipping.")
if (isFALSE(i_package %in% deps)) {
cli::cli_alert_info("Package {.pkg {i_package}} is not a dependency. Skipping.")
next
}

x_remote_ref_branch <- remote_ref_add_branch(x_remote_ref, current_branch)
if (isFALSE(remote_ref_ping(x_remote_ref_branch))) {
cli::cli_alert_info("Feature branch {.field {current_branch}} does not exist for package {.pkg {x_package}}. Skipping.")
i_remote_ref_branch <- remote_ref_add_branch(i_remote_ref, current_branch)
if (isFALSE(remote_ref_ping(i_remote_ref_branch))) {
cli::cli_alert_info("Feature branch {.field {current_branch}} does not exist for reference {.field {i_ref}}. Skipping.")
next
}

desc_field_append(d, "Config/Needs/DepsBranch", x_remote_ref_branch$ref)
cli::cli_alert_success("Package {.pkg {x_package}} added to the {.code Config/Needs/DepsBranch} field.")
desc_field_append(d, "Config/Needs/DepsBranch", i_remote_ref_branch$ref)
cli::cli_alert_success("Reference {.field {i_remote_ref_branch$ref}} added to the {.field Config/Needs/DepsBranch} field.")
}

desc_field_clear_if_empty(d, "Config/Needs/DepsBranch")
Expand All @@ -256,7 +245,9 @@ runs:
cat("::endgroup::\n")

- name: Prepare DESCRIPTION file (development)
if: ${{ inputs.skip-desc-dev == 'false' }}
if: >
${{ inputs.skip-desc-dev == 'false' }} &&
${{ inputs.lookup-refs != '' }}
id: desc-dev
shell: Rscript {0}
run: |
Expand All @@ -265,10 +256,10 @@ runs:
cat("::endgroup::\n")

cat("::group::Parse inputs\n")
lookup_refs <- parse_input("${{ inputs.lookup-refs }}")
path <- parse_input("${{ inputs.repository-path }}")
lookup_refs <- parse_input("${{ inputs.lookup-refs }}")
max_iter <- as.integer("${{ inputs.max-iter }}")
log_vars(lookup_refs, path, max_iter)
log_vars(path, lookup_refs, max_iter)
cat("::endgroup::\n")

cat("::group::Assertions\n")
Expand All @@ -277,11 +268,6 @@ runs:
cat("::endgroup::\n")
q(save = "no")
}
if (length(lookup_refs) == 0 || identical(lookup_refs, "")) {
cli::cli_alert_danger("No lookup refs provided. Skipping.")
cat("::endgroup::\n")
q(save = "no")
}
parsed_lookup_refs <- pkgdepends::parse_pkg_refs(lookup_refs)
if (any(!vapply(parsed_lookup_refs, is, logical(1), "remote_ref_github"))) {
incorrect_idx <- which(!vapply(parsed_lookup_refs, is, logical(1), "remote_ref_github"))
Expand All @@ -292,12 +278,12 @@ runs:
cat("::endgroup::\n")

cat("::group::Modify DESCRIPTION file (development)\n")
x <- new_pkg_deps(path)
x$solve()
d <- x$get_resolution()[1, "extra"][[1]]$description

d <- desc::desc(path)
d$set_list("Config/Needs/DepsDev", character(0))

x <- new_pkg_deps(sprintf("local::%s", path))
x$solve()

i <- 0L
failures_message_prev <- NULL
while (i <= max_iter) {
Expand Down Expand Up @@ -339,7 +325,7 @@ runs:

cli::cli_alert_info("Trying to resolve dependencies again.")
cli::cli_text("---")
x <- new_pkg_deps(path)
x <- new_pkg_deps(sprintf("local::%s", path))
}

desc_field_clear_if_empty(d, "Config/Needs/DepsDev")
Expand Down
Loading