-
Notifications
You must be signed in to change notification settings - Fork 9
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
Submodule support #89
Open
ch1bo
wants to merge
8
commits into
input-output-hk:main
Choose a base branch
from
cardano-scaling:submodule-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2943666
Write a test case using a test fixture repository
ch1bo ba799ae
Add a GitClone rule which fetches sources using git
ch1bo 77d2454
Remove unused githubRepoTarballUrl helper
ch1bo 7cd94c9
Fetch already cloned working copies and add test fixture
ch1bo cae3ce4
Make gitCheckout just an Action, no additional rule
ch1bo ac429cc
Re-add custom rule for GitClone and use git worktree to prepare source
ch1bo 745c03c
Use untracked version of doesDirectoryExist in GitClone
ch1bo ca51e1b
Not use Show instance for GitHubRepo and Rev
ch1bo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
-- | Clone a github repository into a cache directory. | ||
module Foliage.GitClone ( | ||
gitClone, | ||
addGitCloneRule, | ||
) | ||
where | ||
|
||
import Development.Shake hiding (doesDirectoryExist) | ||
import Development.Shake.Classes | ||
import Development.Shake.FilePath | ||
import Development.Shake.Rule | ||
import Foliage.Meta (GitHubRepo, gitHubRepoToString) | ||
import GHC.Generics (Generic) | ||
import System.Directory (doesDirectoryExist) | ||
|
||
newtype GitClone = GitClone {repo :: GitHubRepo} | ||
deriving (Eq, Generic) | ||
deriving newtype (NFData) | ||
|
||
instance Show GitClone where | ||
show GitClone{repo} = "gitClone " <> gitHubRepoToString repo | ||
|
||
instance Hashable GitClone | ||
|
||
instance Binary GitClone | ||
|
||
type instance RuleResult GitClone = FilePath | ||
|
||
-- | Clone given repo at given revision into the cache directory and return the working copy path. | ||
gitClone :: GitHubRepo -> Action FilePath | ||
gitClone repo = apply1 GitClone{repo} | ||
|
||
-- | Set up the 'GitClone' rule with a cache directory. | ||
addGitCloneRule | ||
:: FilePath | ||
-- ^ Cache directory | ||
-> Rules () | ||
addGitCloneRule cacheDir = addBuiltinRule noLint noIdentity run | ||
where | ||
run :: BuiltinRun GitClone FilePath | ||
run GitClone{repo} _old _mode = do | ||
let path = cacheDir </> "git" </> gitHubRepoToString repo | ||
|
||
alreadyCloned <- liftIO $ doesDirectoryExist path | ||
if alreadyCloned | ||
then command_ [Cwd path] "git" ["fetch"] | ||
else do | ||
let url = "https://github.com/" <> gitHubRepoToString repo <> ".git" | ||
command_ [] "git" ["clone", "--recursive", url, path] | ||
|
||
return $ RunResult{runChanged = ChangedRecomputeDiff, runStore = "", runValue = path} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/fixtures/git-submodule/_sources/foliage-test-with-submodule/1.0.0/meta.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
timestamp = 2023-11-03T17:35:22+00:00 | ||
github = { repo = "cardano-scaling/foliage-test-with-submodule", rev = "db5874494ee5bac3fa8fee07d5806fcec27a2f4e" } |
2 changes: 2 additions & 0 deletions
2
tests/fixtures/git-submodule/_sources/foliage-test-with-submodule/1.1.0/meta.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
timestamp = 2023-11-03T15:53:59+00:00 | ||
github = { repo = "cardano-scaling/foliage-test-with-submodule", rev = "1.1.0" } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you should use that
_old
parameter to store (inside shake itself) information from the rule previous run. From the docs:The argument
oldStore
isMaybe ByteString
andnewStore
has to beByteString
,oldStore
isNothing
if it is the first time the rule runs.E.g. you could use that 1) to detect whether you checkout out the repo before 2) perhaps remember what commit you had checkedout (not sure if it's worth it but you can do that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought about using the last fetched revision in the store. It felt like an optimization though and not sure if needed. You think we should do that?