Skip to content

Add glob bindings #10

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@actions/cache": "^1.0.2",
"@actions/core": "^1.2.5",
"@actions/exec": "^1.0.4",
"@actions/glob": "^0.1.0",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.6.0"
}
Expand Down
13 changes: 13 additions & 0 deletions src/GitHub/Actions/Glob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

const glob = require("@actions/glob");

exports.createImpl = glob.create;

exports.getSearchPaths = function (globber) {
return globber.getSearchPaths();
};

exports.globImpl = function (globber) {
return globber.glob();
};
75 changes: 75 additions & 0 deletions src/GitHub/Actions/Glob.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- | Exports functions from the @actions/glob module provided by GitHub
-- | https://github.com/actions/toolkit/tree/main/packages/glob
module GitHub.Actions.Glob
( Globber
, GlobOptions(..)
, getSearchPaths
, glob
) where

import Prelude

import Control.Monad.Except (ExceptT(..))
import Control.Promise (Promise, toAffE)
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, toNullable)
import Effect (Effect)
import Effect.Aff (Aff, Error, try)
import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2)

-- | Used to match files and directories.
foreign import data Globber :: Type

-- | Options to control globbing behavior.
type GlobOptions =
{ followSymbolicLinks :: Maybe Boolean
, implicitDescendants :: Maybe Boolean
, omitBrokenSymbolicLinks :: Maybe Boolean
}

-- | Defaults for `GlobOptions`.
defaultGlobOptions :: GlobOptions
defaultGlobOptions =
{ followSymbolicLinks: Just true
, implicitDescendants: Just true
, omitBrokenSymbolicLinks: Just true
}

type JSGlobOptions =
{ followSymbolicLinks :: Nullable Boolean
, implicitDescendants :: Nullable Boolean
, omitBrokenSymbolicLinks :: Nullable Boolean
}

toJSGlobOptions :: GlobOptions -> JSGlobOptions
toJSGlobOptions opts =
{ followSymbolicLinks: toNullable opts.followSymbolicLinks
, implicitDescendants: toNullable opts.implicitDescendants
, omitBrokenSymbolicLinks: toNullable opts.omitBrokenSymbolicLinks
}

foreign import createImpl :: EffectFn2 String (Nullable (JSGlobOptions)) (Promise Globber)

-- | Constructs a globber.
create :: Maybe GlobOptions -> String -> ExceptT Error Aff Globber
create opts pattern =
runEffectFn2 createImpl pattern jsOpts
# toAffE
# (try >>> ExceptT)
where
jsOpts = toNullable $ map toJSGlobOptions $ opts

-- | Returns the search path preceding the first glob segment, from each pattern.
-- | Duplicates and descendants of other paths are filtered out.
foreign import getSearchPaths :: Globber -> Effect (Array String)

foreign import globImpl :: EffectFn1 Globber (Promise (Array String))

-- | Returns files and directories matching the glob patterns.
-- |
-- | Order of the results is not guaranteed.
glob :: Globber -> ExceptT Error Aff (Array String)
glob globber =
runEffectFn1 globImpl globber
# toAffE
# (try >>> ExceptT)