From f4bf81973ba98c4bec467808133df1322219661e Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Fri, 10 Dec 2021 18:15:44 +0000 Subject: [PATCH] Build linux binaries in alpine container --- .github/workflows/build.yml | 126 +++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e6fd17fd3d..da8281c6e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,14 +12,13 @@ on: - '*-check-build' jobs: - build: + build-mac-win: runs-on: ${{ matrix.os }} - strategy: fail-fast: false matrix: ghc: ['9.0.1', '8.10.7', '8.10.6', '8.8.4', '8.6.5'] - os: [ubuntu-18.04, macOS-latest, windows-latest] + os: [macOS-latest, windows-latest] cabal: ['3.6'] steps: @@ -154,6 +153,127 @@ jobs: name: haskell-language-server-wrapper-${{ runner.OS }}${{env.EXE_EXT}}.${{ steps.compress_wrapper_binary.outputs.extension }} path: ${{ steps.compress_wrapper_binary.outputs.path }} + build-linux: + runs-on: ubuntu-latest + container: alpine:3.12 + + strategy: + fail-fast: false + matrix: + ghc: ['9.0.1', '8.10.7', '8.10.6', '8.8.4', '8.6.5'] + cabal: ['3.6'] + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: haskell/actions/setup@v1 + with: + ghc-version : ${{ matrix.ghc }} + cabal-version: ${{ matrix.cabal }} + + - name: Use modified cabal.project for ghc9 + if: ${{ matrix.ghc == '9.0.1' }} + run: cp cabal-ghc901.project cabal.project + + - name: Shorten binary names + run: | + sed -i.bak -e 's/haskell-language-server/hls/g' \ + -e 's/haskell_language_server/hls/g' \ + haskell-language-server.cabal cabal.project + sed -i.bak -e 's/Paths_haskell_language_server/Paths_hls/g' \ + src/**/*.hs exe/*.hs + + - name: Set some linux specific things + if: matrix.os == 'ubuntu-18.04' + env: + GHC_VER: ${{ matrix.ghc }} + run: | + echo "LINUX_CABAL_ARGS=--enable-executable-static --ghc-options=-split-sections" >> $GITHUB_ENV + echo "GHC_VERSION=$GHC_VER" >> $GITHUB_ENV + + - name: Build server + # Try building it twice in case of flakey builds on Windows + run: | + cabal build exe:hls -O2 $LINUX_CABAL_ARGS || \ + cabal build exe:hls -O2 $LINUX_CABAL_ARGS -j1 + + - name: Compress server binary + id: compress_server_binary + run: | + HLS_BUILD=$(find dist-newstyle \( -name 'hls' -o -name 'hls.exe' \) -type f) + HLS=haskell-language-server-${{env.GHC_VERSION}} + mv $HLS_BUILD $HLS${{env.EXE_EXT}} + if [[ "$OSTYPE" == "msys" ]]; then + 7z a $HLS.zip $HLS${{env.EXE_EXT}} + echo ::set-output name=path::$HLS.zip + echo ::set-output name=content_type::application/zip + echo ::set-output name=extension::zip + else + gzip --best $HLS + echo ::set-output name=path::$HLS.gz + echo ::set-output name=content_type::application/gzip + echo ::set-output name=extension::gz + fi + + - name: Upload server to release + if: ${{ !contains(github.ref_name, 'check') }} + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ steps.compress_server_binary.outputs.path }} + asset_name: haskell-language-server-${{ runner.OS }}-${{ env.GHC_VERSION }}${{env.EXE_EXT}}.${{ steps.compress_server_binary.outputs.extension }} + asset_content_type: ${{ steps.compress_server_binary.outputs.content_type }} + + - name: Upload server to workflow artifacts + uses: actions/upload-artifact@v2 + with: + name: haskell-language-server-${{ runner.OS }}-${{ matrix.ghc }}${{env.EXE_EXT}}.${{ steps.compress_server_binary.outputs.extension }} + path: ${{ steps.compress_server_binary.outputs.path }} + + - name: Build wrapper + if: matrix.ghc == '8.10.7' + run: cabal build exe:hls-wrapper -O2 $LINUX_CABAL_ARGS + + - name: Compress wrapper binary + if: matrix.ghc == '8.10.7' + id: compress_wrapper_binary + run: | + HLS_WRAPPER_BUILD=$(find dist-newstyle \( -name 'hls-wrapper' -o -name 'hls-wrapper.exe' \) -type f) + HLS_WRAPPER=haskell-language-server-wrapper + mv $HLS_WRAPPER_BUILD $HLS_WRAPPER${{env.EXE_EXT}} + if [[ "$OSTYPE" == "msys" ]]; then + 7z a $HLS_WRAPPER.zip $HLS_WRAPPER${{env.EXE_EXT}} + echo ::set-output name=path::$HLS_WRAPPER.zip + echo ::set-output name=content_type::application/zip + echo ::set-output name=extension::zip + else + gzip --best $HLS_WRAPPER + echo ::set-output name=path::$HLS_WRAPPER.gz + echo ::set-output name=content_type::application/gzip + echo ::set-output name=extension::gz + fi + + - name: Upload wrapper to the release + if: ${{ matrix.ghc == '8.10.7' && !contains(github.ref_name, 'check') }} + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ steps.compress_wrapper_binary.outputs.path }} + asset_name: haskell-language-server-wrapper-${{ runner.OS }}${{env.EXE_EXT}}.${{ steps.compress_wrapper_binary.outputs.extension }} + asset_content_type: ${{ steps.compress_wrapper_binary.outputs.content_type}} + + - name: Upload wrapper to workflow artifacts + uses: actions/upload-artifact@v2 + if: matrix.ghc == '8.10.7' + with: + name: haskell-language-server-wrapper-${{ runner.OS }}${{env.EXE_EXT}}.${{ steps.compress_wrapper_binary.outputs.extension }} + path: ${{ steps.compress_wrapper_binary.outputs.path }} + # generates a custom tarball with sources, used by `ghcup compile hls` src-tar: needs: build