From 999215d9b5ced14eb00d1027aa1eef76799d1f63 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Thu, 6 Feb 2025 18:42:22 +0100 Subject: [PATCH] fix: emit proper URL in publish help (#1836) --- src/alire/alire-formatting.adb | 23 ++++++++++++ src/alire/alire-formatting.ads | 6 +++- src/alire/alire-meta.ads | 3 ++ src/alr/alr-commands-publish.adb | 41 ++++++++++++++++++++++ src/alr/alr-commands-publish.ads | 26 +------------- testsuite/tests/publish/help-url/test.py | 15 ++++++++ testsuite/tests/publish/help-url/test.yaml | 4 +++ 7 files changed, 92 insertions(+), 26 deletions(-) create mode 100644 testsuite/tests/publish/help-url/test.py create mode 100644 testsuite/tests/publish/help-url/test.yaml diff --git a/src/alire/alire-formatting.adb b/src/alire/alire-formatting.adb index 35f8046d..94aaf2a9 100644 --- a/src/alire/alire-formatting.adb +++ b/src/alire/alire-formatting.adb @@ -2,8 +2,10 @@ with AAA.Enum_Tools; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Alire.Meta; with Alire.OS_Lib; with Alire.Platforms.Current; +with Alire.Version; package body Alire.Formatting is @@ -38,6 +40,27 @@ package body Alire.Formatting is return Result; end For_Archive_Download; + -------------------- + -- For_Github_URL -- + -------------------- + + function For_Github_URL return Replacements is + -- Examples: + -- https://github.com/alire-project/alire/blob/v2.0.2/doc/publishing.md + -- https://github.com/alire-project/alire/blob/master/doc/publishing.md + Result : Replacements; + begin + if Version.Current.Pre_Release /= "" then + Result.Insert (Formatting.Alire_Version, + Meta.Working_Tree.Main_Branch); + else + Result.Insert (Formatting.Alire_Version, + "v" & AAA.Strings.Head (Version.Current.Image, "+")); + end if; + + return Result; + end For_Github_URL; + ------------------------------ -- For_Manifest_Environment -- ------------------------------ diff --git a/src/alire/alire-formatting.ads b/src/alire/alire-formatting.ads index a22fc585..f798da2d 100644 --- a/src/alire/alire-formatting.ads +++ b/src/alire/alire-formatting.ads @@ -4,7 +4,8 @@ private with Ada.Containers.Indefinite_Ordered_Maps; package Alire.Formatting is - type Patterns is (Crate_Root, + type Patterns is (Alire_Version, + Crate_Root, Dest, Distrib_Root, GPR_File, @@ -29,6 +30,9 @@ package Alire.Formatting is Prj_File : Relative_Path) return Replacements; + function For_Github_URL return Replacements; + -- ${ALIRE_VERSION} --> vX.Y.Z or master if a devel version + function Contains (This : Replacements; Pattern : Patterns) return Boolean; function Value (This : Replacements; Pattern : Patterns) return String diff --git a/src/alire/alire-meta.ads b/src/alire/alire-meta.ads index c8d25993..0e5f1b43 100644 --- a/src/alire/alire-meta.ads +++ b/src/alire/alire-meta.ads @@ -9,6 +9,9 @@ package Alire.Meta with Preelaborate is Commit : constant String := "unknown"; Changes : constant String := "unknown"; + Main_Branch : constant String := "master"; + -- In case some day we rename the master branch in the repo + end Working_Tree; end Alire.Meta; diff --git a/src/alr/alr-commands-publish.adb b/src/alr/alr-commands-publish.adb index f3e7357d..63441939 100644 --- a/src/alr/alr-commands-publish.adb +++ b/src/alr/alr-commands-publish.adb @@ -1,3 +1,4 @@ +with Alire.Formatting; with Alire.Origins; with Alire.Publish.States; with Alire.URI; @@ -5,8 +6,13 @@ with Alire.Utils; package body Alr.Commands.Publish is + package Format renames Alire.Formatting; package URI renames Alire.URI; + ------------ + -- To_Int -- + ------------ + function To_Int (S : String) return Integer is begin return Integer'Value (S); @@ -140,6 +146,41 @@ package body Alr.Commands.Publish is end if; end Execute; + ---------------------- + -- Long_Description -- + ---------------------- + + overriding + function Long_Description (Cmd : Command) + return AAA.Strings.Vector + is (AAA.Strings.Empty_Vector + .Append ("Checks a release and generates an index manifest.") + .New_Line + .Append ("See full details at") + .New_Line + .Append + (" https://github.com/alire-project/alire/blob" + & Format.Format ("/${ALIRE_VERSION}/", Format.For_Github_URL, + Convert_Path_Seps => False) + & "doc/publishing.md") + .New_Line + .Append ("URL is an optional path to a remote source archive, or" + & " a local or remote git repository.") + .New_Line + .Append ("For the common use case of a github-hosted repository," + & " issue `alr publish` after committing and pushing" + & " the new release version.") + .New_Line + .Append ("See the above link for instructions on how to create a " + & "Github Personal Access Token (PAT), needed to allow `alr` to " + & "interact with Github (forking, PR creation) on your behalf.") + .New_Line + .Append ("Use --tar to create a source archive ready to be uploaded.") + .New_Line + .Append ("Use --manifest to use metadata in a non-default file.") + .New_Line + .Append ("See the above link for help with other scenarios.")); + -------------------- -- Setup_Switches -- -------------------- diff --git a/src/alr/alr-commands-publish.ads b/src/alr/alr-commands-publish.ads index 9b743c07..ae4de28b 100644 --- a/src/alr/alr-commands-publish.ads +++ b/src/alr/alr-commands-publish.ads @@ -18,31 +18,7 @@ package Alr.Commands.Publish is overriding function Long_Description (Cmd : Command) - return AAA.Strings.Vector - is (AAA.Strings.Empty_Vector - .Append ("Checks a release and generates an index manifest.") - .New_Line - .Append ("See full details at") - .New_Line - .Append (" https://github.com/alire-project/alire/blob/master/" - & "doc/publishing.md") - .New_Line - .Append ("URL is an optional path to a remote source archive, or" - & " a local or remote git repository.") - .New_Line - .Append ("For the common use case of a github-hosted repository," - & " issue `alr publish` after committing and pushing" - & " the new release version.") - .New_Line - .Append ("See the above link for instructions on how to create a " - & "Github Personal Access Token (PAT), needed to allow `alr` to " - & "interact with Github (forking, PR creation) on your behalf.") - .New_Line - .Append ("Use --tar to create a source archive ready to be uploaded.") - .New_Line - .Append ("Use --manifest to use metadata in a non-default file.") - .New_Line - .Append ("See the above link for help with other scenarios.")); + return AAA.Strings.Vector; overriding procedure Setup_Switches diff --git a/testsuite/tests/publish/help-url/test.py b/testsuite/tests/publish/help-url/test.py new file mode 100644 index 00000000..86cff328 --- /dev/null +++ b/testsuite/tests/publish/help-url/test.py @@ -0,0 +1,15 @@ +""" +Verify proper URL given in help for `alr publish`, matching alr version or +master branch. +""" + +from drivers.alr import run_alr +from drivers.asserts import assert_substring + +version = run_alr("--version").out.split()[1] +tag = "master" if '-' in version else f"v{version}" + +assert_substring(f"/{tag}/doc/publishing.md", + run_alr("publish", "--help").out) + +print("SUCCESS") diff --git a/testsuite/tests/publish/help-url/test.yaml b/testsuite/tests/publish/help-url/test.yaml new file mode 100644 index 00000000..70201052 --- /dev/null +++ b/testsuite/tests/publish/help-url/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +build_mode: both +indexes: + compiler_only_index: {} -- 2.39.5