-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b6d5652
Showing
4 changed files
with
157 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: parse-cabal-file | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
uses: actions/checkout@v3 | ||
- | ||
run: ghc -Wall -Werror ParseCabalFile.hs | ||
|
||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- ubuntu-22.04 | ||
- ubuntu-20.04 | ||
- ubuntu-18.04 | ||
- macos-latest | ||
- macos-12 | ||
- macos-11 | ||
- windows-latest | ||
- windows-2022 | ||
- windows-2019 | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- | ||
uses: actions/checkout@v3 | ||
- | ||
name: Write test cabal file | ||
run: | | ||
echo 'name: foo' >> foo.cabal | ||
echo 'version: 12.34' >> foo.cabal | ||
- | ||
name: Run action | ||
uses: ./ | ||
id: cabal_file | ||
with: | ||
cabal_file: foo.cabal | ||
- | ||
name: Check action worked | ||
run: | | ||
if [[ "${{ steps.cabal_file.outputs.version }}" != "12.34" ]]; then | ||
echo 'Action failed!' >&2 | ||
exit 1 | ||
fi | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
uses: actions/checkout@v3 | ||
- | ||
uses: fourmolu/fourmolu-action@v7 | ||
with: | ||
pattern: '*.hs' | ||
extra-args: > | ||
--indentation 2 | ||
--indent-wheres true |
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,36 @@ | ||
{-# LANGUAGE ImportQualifiedPost #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
import Data.ByteString qualified as BS | ||
import Data.List (intercalate) | ||
import Distribution.Package (packageVersion) | ||
import Distribution.PackageDescription.Parsec (parseGenericPackageDescriptionMaybe) | ||
import Distribution.Version (versionNumbers) | ||
import System.Environment (getArgs) | ||
import System.IO (hPutStrLn, stderr, stdout) | ||
|
||
main :: IO () | ||
main = do | ||
cabalFile <- | ||
getArgs >>= \case | ||
[cabalFile] -> return cabalFile | ||
_ -> errorWithoutStackTrace "Expected exactly one argument: CABAL_FILE" | ||
|
||
cabalFileContents <- BS.readFile cabalFile | ||
packageDesc <- | ||
maybe (errorWithoutStackTrace "Could not parse cabal file") return $ | ||
parseGenericPackageDescriptionMaybe cabalFileContents | ||
|
||
output | ||
[ ("version", intercalate "." . map show . versionNumbers . packageVersion $ packageDesc) | ||
] | ||
|
||
output :: [(String, String)] -> IO () | ||
output = mapM_ (uncurry output') | ||
where | ||
output' key value = do | ||
let kv = key ++ "=" ++ value | ||
-- log to stderr | ||
hPutStrLn stderr $ "Setting: " ++ kv | ||
-- output to stdout into $GITHUB_OUTPUT | ||
hPutStrLn stdout kv |
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,30 @@ | ||
# `haskell-actions/parse-cabal-file` | ||
|
||
GitHub Action: Parse Cabal file | ||
|
||
Assumes the runner has GHC installed. | ||
|
||
## Inputs | ||
|
||
* `cabal_file` (required): The path to a cabal file | ||
|
||
## Outputs | ||
|
||
* `version`: The version in the Cabal file | ||
|
||
## Example | ||
|
||
```yaml | ||
jobs: | ||
my-job: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: haskell-actions/parse-cabal-file@v1 | ||
id: cabal_file | ||
with: | ||
cabal_file: my-library.cabal | ||
|
||
- run: echo ${{ steps.cabal_file.outputs.version }} | ||
``` |
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,23 @@ | ||
name: Parse Cabal File | ||
description: Parse information in a provided cabal file | ||
|
||
inputs: | ||
cabal_file: | ||
description: Path to cabal file | ||
required: true | ||
|
||
outputs: | ||
version: | ||
description: The version in the cabal file | ||
value: ${{ steps.cabal_file.outputs.version }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- run: | | ||
BINDIR=${GITHUB_ACTION_PATH}/bin | ||
mkdir -p ${BINDIR} | ||
ghc ${GITHUB_ACTION_PATH}/ParseCabalFile.hs -outputdir /tmp -o ${BINDIR}/parse-cabal-file | ||
${BINDIR}/parse-cabal-file "${{ inputs.cabal_file }}" >> "${GITHUB_OUTPUT}" | ||
id: cabal_file | ||
shell: bash |