From cd39585eb4700f7b5a6baf7b250038404681a74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Choutri?= Date: Mon, 24 Jun 2024 18:43:53 +0200 Subject: [PATCH] Setup confer-head prereleases --- .github/workflows/ci.yml | 116 ++++++++++++++++++++++++++++--- .github/workflows/linting.yml | 27 +++---- .gitignore | 1 + Makefile | 2 +- app/Main.hs | 4 +- cabal.project | 2 - cabal.release.project | 14 ++++ confer.cabal | 13 ---- src/Confer/Effect/Symlink.hs | 12 +++- test/Confer/CLI/Cmd/CheckTest.hs | 2 +- 10 files changed, 150 insertions(+), 43 deletions(-) create mode 100644 cabal.release.project diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d9a6aa..718ccda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,12 @@ name: CI on: pull_request: push: - branches: ["main"] + branches: ['main'] jobs: generate-matrix: - name: "Generate matrix from cabal" - outputs: + name: 'Generate matrix from cabal' + outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} runs-on: ubuntu-latest steps: @@ -18,8 +18,8 @@ jobs: uses: kleidukos/get-tested@v0.1.7.0 with: cabal-file: confer.cabal - ubuntu-version: "latest" - macos: "macos-13" + ubuntu-version: 'latest' + macos: 'macos-13' version: 0.1.7.0 tests: name: ${{ matrix.ghc }} on ${{ matrix.os }} @@ -39,7 +39,7 @@ jobs: - name: Configure run: cabal configure --enable-tests - name: Freeze - run: cabal freeze + run: cabal freeze --project-file=cabal.release.project - name: Cache uses: actions/cache@v4.0.2 with: @@ -47,6 +47,106 @@ jobs: key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-cabal-${{ hashFiles('**/plan.json') }} restore-keys: ${{ runner.os }}-ghc-${{ matrix.ghc }}- - name: Build - run: cabal new-build + run: cabal build --project-file=cabal.release.project - name: Test - run: cabal new-test all + run: cabal test --project-file=cabal.release.project all + - name: Package the confer-head executable + run: | + CONFER_EXEC=$(cabal list-bin --project-file=cabal.release.project confer:exe:confer) + DIR=$(dirname $CONFER_EXEC) + FILE=$(basename $CONFER_EXEC) + CONFER_EXEC_TAR=confer-head-${{ runner.os }}-x86_64.tar.gz + tar -czvf $CONFER_EXEC_TAR -C $DIR $FILE + echo CONFER_EXEC_TAR=$CONFER_EXEC_TAR >> $GITHUB_ENV + - name: Upload the confer-head executable + uses: actions/upload-artifact@v3 + with: + name: confer-${{ runner.os }}-x86_64 + path: ${{ env.CONFER_EXEC_TAR }} + + build-alpine: + name: Build statically linked using alpine + runs-on: ubuntu-latest + container: 'alpine:3.19' + needs: ['generate-matrix', 'tests'] + strategy: + matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} + steps: + - name: Install extra dependencies + shell: sh + run: | + apk add bash curl sudo jq pkgconfig \ + zlib-dev zlib-static binutils-gold curl \ + gcc g++ gmp-dev libc-dev libffi-dev make \ + musl-dev ncurses-dev perl tar xz git + + - uses: actions/checkout@v4 + + - uses: haskell-actions/setup@v2 + id: setup-haskell + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: 'latest' + + - name: Configure + run: cabal configure --enable-tests + + - name: Freeze + run: cabal freeze --project-file=cabal.release.project + + - uses: actions/cache@v4 + with: + path: ${{ steps.setup-haskell.outputs.cabal-store }} + key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-cabal-${{ hashFiles('**/plan.json') }} + restore-keys: ${{ runner.os }}-ghc-${{ matrix.ghc }}- + + - name: Enable statically linked executables + run: | + echo 'executable-static: true' >> cabal.release.project + + - name: Build + run: cabal build --project-file=cabal.release.project + + - name: Test + run: cabal test --project-file=cabal.release.project all + + - name: Tar cabal head executable + run: | + CONFER_EXE=$(cabal list-bin --project-file=cabal.release.project confer:exe:confer) + DIR=$(dirname $CONFER_EXEC) + FILE=$(basename $CONFER_EXEC) + CONFER_EXEC_TAR=confer-head-${{ runner.os }}-x86_64.tar.gz + tar -czvf $CONFER_EXEC_TAR -C $DIR $FILE + echo CONFER_EXEC_TAR=$CONFER_EXEC_TAR >> $GITHUB_ENV + + - name: Upload confer executable to workflow artifacts + uses: actions/upload-artifact@v3 + with: + name: cabal-${{ runner.os }}-static-x86_64 + path: ${{ env.CONFER_EXEC_TAR }} + + prerelease-head: + name: Create a GitHub prerelease with the binary artifacts + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + needs: ['tests', 'build-alpine'] + + steps: + - uses: actions/download-artifact@v3 + with: + name: confer-Linux-x86_64 + + - uses: actions/download-artifact@v3 + with: + name: confer-Linux-static-x86_64 + + - name: Create GitHub prerelease + uses: marvinpinto/action-automatic-releases@v1.2.1 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + automatic_release_tag: confer-head + prerelease: true + title: confer-head + files: | + confer-head-Linux-x86_64.tar.gz + confer-head-Linux-static-x86_64.tar.gz diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 50dadb4..35c684b 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -5,18 +5,19 @@ on: push: branches: ["main"] -# jobs: -# fourmolu: -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v4 -# -# - uses: fourmolu/fourmolu-action@v10 -# with: -# pattern: | -# src/**/*.hs -# test/**/*.hs -# +jobs: + fourmolu: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: fourmolu/fourmolu-action@v10 + with: + pattern: | + app/**/*.hs + src/**/*.hs + test/**/*.hs + hlint: runs-on: ubuntu-latest steps: @@ -30,5 +31,5 @@ on: - name: 'Run HLint' uses: haskell-actions/hlint-run@v2 with: - path: '["src/", "test/"]' + path: '["app/", "src/", "test/"]' fail-on: warning diff --git a/.gitignore b/.gitignore index 449345b..64e95b1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ tags tags.mtime .hpc *.tix +*.local diff --git a/Makefile b/Makefile index c611838..9530983 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ test: ## Run the test suite @cabal test lint: ## Run the code linter (HLint) - @find test src -name "*.hs" | xargs -P $(PROCS) -I {} hlint --refactor-options="-i" --refactor {} + @find app test src -name "*.hs" | xargs -P $(PROCS) -I {} hlint --refactor-options="-i" --refactor {} style: ## Run the code styler (fourmolu and cabal-fmt) @cabal-fmt -i *.cabal diff --git a/app/Main.hs b/app/Main.hs index 53528ed..8e8a3ee 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE QuasiQuotes #-} - module Main where import Control.Placeholder @@ -96,4 +94,4 @@ withInfo :: Parser a -> String -> ParserInfo a withInfo opts desc = info (helper <*> opts) $ progDesc desc osPathOption :: ReadM OsPath -osPathOption = maybeReader (OsPath.encodeUtf) +osPathOption = maybeReader OsPath.encodeUtf diff --git a/cabal.project b/cabal.project index 747edfa..21e8ee2 100644 --- a/cabal.project +++ b/cabal.project @@ -8,8 +8,6 @@ test-show-details: direct documentation: True -optimization: 2 - tests: True -- package confer diff --git a/cabal.release.project b/cabal.release.project new file mode 100644 index 0000000..b359dab --- /dev/null +++ b/cabal.release.project @@ -0,0 +1,14 @@ +import: cabal.project + +optimization: 2 + +documentation: False + +flags: -development + +package * + ghc-options: + -flate-specialise -funbox-strict-fields + -finline-generics-aggressively -fexpose-all-unfoldings + -Wwarn=extended-warnings -fdicts-strict -fmax-worker-args=16 + -fspec-constr-recursive=16 -funbox-strict-fields diff --git a/confer.cabal b/confer.cabal index a4b451a..c62b948 100644 --- a/confer.cabal +++ b/confer.cabal @@ -20,11 +20,6 @@ extra-doc-files: data-dir: runtime/lua tested-with: GHC ==9.8.2 -flag release - description: Compile the project for release - default: False - manual: True - flag development description: Compile the project for development default: True @@ -54,14 +49,6 @@ common ghc-options -fhide-source-paths -Wno-unused-do-bind -fshow-hole-constraints -Wno-unticked-promoted-constructors - if flag(release) - ghc-options: - -flate-specialise -funbox-strict-fields - -finline-generics-aggressively -fexpose-all-unfoldings - -Werror=extended-warnings -fdicts-strict -fmax-worker-args=16 - -fspec-constr-recursive=16 -funbox-strict-fields - -Wno-unused-packages -Werror=unused-imports - if flag(development) ghc-options: -finfo-table-map -Wno-unused-imports -Wno-unused-packages diff --git a/src/Confer/Effect/Symlink.hs b/src/Confer/Effect/Symlink.hs index f9df4f6..a78dde5 100644 --- a/src/Confer/Effect/Symlink.hs +++ b/src/Confer/Effect/Symlink.hs @@ -11,7 +11,6 @@ module Confer.Effect.Symlink import Control.Exception import Control.Monad -import Control.Placeholder import Data.Map.Strict (Map) import Data.Map.Strict qualified as Map import Data.Text (Text) @@ -80,7 +79,16 @@ runSymlinkIO = interpret $ \_ -> \case createFileLink sourcePath destinationPath Directory -> createDirectoryLink sourcePath destinationPath - DeleteSymlink _ -> todo + DeleteSymlink linkOsPath -> do + linkFilePath <- liftIO $ OsPath.decodeFS linkOsPath + sourceType <- liftIO $ do + metadata <- Directory.getFileMetadata linkOsPath + pure $ Directory.fileTypeFromMetadata metadata + case sourceType of + File -> + FileSystem.removeFile linkFilePath + Directory -> + FileSystem.removeDirectory linkFilePath TestSymlink linkOsPath expectedLinkTarget -> do linkFilepath <- liftIO $ OsPath.decodeFS linkOsPath liftIO $ diff --git a/test/Confer/CLI/Cmd/CheckTest.hs b/test/Confer/CLI/Cmd/CheckTest.hs index a2eca7f..8d748ba 100644 --- a/test/Confer/CLI/Cmd/CheckTest.hs +++ b/test/Confer/CLI/Cmd/CheckTest.hs @@ -87,5 +87,5 @@ testNonSymlink = Temporary.withSystemTempFile "confer-test.ext" $ \filepath _ -> do result <- Symlink.runSymlinkIO $ do osFilepath <- liftIO $ OsPath.encodeFS filepath - Symlink.testSymlink osFilepath ([osp| lol |]) + Symlink.testSymlink osFilepath [osp| lol |] assertIsNotSymlink result