From aeabcfd56256a74e29401362b2cf813e03eafdae Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Fri, 15 Dec 2023 12:11:19 -0600 Subject: [PATCH] ci/cd: use Nix for building and testing Pushup on GitHub Actions --- .github/workflows/go.yml | 22 +++++++--------------- flake.nix | 37 ++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e2ed946..4b6e010 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,20 +8,12 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.20' - - name: Build - run: go build -o pushup -ldflags "-s -w -extldflags '-static'" -v - env: - CGO_ENABLED: 0 - - name: Test - run: go test -v . ./_runtime + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v22 + - run: nix flake check + - run: nix build - name: Upload Pushup executable - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: pushup-exe - path: pushup - retention-days: 3 + name: pushup + path: result/bin/pushup diff --git a/flake.nix b/flake.nix index 663ffc5..2fc4e4f 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,7 @@ outputs = { self, nixpkgs }: let - version = "0.0.1"; # TODO(paulsmith): source from version.go + name = "pushup"; forEachSystem = fn: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-darwin" "aarch64-linux" ] (system: @@ -14,29 +14,36 @@ inherit system; }); in { - packages = forEachSystem ({ pkgs, system }: { - default = pkgs.buildGoModule rec { - pname = "pushup"; - inherit version; + packages = forEachSystem ({ pkgs, system }: + let + pname = name; + version = "0.0.1"; # TODO(paulsmith): source from version.go src = ./.; vendorHash = null; subPackages = "."; CGO_ENABLED = 0; - doCheck = false; - nativeBuildInputs = with pkgs; [ makeWrapper ]; - allowGoReference = true; - postInstall = '' - wrapProgram $out/bin/${pname} --prefix PATH : ${ - pkgs.lib.makeBinPath (with pkgs; [ go ]) - } - ''; meta = with nixpkgs.lib; { description = "Pushup web framework for Go"; homepage = "https://pushup.adhoc.dev/"; license = licenses.mit; }; - }; - }); + + in { + default = pkgs.buildGoModule rec { + inherit pname version src vendorHash subPackages CGO_ENABLED meta; + }; + + withGo = pkgs.buildGoModule rec { + inherit pname version src vendorHash subPackages CGO_ENABLED meta; + nativeBuildInputs = with pkgs; [ makeWrapper ]; + allowGoReference = true; + postInstall = '' + wrapProgram $out/bin/${pname} --prefix PATH : ${ + pkgs.lib.makeBinPath (with pkgs; [ go ]) + } + ''; + }; + }); devShells = forEachSystem ({ pkgs, ... }: { default =