From bab61aaf9f7257eda948212313e356db57f79217 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Fri, 7 Feb 2025 03:59:31 +0100 Subject: [PATCH 01/12] Add a build/test CI based on setup-haskell and get-tested --- .github/workflows/test.yaml | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..41a494a --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,59 @@ +name: Run Tests (on push and pull request) + +on: + pull_request: + branches: ['master'] + + push: + branches: ['master'] + +jobs: + generate-matrix: + name: "Generate matrix from cabal file" + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + runs-on: ubuntu-latest + steps: + - name: Extract the tested GHC versions + id: set-matrix + uses: kleidukos/get-tested@v0.1.7.1 + with: + cabal-file: opus.cabal + ubuntu-version: "latest" + macos-version: "latest" + windows-version: "latest" + version: 0.1.7.1 + tests: + name: ${{ matrix.ghc }} on ${{ matrix.os }} + needs: generate-matrix + runs-on: ${{ matrix.os }} + strategy: + matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Set up Haskell + id: setup-haskell + uses: haskell-actions/setup@v2 + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: "latest" + + - name: Install libopus (Linux only) + if: runner.os == 'Linux' + run: sudo apt-get install libopus0 + + - name: Install libopus (macOS only) + if: runner.os == 'macOS' + run: brew install opus + + - name: Install libopus (Windows only) + if: runner.os == 'Windows' + run: cabal exec -- pacman -S mingw64/mingw-w64-x86_64-opus + + - name: Build the project + run: cabal build + + - name: Run the tests + run: cabal test From 011a1db6f2d64423d0c982ec923e12bb9f36140a Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Fri, 7 Feb 2025 04:01:42 +0100 Subject: [PATCH 02/12] Add tested-with to cabal file, marking GHC 9.4.8 as tested --- opus.cabal | 1 + 1 file changed, 1 insertion(+) diff --git a/opus.cabal b/opus.cabal index f824914..873e91b 100644 --- a/opus.cabal +++ b/opus.cabal @@ -36,6 +36,7 @@ copyright: Markus Barenhoff , Yuto Takano =1.10 +tested-with: GHC ==9.4.8 extra-source-files: README.md ChangeLog.md From dc803d05294d1690742f08485093a45446c327e5 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Fri, 7 Feb 2025 04:07:34 +0100 Subject: [PATCH 03/12] Fix wrong Debian package dependency: libopus0 -> libopus-dev --- .github/workflows/test.yaml | 2 +- opus.cabal | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 41a494a..e6cba4b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -42,7 +42,7 @@ jobs: - name: Install libopus (Linux only) if: runner.os == 'Linux' - run: sudo apt-get install libopus0 + run: sudo apt-get install libopus-dev - name: Install libopus (macOS only) if: runner.os == 'macOS' diff --git a/opus.cabal b/opus.cabal index 873e91b..fddcf38 100644 --- a/opus.cabal +++ b/opus.cabal @@ -14,7 +14,7 @@ description: system. . - On Debian-based systems, you can install it with @sudo apt-get install - libopus0@. + libopus-dev@. - On MacOS, you can install it with @brew install opus@ using Homebrew. - On Windows (MinGW-based, e.g. GHCup toolchain), you can install it with @cabal exec -- pacman -S mingw64/mingw-w64-x86_64-opus@ (for x64). From 0561bc45cf35fb2794831905860a8717c638f194 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Fri, 7 Feb 2025 04:20:43 +0100 Subject: [PATCH 04/12] Add MSYS2 setup for Windows CI since pacman isn't found --- .github/workflows/test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e6cba4b..d5f81a5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -33,6 +33,9 @@ jobs: - name: Checkout the repository uses: actions/checkout@v4 + - uses: msys2/setup-msys2@v2 + if: runner.os == 'Windows' + - name: Set up Haskell id: setup-haskell uses: haskell-actions/setup@v2 From aefa99c6594a509ced3bbf7aac188e5272e2d148 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Fri, 7 Feb 2025 04:32:41 +0100 Subject: [PATCH 05/12] Use pwsh to call pacman and update PATH in Windows CI --- .github/workflows/test.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d5f81a5..3c3a0b3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -33,9 +33,6 @@ jobs: - name: Checkout the repository uses: actions/checkout@v4 - - uses: msys2/setup-msys2@v2 - if: runner.os == 'Windows' - - name: Set up Haskell id: setup-haskell uses: haskell-actions/setup@v2 @@ -53,7 +50,11 @@ jobs: - name: Install libopus (Windows only) if: runner.os == 'Windows' - run: cabal exec -- pacman -S mingw64/mingw-w64-x86_64-opus + shell: pwsh + run: | + $env:PATH = "C:\msys64\usr\bin;$env:PATH" + pacman --noconfirm -S mingw64/mingw-w64-x86_64-opus + echo "C:\msys64\mingw64\bin" | Out-File -FilePath "$env:GITHUB_PATH" -Append - name: Build the project run: cabal build From 86016d32b7e3917e75c8154e5c6df0bbf3f61442 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Thu, 13 Feb 2025 17:22:15 +0100 Subject: [PATCH 06/12] Use pkg-config on Windows as well (less pain with include paths etc) --- .github/workflows/test.yaml | 7 +++---- opus.cabal | 10 ++-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3c3a0b3..89266f8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -50,11 +50,10 @@ jobs: - name: Install libopus (Windows only) if: runner.os == 'Windows' - shell: pwsh run: | - $env:PATH = "C:\msys64\usr\bin;$env:PATH" - pacman --noconfirm -S mingw64/mingw-w64-x86_64-opus - echo "C:\msys64\mingw64\bin" | Out-File -FilePath "$env:GITHUB_PATH" -Append + set PATH=C:\msys64\usr\bin;%PATH% + pacman --noconfirm -S mingw64/mingw-w64-x86_64-opus mingw64/mingw-w64-x86_64-pkg-config + set GITHUB_PATH=C:\msys64\mingw64\bin;%GITHUB_PATH% - name: Build the project run: cabal build diff --git a/opus.cabal b/opus.cabal index fddcf38..74aee23 100644 --- a/opus.cabal +++ b/opus.cabal @@ -35,7 +35,7 @@ maintainer: Yuto Takano copyright: Markus Barenhoff , Yuto Takano , Haskell Opus Library Contributors category: Codec build-type: Simple -cabal-version: >=1.10 +cabal-version: >=1.12 tested-with: GHC ==9.4.8 extra-source-files: README.md @@ -55,13 +55,7 @@ library Codec.Audio.Opus.Internal.Opus default-language: Haskell2010 build-tools: hsc2hs - includes: - opus/opus.h - opus/opus_types.h - opus/opus_defines.h - extra-libraries: opus - if !os(windows) - pkgconfig-depends: opus + pkgconfig-depends: opus ghc-options: -Wall build-depends: base >= 4.7 && < 5, exceptions, From 6f3f7217312f57706bde8c2ebb53f2a470efa234 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Thu, 13 Feb 2025 18:02:54 +0100 Subject: [PATCH 07/12] Fix missing quoting for setting PATH in Windows CI --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 89266f8..d0a3e88 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -51,9 +51,9 @@ jobs: - name: Install libopus (Windows only) if: runner.os == 'Windows' run: | - set PATH=C:\msys64\usr\bin;%PATH% + set "PATH=C:\msys64\usr\bin;%PATH%" pacman --noconfirm -S mingw64/mingw-w64-x86_64-opus mingw64/mingw-w64-x86_64-pkg-config - set GITHUB_PATH=C:\msys64\mingw64\bin;%GITHUB_PATH% + set "GITHUB_PATH=C:\msys64\mingw64\bin;%GITHUB_PATH%" - name: Build the project run: cabal build From 4eecbf767eee3b97be25a64c1c58c2f7008777c8 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Thu, 13 Feb 2025 19:03:58 +0100 Subject: [PATCH 08/12] Use pwsh syntax in CI (after finding out GH Actions defaults to pwsh) --- .github/workflows/test.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d0a3e88..cabf598 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -50,10 +50,11 @@ jobs: - name: Install libopus (Windows only) if: runner.os == 'Windows' + shell: pwsh run: | - set "PATH=C:\msys64\usr\bin;%PATH%" + $env:PATH = "C:\msys64\usr\bin;$env:PATH" pacman --noconfirm -S mingw64/mingw-w64-x86_64-opus mingw64/mingw-w64-x86_64-pkg-config - set "GITHUB_PATH=C:\msys64\mingw64\bin;%GITHUB_PATH%" + $env:GITHUB_PATH = "C:\msys64\mingw64\bin;$env:GITHUB_PATH" - name: Build the project run: cabal build From 0226601594fe239e6b14d6ffd3e537d8d48c8f1f Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Thu, 13 Feb 2025 19:23:40 +0100 Subject: [PATCH 09/12] Fix incorrect use of GITHUB_PATH, which refers to a file path --- .github/workflows/test.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cabf598..e5f677d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -54,7 +54,9 @@ jobs: run: | $env:PATH = "C:\msys64\usr\bin;$env:PATH" pacman --noconfirm -S mingw64/mingw-w64-x86_64-opus mingw64/mingw-w64-x86_64-pkg-config - $env:GITHUB_PATH = "C:\msys64\mingw64\bin;$env:GITHUB_PATH" + + # Add the mingw64 bin directory to the PATH so cabal can find pkg-config & opus + echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Build the project run: cabal build From be0af7b4ab1877a280f30fee26cd652cf157cfee Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Thu, 13 Feb 2025 19:49:27 +0100 Subject: [PATCH 10/12] Use instead of as Windows pkg-config likes it better --- src/Codec/Audio/Opus/Internal/Opus.hsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codec/Audio/Opus/Internal/Opus.hsc b/src/Codec/Audio/Opus/Internal/Opus.hsc index cde83ec..29722ea 100644 --- a/src/Codec/Audio/Opus/Internal/Opus.hsc +++ b/src/Codec/Audio/Opus/Internal/Opus.hsc @@ -7,7 +7,7 @@ import Foreign import Foreign.C.Types import Foreign.C.String -#include +#include newtype ErrorCode = ErrorCode { unErrorCode :: CInt } deriving (Eq,Show) From 0fa12e4b52fd3eea0df016bd0a5d918f585eedd5 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Thu, 13 Feb 2025 19:49:52 +0100 Subject: [PATCH 11/12] Fix `cabal test` not solving for test suite in CI For some reason, it's not required for the solver to include the test suite when running `cabal test`. This means that there is a chance that `cabal test` can reach a local maxima of dependencies that bizzarely doesn't contain the test suite itself. This is tracked in: https://github.com/haskell/cabal/issues/7883 The solution is either to add tests: True to cabal.project, or call `cabal test` with the --enable-tests flag. This commit does the latter in the CI, but eventually it'd be nice to get rid of the confusing flag. --- .github/workflows/test.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e5f677d..f2396a1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -59,7 +59,13 @@ jobs: echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Build the project - run: cabal build + # Use --enable-tests until https://github.com/haskell/cabal/issues/7883 + # is fixed, as otherwise build will solve dependencies without considering + # the test-suite dependencies, and then the tests will fail. + run: cabal build --enable-tests - name: Run the tests - run: cabal test + # Use --enable-tests until https://github.com/haskell/cabal/issues/7883 + # is fixed, as otherwise cabal test can sometimes reach a local maxima + # of dependencies that bizarrely doesn't (!) include the test suite. + run: cabal test --enable-tests From 04bf3bce58ff7182b10e657eb31fbe2008657997 Mon Sep 17 00:00:00 2001 From: Yuto Takano Date: Thu, 13 Feb 2025 20:18:19 +0100 Subject: [PATCH 12/12] Cache Cabal store across runs in Github Actions Caching strategy has been taken from https://markkarpov.com/post/github-actions-for-haskell-ci.html which has kindly described the directories and keys to use for caching the Cabal store in GH actions. --- .github/workflows/test.yaml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f2396a1..5221da0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -58,11 +58,20 @@ jobs: # Add the mingw64 bin directory to the PATH so cabal can find pkg-config & opus echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Build the project - # Use --enable-tests until https://github.com/haskell/cabal/issues/7883 - # is fixed, as otherwise build will solve dependencies without considering - # the test-suite dependencies, and then the tests will fail. - run: cabal build --enable-tests + - name: Update cabal store + run: cabal update + + - name: Create a freeze file for the cache + run: cabal freeze --enable-tests + + - uses: actions/cache@v4 + with: + path: | + ${{ steps.setup-haskell.outputs.cabal-store }} + dist-newstyle + key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.ghc }}- - name: Run the tests # Use --enable-tests until https://github.com/haskell/cabal/issues/7883