Skip to content

Instantly share code, notes, and snippets.

@pat-s

pat-s/example.R

Created Mar 17, 2020
Embed
What would you like to do?
init_mlr3learner_drat_deploy
init_mlr3learner_drat_deploy("mlr3learners.mboost") # replace this with the actual learner name
init_mlr3learner_drat_deploy = function(repo_name) {
# generate deploy key pair
key <- openssl::rsa_keygen()
# encrypt private key using tempkey and iv
pub_key <- travis::get_public_key(key)
private_key <- travis::encode_private_key(key)
key_id <- gh::gh("GET /repos/:owner/:repo/actions/secrets/public-key",
owner = travis::get_owner("origin"),
repo = travis::get_repo("origin")
)$key_id
pub_key_gh <- gh::gh("GET /repos/:owner/:repo/actions/secrets/public-key",
owner = travis::get_owner("origin"),
repo = travis::get_repo("origin")
)$key
private_key_raw <- charToRaw(private_key)
# decode public key
pub_key_gh_dec <- base64enc::base64decode(pub_key_gh)
# encrypt using the pub key
private_key_encr <- sodium::simple_encrypt(private_key_raw, pub_key_gh_dec)
# base64 encode secret
private_key_encr <- base64enc::base64encode(private_key_encr)
gh::gh("PUT /repos/:owner/:repo/actions/secrets/:name",
owner = travis::get_owner("origin"),
repo = travis::get_repo("origin"),
name = "id_rsa",
key_id = key_id,
encrypted_value = private_key_encr
)
# add public key
travis::github_add_key(
pubkey = pub_key,
user = "mlr3learners",
repo = "mlr3learners.drat",
title = sprintf("%s deploy key", repo_name),
check_role = FALSE
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment