Skip to content

Commit

Permalink
Allow to overwrite the dev-repo field when creating a GH tag/release
Browse files Browse the repository at this point in the history
This is useful for private projects where it's (sometimes) unclear
what's the dev-repo field should look like.
  • Loading branch information
samoht committed Dec 16, 2024
1 parent 80ce7b5 commit 754ae86
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
7 changes: 4 additions & 3 deletions bin/bistro.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ let bistro () (`Dry_run dry_run) (`Package_names pkg_names)
(`Include_submodules include_submodules) (`Draft draft)
(`Keep_build_dir keep_dir) (`Skip_lint skip_lint) (`Skip_build skip_build)
(`Skip_tests skip_tests) (`Local_repo local_repo) (`Remote_repo remote_repo)
(`Opam_repo opam_repo) (`No_auto_open no_auto_open) =
(`Opam_repo opam_repo) (`No_auto_open no_auto_open) (`Dev_repo dev_repo) =
Cli.handle_error
( Dune_release.Config.token ~token ~dry_run () >>= fun token ->
let token = Dune_release.Config.Cli.make token in
Distrib.distrib ~dry_run ~pkg_names ~version ~tag ~keep_v ~keep_dir
~skip_lint ~skip_build ~skip_tests ~include_submodules ()
>! fun () ->
Publish.publish ~token ~pkg_names ~version ~tag ~keep_v ~dry_run
Publish.publish ~token ~pkg_names ~version ~tag ~keep_v ~dry_run ?dev_repo
~publish_artefacts:[] ~yes:false ~draft ()
>! fun () ->
Opam.get_pkgs ~dry_run ~keep_v ~tag ~pkg_names ~version () >>= fun pkgs ->
Expand Down Expand Up @@ -55,7 +55,8 @@ let term =
const bistro $ Cli.setup $ Cli.dry_run $ Cli.pkg_names $ Cli.pkg_version
$ Cli.dist_tag $ Cli.keep_v $ Cli.token $ Cli.include_submodules $ Cli.draft
$ Cli.keep_build_dir $ Cli.skip_lint $ Cli.skip_build $ Cli.skip_tests
$ Cli.local_repo $ Cli.remote_repo $ Cli.opam_repo $ Cli.no_auto_open)
$ Cli.local_repo $ Cli.remote_repo $ Cli.opam_repo $ Cli.no_auto_open
$ Cli.dev_repo)

let info = Cmd.info "bistro" ~doc ~sdocs ~exits ~man ~man_xrefs
let cmd = Cmd.v info term
Expand Down
9 changes: 9 additions & 0 deletions bin/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ let remote_repo =
in
named (fun x -> `Remote_repo x) (config_opt arg)

let dev_repo =
let doc = "Location of the dev repo of the current package" in
let env = Cmd.Env.info "DUNE_RELEASE_DEV_REPO" in
let arg =
Arg.(
value & opt (some string) None & info ~env [ "dev-repo" ] ~doc ~docv:"URI")
in
named (fun x -> `Dev_repo x) arg

let opam_repo =
let doc =
"The Github opam-repository to which packages should be released. Use this \
Expand Down
6 changes: 5 additions & 1 deletion bin/cli.mli
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ val local_repo :
(** A [--local-repo] option to define the location of the local fork of
opam-repository. *)

val dev_repo : [ `Dev_repo of string option ] Term.t
(** A [--dev-repo] option to define the Github opam-repository to which packages
should be released. *)

