Skip to content

Commit

Permalink
Fix monorepo bug wrt location of generated manifest (#1684)
Browse files Browse the repository at this point in the history
* Fix monorepo bug wrt location of generated manifest

When deploying crates, to avoid confusion, we replace the packaged manifest (if
any) with the one from the index, which is the one used anyway. For monorepos,
the replacement was placed at the repo root instead of at the crate location.

* Use macOS 12 to avoid linking problems

* Self-review
  • Loading branch information
mosteo committed May 30, 2024
1 parent a52f870 commit 119e690
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/alire/alire-releases.adb
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,24 @@ package body Alire.Releases is
Mark_Completion : Boolean := True)
is
use Alire.Directories;
Folder : constant Any_Path := Parent_Folder / This.Deployment_Folder;
Completed : Flags.Flag := Flags.Complete_Copy (Folder);
Repo_Folder : constant Any_Path :=
Parent_Folder / This.Deployment_Folder;
Rel_Folder : constant Any_Path :=
Parent_Folder / This.Base_Folder;
Completed : Flags.Flag := Flags.Complete_Copy (Repo_Folder);

------------------------------
-- Backup_Upstream_Manifest --
------------------------------

procedure Backup_Upstream_Manifest is
Working_Dir : Guard (Enter (Folder)) with Unreferenced;
Working_Dir : Guard (Enter (Rel_Folder)) with Unreferenced;
begin
Ada.Directories.Create_Path (Paths.Working_Folder_Inside_Root);

if GNAT.OS_Lib.Is_Regular_File (Paths.Crate_File_Name) then
Trace.Debug ("Backing up bundled manifest file as *.upstream");
Trace.Debug ("Backing up bundled manifest file at "
& Adirs.Current_Directory & " as *.upstream");
declare
Upstream_File : constant String :=
Paths.Working_Folder_Inside_Root
Expand Down Expand Up @@ -295,16 +299,17 @@ package body Alire.Releases is
begin
Trace.Debug ("Generating manifest file for "
& This.Milestone.TTY_Image & " with"
& This.Dependencies.Leaf_Count'Img & " dependencies");
& This.Dependencies.Leaf_Count'Img & " dependencies "
& " at " & (Rel_Folder / Paths.Crate_File_Name));

This.Whenever (Env).To_File (Folder / Paths.Crate_File_Name,
This.Whenever (Env).To_File (Rel_Folder / Paths.Crate_File_Name,
Kind);
end Create_Authoritative_Manifest;

begin

Trace.Debug ("Deploying " & This.Milestone.TTY_Image
& " into " & TTY.URL (Folder));
& " into " & TTY.URL (Repo_Folder));

-- Deploy if the target dir is not already there. We only skip for
-- releases that require a folder to be deployed; system releases
Expand All @@ -331,14 +336,14 @@ package body Alire.Releases is
else
Was_There := False;
Put_Info ("Deploying " & This.Milestone.TTY_Image & "...");
Alire.Origins.Deployers.Deploy (This, Folder).Assert;
Alire.Origins.Deployers.Deploy (This, Repo_Folder).Assert;
end if;

-- For deployers that do nothing, we ensure the folder exists so all
-- dependencies leave a trace in the cache/dependencies folder, and
-- a place from where to run their actions by default.

Ada.Directories.Create_Path (Folder);
Ada.Directories.Create_Path (Repo_Folder);

-- Backup a potentially packaged manifest, so our authoritative
-- manifest from the index is always used.
Expand All @@ -349,8 +354,8 @@ package body Alire.Releases is

if Create_Manifest then
Create_Authoritative_Manifest (if Include_Origin
then Manifest.Index
else Manifest.Local);
then Manifest.Index
else Manifest.Local);
end if;

if Mark_Completion then
Expand All @@ -363,10 +368,10 @@ package body Alire.Releases is
-- during an action).
Log_Exception (E);

if Ada.Directories.Exists (Folder) then
if Ada.Directories.Exists (Repo_Folder) then
Trace.Debug ("Cleaning up failed release deployment of "
& This.Milestone.TTY_Image);
Directories.Force_Delete (Folder);
Directories.Force_Delete (Repo_Folder);
end if;

raise;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.1"
54 changes: 54 additions & 0 deletions testsuite/tests/monorepo/manifest-in-place/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Verify that the index manifest is copied in the proper place instead of the one
possibly packed by upstream, like it is done for regular crates.
"""

from glob import glob
import os
from subprocess import run

from drivers.alr import alr_manifest, alr_publish, init_local_crate, run_alr
from drivers.asserts import assert_contents
from drivers.helpers import init_git_repo

# We create a repository with a nested crate that will act as the upstream
# remote repository:

start_dir = os.getcwd()
os.mkdir("monoproject.upstream")
os.chdir("monoproject.upstream")
init_local_crate("crate1", enter=False)
os.chdir(start_dir)
commit1 = init_git_repo("monoproject.upstream")

# We clone the project to obtain our local copy

assert run(["git", "clone",
"monoproject.upstream", "monoproject"]).returncode == 0

# We enter the crate nested inside and publish.

os.chdir("monoproject")
os.chdir("crate1")
alr_publish("crate1", "0.1.0-dev",
index_path=os.path.join(start_dir, "my_index"))

# Verify that we can `alr get` the nested crate

os.chdir(start_dir)
run_alr("get", "crate1")

# Enter and verify the only manifest is at the expected location (in the nested
# crate), and the only backup is too there.

os.chdir(glob("monoproject_*")[0])

assert not os.path.isfile(alr_manifest()), \
"Unexpected manifest at the root of the repository"

assert_contents(".",
['./crate1/alire.toml',
'./crate1/alire/alire.toml.upstream'],
regex=".*alire.*toml")

print('SUCCESS')
5 changes: 5 additions & 0 deletions testsuite/tests/monorepo/manifest-in-place/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: python-script
indexes:
my_index:
in_fixtures: false
compiler_only_index: {}

0 comments on commit 119e690

Please sign in to comment.