Skip to content

Commit

Permalink
Add cache prefix to remote framework upload path with engine (#192)
Browse files Browse the repository at this point in the history
* Add cache prefix to remote framework upload path with engine
* Add tests for checking that list command includes cache prefix in engine
  • Loading branch information
BalestraPatrick authored and tmspzz committed Jun 19, 2019
1 parent 10e7a05 commit 5458036
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
13 changes: 13 additions & 0 deletions integration-tests/current-framework-named-engine-yml.bats
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,16 @@ teardown() {
[ -d "Carthage/Build/watchOS/${FRAMEWORK_ARTIFACT_NAME}.framework.dSYM" ]
[ -f "Carthage/Build/watchOS/${WATCHOS_ARMV7K_DWARF_UUID}.bcsymbolmap" ]
}

@test "rome list named artifacts for current framework with engine skipping local cache (dynamic, yaml)" {

# restore server cache
if [ -d "../../_server-cache_bkp" ]; then
echo "# Server cache restored" >&3
cp -R ../../_server-cache_bkp server-cache/
fi

run rome list --cache-prefix travis

[ "$status" -eq 0 ]
}
9 changes: 7 additions & 2 deletions integration-tests/engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ STORAGE_DIR="server-cache"
if [ "$ACTION" == "upload" ]; then
LOCAL_PATH="$2"
REMOTE_PATH="$3"
# POST request to upload file to remote path
# create directory structure if it doesn't exist yet
mkdir -p $STORAGE_DIR/$(dirname $REMOTE_PATH)
# fake the upload of a file by just copying binary to the storage directory
Expand All @@ -28,8 +27,14 @@ elif [ "$ACTION" == "download" ]; then

elif [ "$ACTION" == "list" ]; then
REMOTE_PATH="$2"

# verify that the list command contains the cache prefix
if [[ ! "$REMOTE_PATH" =~ "travis" ]]; then
exit 1
fi

# fake list command by just checking if file exists
if [ ! -f "$STORAGE_DIR/$REMOTE_PATH" ]; then
if [[ ! -f "$STORAGE_DIR/$REMOTE_PATH" ]]; then
exit 1
fi

Expand Down
15 changes: 10 additions & 5 deletions src/Engine/Probing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,41 @@ import Data.Romefile (_frameworkPlatforms)
import Types hiding (version)
import Utils
import qualified Turtle
import System.FilePath ((</>))


-- | Probes a `FilePath` to check if each `FrameworkVersion` exists for each `TargetPlatform`
probeEngineForFrameworks
:: MonadIO m
=> FilePath -- ^ The `FilePath` to the engine
-> CachePrefix -- ^ The top level directory prefix.
-> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s.
-> [FrameworkVersion] -- ^ A list of `FrameworkVersion` to probe for.
-> [TargetPlatform] -- ^ A list target platforms restricting the scope of this action.
-> m [FrameworkAvailability]
probeEngineForFrameworks lCacheDir reverseRomeMap frameworkVersions
probeEngineForFrameworks lCacheDir cachePrefix reverseRomeMap frameworkVersions
= sequence . probeForEachFramework
where
probeForEachFramework = mapM
(probeEngineForFramework lCacheDir reverseRomeMap)
(probeEngineForFramework lCacheDir cachePrefix reverseRomeMap)
frameworkVersions


-- | Probes the engine at `FilePath` to check if a `FrameworkVersion` exists for each `TargetPlatform`
probeEngineForFramework
:: MonadIO m
=> FilePath -- ^ The `FilePath` to the engine
-> CachePrefix -- ^ The top level directory prefix.
-> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s.
-> FrameworkVersion -- ^ The `FrameworkVersion` to probe for.
-> [TargetPlatform] -- ^ A list target platforms restricting the scope of this action.
-> m FrameworkAvailability
probeEngineForFramework lCacheDir reverseRomeMap frameworkVersion platforms
probeEngineForFramework lCacheDir cachePrefix reverseRomeMap frameworkVersion platforms
= fmap (FrameworkAvailability frameworkVersion) probeForEachPlatform
where
probeForEachPlatform = mapM
(probeEngineForFrameworkOnPlatform lCacheDir
cachePrefix
reverseRomeMap
frameworkVersion
)
Expand All @@ -50,16 +54,17 @@ probeEngineForFramework lCacheDir reverseRomeMap frameworkVersion platforms
probeEngineForFrameworkOnPlatform
:: MonadIO m
=> FilePath -- ^ The `FilePath` to the engine
-> CachePrefix -- ^ The top level directory prefix.
-> InvertedRepositoryMap -- ^ The map used to resolve `FrameworkName`s to `GitRepoName`s.
-> FrameworkVersion -- ^ The `FrameworkVersion` to probe for.
-> TargetPlatform -- ^ A target platforms restricting the scope of this action.
-> m PlatformAvailability
probeEngineForFrameworkOnPlatform enginePath reverseRomeMap (FrameworkVersion fwn version) platform
probeEngineForFrameworkOnPlatform enginePath (CachePrefix prefix) reverseRomeMap (FrameworkVersion fwn version) platform
= do
let cmd = Turtle.fromString enginePath
exitCode <- Turtle.proc
cmd
["list", Turtle.fromString remoteFrameworkUploadPath]
["list", Turtle.fromString (prefix </> remoteFrameworkUploadPath)]
(return $ Turtle.unsafeTextToLine "")
case exitCode of
-- If engine exits with success, we assume the framework exists.
Expand Down
2 changes: 2 additions & 0 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ getProjectAvailabilityFromCaches Nothing (Just lCacheDir) Nothing reverseReposit

getProjectAvailabilityFromCaches Nothing _ (Just ePath) reverseRepositoryMap frameworkVersions platforms
= do
(cachePrefix, _, _) <- ask
availabilities <- probeEngineForFrameworks ePath
cachePrefix
reverseRepositoryMap
frameworkVersions
platforms
Expand Down

0 comments on commit 5458036

Please sign in to comment.