From 6606a06ba17ae5b20247d8a34df74c5932bdcdcf Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Mon, 24 May 2021 13:42:00 +0800 Subject: [PATCH] Use cabal-install if nix is failing in CI (#1859) * Use cabal-install if nix is failing in CI * Add default.nix * Split nix job * Fix syntax error * Reorder --- .github/workflows/nix.yml | 53 +++++++++++++++++++++++++++++++-------- default.nix | 11 ++++++++ 2 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 default.nix diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 74f5720b54..4bf30440ce 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -4,6 +4,9 @@ on: pull_request: branches: - '**' + push: + branches: + - master jobs: pre_job: @@ -17,11 +20,10 @@ jobs: cancel_others: true paths_ignore: '["**/docs/**", "**.md", "**/LICENSE", ".circleci/**", "install/**"]' - nix: + # Enter the development shell and run `cabal build` + develop: needs: pre_job runs-on: ${{ matrix.os }} - env: - HAS_TOKEN: ${{ secrets.HLS_CACHIX_AUTH_TOKEN != '' }} strategy: fail-fast: false @@ -41,14 +43,43 @@ jobs: extra_nix_config: | experimental-features = nix-command flakes nix_path: nixpkgs=channel:nixos-unstable - - if: ${{ needs.pre_job.outputs.should_skip != 'true' && env.HAS_TOKEN == 'true' }} - uses: cachix/cachix-action@v8 + - if: ${{ needs.pre_job.outputs.should_skip != 'true' }} + uses: cachix/cachix-action@v10 with: name: haskell-language-server - authToken: ${{ secrets.HLS_CACHIX_AUTH_TOKEN }} + # Disable pushing, we will do that in job `build` + skipPush: true - if: ${{ needs.pre_job.outputs.should_skip != 'true' }} - run: nix build - - if: ${{ needs.pre_job.outputs.should_skip != 'true' && env.HAS_TOKEN == 'true' }} - run: nix develop --profile dev && cachix push haskell-language-server dev - - if: ${{ needs.pre_job.outputs.should_skip != 'true' && env.HAS_TOKEN == 'true' }} - run: nix path-info --json | jq -r '.[].path' | cachix push haskell-language-server + run: | + nix develop --command cabal update + nix develop --command cabal build + + # Build and then push HLS binaries with developmet shell to cachix + # This job runs when PRs are merged to master, and should be excluded from branch protections + build: + runs-on: ${{ matrix.os }} + if: ${{ github.repository_owner == 'haskell' && github.ref == 'ref/heads/master' }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macOS-latest] + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: cachix/install-nix-action@v13 + with: + install_url: https://nixos-nix-install-tests.cachix.org/serve/lb41az54kzk6j12p81br4bczary7m145/install + install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve' + extra_nix_config: | + experimental-features = nix-command flakes + nix_path: nixpkgs=channel:nixos-unstable + - uses: cachix/cachix-action@v10 + with: + name: haskell-language-server + authToken: ${{ secrets.HLS_CACHIX_AUTH_TOKEN }} + - run: | + nix develop --profile dev && cachix push haskell-language-server dev + nix build + nix path-info --json | jq -r '.[].path' | cachix push haskell-language-server diff --git a/default.nix b/default.nix new file mode 100644 index 0000000000..d87fd23886 --- /dev/null +++ b/default.nix @@ -0,0 +1,11 @@ +# This file is the compt layer of flakes: https://github.com/edolstra/flake-compat +# See flake.nix for details +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; } +) { + src = ./.; +}).defaultNix