val remote_repo :
[ `Remote_repo of string Dune_release.Config.Cli.t option ] Term.t
(** A [--remote-repo] option to define the location of the remote fork of
opam-repository. *)

val opam_repo : [ `Opam_repo of (string * string) option ] Term.t
(** A [--opam_repo] option to define the Github opam-repository to which
(** A [--opam-repo] option to define the Github opam-repository to which
packages should be released. *)

val skip_lint : [> `Skip_lint of bool ] Term.t
Expand Down
17 changes: 9 additions & 8 deletions bin/publish.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ let publish_doc ~specific ~dry_run ~yes pkg_names pkg =
Ok ()
| Ok _ -> publish_doc ~dry_run ~yes pkg_names pkg

let publish_distrib ?token ~dry_run ~yes ~draft pkg =
let publish_distrib ?token ~dry_run ~yes ~draft ?dev_repo pkg =
App_log.status (fun l -> l "Publishing distribution");
Pkg.distrib_file ~dry_run pkg >>= fun archive ->
Pkg.publish_msg pkg >>= fun msg ->
App_log.status (fun l -> l "Publishing to github");
Config.token ~token ~dry_run () >>= fun token ->
Github.publish_distrib ~token ~dry_run ~yes ~msg ~archive ~draft pkg
Github.publish_distrib ~token ~dry_run ~yes ~msg ~archive ~draft ?dev_repo pkg
>>= fun url ->
Pkg.archive_url_path pkg >>= fun url_file ->
Sos.write_file ~dry_run url_file url >>= fun () -> Ok ()

let publish ?build_dir ?opam ?change_log ?distrib_file ?publish_msg ?token
~pkg_names ~version ~tag ~keep_v ~dry_run ~publish_artefacts ~yes ~draft ()
=
?dev_repo ~pkg_names ~version ~tag ~keep_v ~dry_run ~publish_artefacts ~yes
~draft () =
let specific_doc =
List.exists (function `Doc -> true | _ -> false) publish_artefacts
in
Expand All @@ -80,7 +80,7 @@ let publish ?build_dir ?opam ?change_log ?distrib_file ?publish_msg ?token
acc >>= fun () ->
match artefact with
| `Doc -> publish_doc ~specific:specific_doc ~dry_run ~yes pkg_names pkg
| `Distrib -> publish_distrib ?token ~dry_run ~yes ~draft pkg
| `Distrib -> publish_distrib ?token ~dry_run ~yes ~draft ?dev_repo pkg
in
List.fold_left publish_artefact (Ok ()) publish_artefacts >>= fun () -> Ok 0

Expand All @@ -89,9 +89,10 @@ let publish_cli () (`Build_dir build_dir) (`Package_names pkg_names)
(`Dist_opam opam) (`Change_log change_log) (`Dist_file distrib_file)
(`Publish_msg publish_msg) (`Dry_run dry_run)
(`Publish_artefacts publish_artefacts) (`Yes yes) (`Token token)
(`Draft draft) =
(`Draft draft) (`Dev_repo dev_repo) =
publish ?build_dir ?opam ?change_log ?distrib_file ?publish_msg ?token
~pkg_names ~version ~tag ~keep_v ~dry_run ~publish_artefacts ~yes ~draft ()
~pkg_names ~version ~tag ~keep_v ~dry_run ~publish_artefacts ~yes ~draft
?dev_repo ()
|> Cli.handle_error

(* Command line interface *)
Expand Down Expand Up @@ -149,7 +150,7 @@ let term =
const publish_cli $ Cli.setup $ Cli.build_dir $ Cli.pkg_names
$ Cli.pkg_version $ Cli.dist_tag $ Cli.keep_v $ Cli.dist_opam
$ Cli.change_log $ Cli.dist_file $ Cli.publish_msg $ Cli.dry_run $ artefacts
$ Cli.yes $ Cli.token $ Cli.draft)
$ Cli.yes $ Cli.token $ Cli.draft $ Cli.dev_repo)

let info = Cmd.info "publish" ~doc ~sdocs ~exits ~man ~man_xrefs
let cmd = Cmd.v info term
Expand Down
1 change: 1 addition & 0 deletions bin/publish.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ val publish :
?distrib_file:Fpath.t ->
?publish_msg:string ->
?token:string Dune_release.Config.Cli.t ->
?dev_repo:string ->
pkg_names:string list ->
version:Dune_release.Version.t option ->
tag:Dune_release.Vcs.Tag.t option ->
Expand Down
9 changes: 6 additions & 3 deletions lib/github.ml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ let undraft_pr ~token ~dry_run ~opam_repo:(user, repo) ~pr_id =
run_with_auth ~dry_run ~default_body curl_t
>>= Github_v4_api.Pull_request.Response.url

let dev_repo p =
let pkg_dev_repo p =
Pkg.dev_repo p >>= function
| Some r -> Ok r
| None ->
Expand Down Expand Up @@ -432,13 +432,16 @@ let create_release ~dry_run ~yes ~dev_repo ~token ~msg ~tag ~version ~user ~repo
App_log.status (fun l -> l "Release with id %d already exists" id);
Ok id

let publish_distrib ~token ~dry_run ~msg ~archive ~yes ~draft p =
let publish_distrib ~token ?dev_repo ~dry_run ~msg ~archive ~yes ~draft p =
Pkg.infer_github_repo p >>= fun { owner; repo } ->
Pkg.tag p >>= fun tag ->
assert_tag_exists ~dry_run tag >>= fun () ->
Vcs.get () >>= fun vcs ->
check_tag ~dry_run vcs tag >>= fun () ->
dev_repo p >>= fun dev_repo ->
let dev_repo =
match dev_repo with Some d -> Ok d | None -> pkg_dev_repo p
in
dev_repo >>= fun dev_repo ->
Pkg.build_dir p >>= fun build_dir ->
Pkg.name p >>= fun name ->
Pkg.version p >>= fun version ->
Expand Down
1 change: 1 addition & 0 deletions lib/github.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ end

val publish_distrib :
token:string ->
?dev_repo:string ->
dry_run:bool ->
msg:string ->
archive:Fpath.t ->
Expand Down

0 comments on commit 754ae86

Please sign in to comment.