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

Improvements to publishing with automatic PR creation #1398

Merged
merged 17 commits into from
Jul 3, 2023
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
3 changes: 2 additions & 1 deletion alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ajunitgen = "^1.0.1"
ansiada = "^1.0"
clic = "~0.3"
gnatcoll = "^21"
minirest = "~0.2"
minirest = "~0.3"
optional = "~0.1"
semantic_versioning = "^3.0"
simple_logging = "^2.0"
Expand Down Expand Up @@ -49,6 +49,7 @@ aaa = { url = "https://github.com/mosteo/aaa", commit = "f60254934a7d6e39b72380b
ada_toml = { url = "https://github.com/mosteo/ada-toml", commit = "da4e59c382ceb0de6733d571ecbab7ea4919b33d" }
clic = { url = "https://github.com/alire-project/clic", commit = "8d26222de71014554999e48c821906fca0e3dc41" }
gnatcoll = { url = "https://github.com/alire-project/gnatcoll-core.git", commit = "403efe11405113cf12ae3d014df474cf7a046176" }
minirest = { url = "https://github.com/mosteo/minirest.git", commit = "9045d8faafcea996fa7b51ccda84c54712eff821" }
semantic_versioning = { url = "https://github.com/alire-project/semantic_versioning", commit = "2f23fc5f6b4855b836b599adf292fed9c0ed4144" }
simple_logging = { url = "https://github.com/alire-project/simple_logging", commit = "3505dc645f3eef6799a486aae223d37e88cfc4d5" }
stopwatch = { url = "https://github.com/mosteo/stopwatch", commit = "f607a63b714f09bbf6126de9851cbc21cf8666c9" }
2 changes: 1 addition & 1 deletion deps/minirest
16 changes: 16 additions & 0 deletions doc/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ command. The steps to take are described after some introductory concepts (jump
to these steps directly [here](#detailed-steps); you can also ask for help on
the [gitter channel](https://gitter.im/ada-lang/Alire) of the project.

## Automated publishing (TL;DR.)

The simplest publishing experience, provided you have a GitHub account and
Personal Access Token, consist on issuing
```
alr publish --submit
```
at the root of your workspace, when said workspace is an up-to-date clone of a
git repository.

The publishing assistant will review your submission, point out any necessary
fixes or additional information required, and provide you with a tracking URL.

Read on for the details underlying these automated steps, or in case you need
to perform further tweaking.

## General concepts

The community index is a collection of
Expand Down
20 changes: 19 additions & 1 deletion doc/user-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ stay on top of `alr` new features.

## Release `2.0-dev`

### Automatic release submission during `alr publish`

PR [#1398](https://github.com/alire-project/alire/pull/1398)

`alr publish` will now prompt to continue after manifest creation into a series
of steps culminating on the creation of a draft pull request on the community
index repository.

The new steps will perform all necessary actions: forking of the community
repository into the user account, cloning, committing of the new manifest, and
pull request creation.

For `alr` to be able to do these steps on the user's behalf, the user has to
provide a 'Personal Access Token (PAT)' with 'repo' permissions.

The old behavior, ending the assistant after manifest creation, can be achieved
with the new `--skip-submit` flag.

### Removal of `alr test --docker`

PR [#1366](https://github.com/alire-project/alire/pull/1366)
Expand Down Expand Up @@ -58,7 +76,7 @@ manually move the contents to avoid redownloading toolchains.

### Installation of indexed crates

PR [#1322](https://github.com/alire-project/alire/pull/1335)
PR [#1335](https://github.com/alire-project/alire/pull/1335)

It is now possible to install an indexed crate directly:
```
Expand Down
15 changes: 15 additions & 0 deletions src/alire/alire-config-edit.ads
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ private
" character. The token ${GPR_FILE} is replaced by" &
" a path to the project file to open.")),

(+Keys.Index_Host,
Cfg_String,
+("URL of the community index host, defaults to "
& Defaults.Index_Host)),

(+Keys.Index_Owner,
Cfg_String,
+("Owner of the index repository (GitHub user/org), defaults to "
& Defaults.Index_Owner)),

(+Keys.Index_Repo_Name,
Cfg_String,
+("Name of the index repository, defaults to "
& Defaults.Index_Repo_Name)),

(+Keys.Msys2_Do_Not_Install,
Cfg_Bool,
+("If true, Alire will not try to automatically" &
Expand Down
10 changes: 10 additions & 0 deletions src/alire/alire-config.ads
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ package Alire.Config with Preelaborate is
-- When unset (default) or true, add the community index if no other
-- index is already configured.

Index_Host : constant Config_Key := "index.host";
Index_Owner : constant Config_Key := "index.owner";
Index_Repo_Name : constant Config_Key := "index.repository_name";
-- These three conform the URL where the community index is hosted,
-- allowing to override the default.

Solver_Autonarrow : constant Config_Key := "solver.autonarrow";
-- When true, `alr with` will substitute "any" dependencies by the
-- appropriate caret/tilde.
Expand Down Expand Up @@ -84,6 +90,10 @@ package Alire.Config with Preelaborate is

Warning_Old_Index : constant Boolean := True;

Index_Host : constant String := "https://github.com";
Index_Owner : constant String := "alire-project";
Index_Repo_Name : constant String := "alire-index";

end Defaults;

end Alire.Config;
68 changes: 53 additions & 15 deletions src/alire/alire-directories.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ with Ada.Exceptions;
with Ada.Numerics.Discrete_Random;
with Ada.Unchecked_Deallocation;

with Alire.Errors;
with Alire.OS_Lib.Subprocess;
with Alire.Paths;
with Alire.Platforms.Current;
with Alire.Platforms.Folders;
with Alire.VFS;

with GNATCOLL.VFS;
Expand All @@ -16,8 +16,6 @@ with SI_Units.Binary;

package body Alire.Directories is

package Adirs renames Ada.Directories;

-------------------
-- Temp_Registry --
-------------------
Expand Down Expand Up @@ -212,18 +210,26 @@ package body Alire.Directories is
procedure Ensure_Deletable (Path : Any_Path) is
use Ada.Directories;
begin
if Exists (Path) and then
Kind (Path) = Directory and then
Platforms.Current.Operating_System in Platforms.Windows
if Platforms.Current.Operating_System in Platforms.Windows
and then Exists (Path)
then
Trace.Debug ("Forcing writability of dir " & Path);
OS_Lib.Subprocess.Checked_Spawn
("attrib",
AAA.Strings.Empty_Vector
.Append ("-R") -- Remove read-only
.Append ("/D") -- On dirs
.Append ("/S") -- Recursively
.Append (Path & "\*"));
if Kind (Path) = Directory then
Trace.Debug ("Forcing writability of dir " & Path);
OS_Lib.Subprocess.Checked_Spawn
("attrib",
AAA.Strings.Empty_Vector
.Append ("-R") -- Remove read-only
.Append ("/D") -- On dirs
.Append ("/S") -- Recursively
.Append (Path & "\*"));
elsif Kind (Path) = Ordinary_File then
Trace.Debug ("Forcing writability of dir " & Path);
OS_Lib.Subprocess.Checked_Spawn
("attrib",
AAA.Strings.Empty_Vector
.Append ("-R") -- Remove read-only
.Append (Path));
end if;
end if;
end Ensure_Deletable;

Expand Down Expand Up @@ -407,6 +413,13 @@ package body Alire.Directories is
function Is_Directory (Path : Any_Path) return Boolean
is (Adirs.Exists (Path) and then Adirs.Kind (Path) in Adirs.Directory);

-------------
-- Is_File --
-------------

function Is_File (Path : Any_Path) return Boolean
is (Adirs.Exists (Path) and then Adirs.Kind (Path) in Adirs.Ordinary_File);

----------------
-- TEMP FILES --
----------------
Expand Down Expand Up @@ -461,13 +474,32 @@ package body Alire.Directories is

else

This.Name := +Ada.Directories.Full_Name (Simple_Name);
-- Default to the system temp folder. Note that spawns that capture
-- output may fail if the temp folder is unset (e.g., git commands
-- that clean the current repository).

This.Name := +Ada.Directories.Full_Name (Platforms.Folders.Temp
/ Simple_Name);

end if;

Temp_Registry.Add (+This.Name);
end Initialize;

------------
-- Create --
------------

function Create (This : in out Temp_File) return GNAT.OS_Lib.File_Descriptor
is
begin
if This.FD in GNAT.OS_Lib.Invalid_FD then
This.FD := GNAT.OS_Lib.Create_Output_Text_File (This.Filename);
end if;

return This.FD;
end Create;

--------------
-- Filename --
--------------
Expand Down Expand Up @@ -500,6 +532,11 @@ package body Alire.Directories is
-- We are deleting it here, so remove from "live" temp files registry
Temp_Registry.Del (+This.Name);

-- Close it first, if created and opened by us
if This.FD not in GNAT.OS_Lib.Invalid_FD then
GNAT.OS_Lib.Close (This.FD);
end if;

-- Force writability of folder when in Windows, as some tools (e.g. git)
-- that create read-only files will cause a Use_Error

Expand Down Expand Up @@ -909,6 +946,7 @@ package body Alire.Directories is
return Temp : constant Temp_File :=
(Temp_File'(Ada.Finalization.Limited_Controlled with
Keep => <>,
FD => <>,
Name => +Adirs.Full_Name (Name)))
do
Temp_Registry.Add (+Temp.Name);
Expand Down
15 changes: 15 additions & 0 deletions src/alire/alire-directories.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ with Ada.Directories;

with AAA.Strings;

with Alire.Errors;
with Alire.OS_Lib;

private with Ada.Finalization;

with GNAT.OS_Lib;

package Alire.Directories is

package Adirs renames Ada.Directories;

function "/" (L, R : String) return String renames OS_Lib."/";

-- Package to enable easy use of "/"
Expand Down Expand Up @@ -78,6 +83,9 @@ package Alire.Directories is
function Is_Directory (Path : Any_Path) return Boolean;
-- Returns false for non-existing paths too

function Is_File (Path : Any_Path) return Boolean;
-- False if Path does not designate a regular file

procedure Merge_Contents (Src, Dst : Any_Path;
Skip_Top_Level_Files : Boolean;
Fail_On_Existing_File : Boolean;
Expand Down Expand Up @@ -164,6 +172,12 @@ package Alire.Directories is
-- The file is deleted once an object of this type goes out of scope.
-- If the file/folder was never created on disk nothing will happen.

function Create (This : in out Temp_File) return GNAT.OS_Lib.File_Descriptor
with Post => Create'Result not in GNAT.OS_Lib.Invalid_FD
or else raise Checked_Error
with Errors.Set ("Could not create temporary file at " & This.Filename);
-- Actually creates the file and returns its file descriptor. Idempotent.

function Filename (This : Temp_File) return Absolute_Path;
-- The filename is a random sequence of 8 characters + ".tmp"

Expand Down Expand Up @@ -230,6 +244,7 @@ private
type Temp_File is new Ada.Finalization.Limited_Controlled with record
Keep : Boolean := False;
Name : Unbounded_Absolute_Path;
FD : GNAT.OS_Lib.File_Descriptor := GNAT.OS_Lib.Invalid_FD;
end record;

overriding
Expand Down
3 changes: 3 additions & 0 deletions src/alire/alire-environment.ads
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ package Alire.Environment is
Config : constant String := "ALR_CONFIG";
-- Folder where current alr will look for configuration

Testsuite : constant String := "ALR_TESTSUITE";
-- If defined, we are running under the testsuite harness

type Context is tagged limited private;

procedure Set (This : in out Context; Name, Value, Origin : String);
Expand Down
Loading