From b20b07dc3de529e084655e85aacd272ce416acc5 Mon Sep 17 00:00:00 2001 From: Ross Light Date: Fri, 28 Jul 2023 15:59:48 -0700 Subject: [PATCH] .github: use Nix to build Git --- .github/workflows/build.yml | 67 ++++++++++--------------------------- flake.nix | 16 ++++----- 2 files changed, 26 insertions(+), 57 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4983224..887dd5f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,90 +23,59 @@ on: jobs: linux: name: Linux - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest strategy: matrix: git: - - "2.27.0" # latest - - "2.25.1" # Ubuntu LTS 20.04 focal - - "2.20.1" # Debian buster - - "2.17.1" # Ubuntu LTS 18.04 bionic + - "2.27.0" # latest + - "2.25.1" # Ubuntu LTS 20.04 focal + - "2.20.1" # Debian buster + - "2.17.1" # Ubuntu LTS 18.04 bionic steps: - - name: Install Git dependencies - run: | - sudo apt-get update && - sudo apt-get install -y --no-install-recommends \ - gettext \ - libcurl4-gnutls-dev \ - libexpat1-dev \ - libssl-dev \ - libz-dev \ - xz-utils - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.19" - name: Check out code uses: actions/checkout@v3 - - name: Install Git - run: misc/build-git.bash ~/git ${{ matrix.git }} - - name: Download dependencies - run: go mod download - env: - GO111MODULE: on + - name: Install Nix + uses: cachix/install-nix-action@v22 - name: Run tests run: | - PATH="$HOME/git/bin-wrappers:$PATH" \ + git_attr="$(echo "$GIT_VERSION" | sed -e 's/\./_/g')" + nix shell ".#$git_attr" '.#go' --command \ go test \ -mod=readonly \ -v \ -race \ ./... env: + GIT_VERSION: ${{ matrix.git }} GO111MODULE: on mac: name: macOS runs-on: macOS-latest steps: - - name: Install xz - run: brew update && brew install xz - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.19" - name: Check out code uses: actions/checkout@v3 - - name: Install Git - run: misc/build-git.bash ~/git 2.27.0 - - name: Download dependencies - run: go mod download - env: - GO111MODULE: on + - name: Install Nix + uses: cachix/install-nix-action@v22 - name: Run tests run: | - PATH="$HOME/git/bin-wrappers:$PATH" \ + git_attr="$(echo "$GIT_VERSION" | sed -e 's/\./_/g')" + nix shell ".#$git_attr" '.#go' --command \ go test \ -mod=readonly \ -v \ -race \ ./... env: - GO111MODULE: on + GIT_VERSION: "2.27.0" windows: name: Windows runs-on: windows-latest steps: + - name: Check out code + uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v4 with: - go-version: "1.19" - - name: Check out code - uses: actions/checkout@v3 - - name: Download dependencies - run: go mod download - env: - GO111MODULE: on + go-version: "1.20" - name: Run tests run: go test -mod=readonly -v -race ./... - env: - GO111MODULE: on diff --git a/flake.nix b/flake.nix index 75ef5ef..b75097c 100644 --- a/flake.nix +++ b/flake.nix @@ -38,6 +38,8 @@ let pkgs = import nixpkgs { inherit system; }; in { + packages.go = pkgs.go_1_20; + packages.git = pkgs.git; packages.git_2_17_1 = self.lib.buildGit { @@ -79,16 +81,14 @@ outputs = [ "out" ]; }); - devShells.default = self.lib.mkShell { inherit pkgs; }; + devShells.default = pkgs.mkShell { + packages = [ + self.packages.${system}.go + pkgs.git + ]; + }; } ) // { - lib.mkShell = { pkgs, git ? pkgs.git }: pkgs.mkShell { - packages = [ - pkgs.go_1_20 - git - ]; - }; - lib.buildGit = { pkgs, packagePath, args ? {} }: let defaultArgs = {