From 865cfc1ff3cc61b49949346bb9d88aae69f0ea6b Mon Sep 17 00:00:00 2001 From: Arthur Jamet Date: Sun, 30 Jun 2024 16:56:36 +0200 Subject: [PATCH] CI: Build, Lint and test --- .github/actions/cache/action.yml | 22 ++++++++ .github/workflows/CI.yml | 87 ++++++++++++++++++++++++++++++++ test/FFProbe/Data/TestChapter.hs | 2 +- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 .github/actions/cache/action.yml create mode 100644 .github/workflows/CI.yml diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml new file mode 100644 index 0000000..c7ed4d5 --- /dev/null +++ b/.github/actions/cache/action.yml @@ -0,0 +1,22 @@ +name: 'Cache' +description: 'Cache for CI' +runs: + using: "composite" + steps: + - uses: actions/cache@v3 + name: Cache ~/.stack + with: + path: ~/.stack + key: stack-global + restore-keys: | + stack-global + - uses: actions/cache@v3 + name: Cache .stack-work + with: + path: ./.stack-work + key: stack-work + restore-keys: | + stack-work + - name: Install Stack + shell: bash + run: curl -sSL https://get.haskellstack.org/ | sh -s - -f \ No newline at end of file diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..d695524 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,87 @@ +name: "CI for haskell-ffprobe" +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] + release: + types: [ published ] + +defaults: + run: + shell: bash + +jobs: + Changes: + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + sources: ${{ steps.filter.outputs.sources }} + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + sources: + - 'src/**' + - 'test/**.hs' + - '.github/workflows/CI.yml' + Build: + needs: changes + if: ${{ needs.changes.outputs.sources == 'true' }} + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: Setup GHC + uses: ./.github/actions/cache + - name: Build + run: stack build + Format: + if: ${{ needs.changes.outputs.sources == 'true' }} + runs-on: ubuntu-latest + needs: [ Build ] + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: Setup GHC + uses: ./.github/actions/cache + - uses: haskell-actions/run-fourmolu@v9 + with: + version: "0.14.0.0" + pattern: | + ./src/**/*.hs + ./test/**/*.hs + follow-symbolic-links: false + Lint: + if: ${{ needs.changes.outputs.sources == 'true' }} + runs-on: ubuntu-latest + needs: [ Build ] + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: Setup GHC + uses: ./.github/actions/cache + - name: 'Set up HLint' + uses: rwe/actions-hlint-setup@v1 + with: + version: '3.5' + - name: 'Run HLint' + uses: rwe/actions-hlint-run@v2 + with: + path: '["./src/", "./test/"]' + fail-on: warning + Tests: + runs-on: ubuntu-latest + needs: [ Build ] + if: ${{ needs.changes.outputs.sources == 'true' }} + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: Setup GHC + uses: ./.github/actions/cache + - name: Run unit tests + run: stack test \ No newline at end of file diff --git a/test/FFProbe/Data/TestChapter.hs b/test/FFProbe/Data/TestChapter.hs index c651f12..cf2fc53 100644 --- a/test/FFProbe/Data/TestChapter.hs +++ b/test/FFProbe/Data/TestChapter.hs @@ -13,7 +13,7 @@ specs = describe "Chapter Parsing" $ do shouldBeRight (eitherDecodeStrict rawJson) ( \chapter -> do - id chapter `shouldBe` 8 + FFProbe.Data.Chapter.id chapter `shouldBe` 8 timeBase chapter `shouldBe` "1/1000000000" startTime chapter `shouldBe` 0.0 endTime chapter `shouldBe` 117.56