Skip to content

Commit

Permalink
all: add flake and use for CI environment
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiezen committed Jul 29, 2023
1 parent 3ea5cd1 commit 367d719
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# shellcheck shell=bash
use flake
69 changes: 21 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,23 @@ jobs:
- "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.20"
- name: Check out code
uses: actions/checkout@v3
- name: Install Git
run: release/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="git_$(echo "$GIT_VERSION" | sed -e 's/\./_/g')"
nix shell ".#$git_attr" '.#default.go' --command \
go test \
-mod=readonly \
-v \
-race \
./...
env:
GO111MODULE: on
GIT_VERSION: ${{ matrix.git }}
- name: Build binary
run: release/build.bash gg
env:
GO111MODULE: on
run: nix develop --command release/build.bash gg
if: matrix.git == '2.27.0'
- name: Upload binary
uses: actions/upload-artifact@v3
Expand All @@ -78,24 +60,23 @@ jobs:
name: macOS
runs-on: macOS-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Check out code
uses: actions/checkout@v3
- name: Download dependencies
run: go mod download
env:
GO111MODULE: on
- name: Install Nix
uses: cachix/install-nix-action@v22
- name: Run tests
run: go test -mod=readonly -v ./...
run: |
git_attr="git_$(echo "$GIT_VERSION" | sed -e 's/\./_/g')"
nix shell ".#$git_attr" '.#default.go' --command \
go test \
-mod=readonly \
-v \
-race \
./...
env:
GO111MODULE: on
GIT_VERSION: "2.27.0"
- name: Build binary
run: release/build.bash gg
env:
GO111MODULE: on
run: nix develop --command release/build.bash gg
- name: Upload binary
uses: actions/upload-artifact@v3
with:
Expand All @@ -105,24 +86,16 @@ jobs:
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.20"
- name: Check out code
uses: actions/checkout@v3
- name: Download dependencies
run: go mod download
env:
GO111MODULE: on
- name: Run tests
run: go test -mod=readonly -v ./...
env:
GO111MODULE: on
- name: Build binary
run: release\build.ps1 -out gg.exe
env:
GO111MODULE: on
- name: Upload binary
uses: actions/upload-artifact@v3
with:
Expand Down
26 changes: 6 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, macOS-latest]
os: [ubuntu-latest, macOS-latest]
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Check out code
uses: actions/checkout@v3
- name: Download dependencies
run: go mod download
env:
GO111MODULE: on
- name: Package release
run: release/release.bash
env:
GO111MODULE: on
id: package
- name: Install Nix
uses: cachix/install-nix-action@v22
- id: package
name: Package release
run: nix develop --command release/release.bash
- name: Upload binary
uses: actions/upload-release-asset@v1
env:
Expand All @@ -60,16 +52,10 @@ jobs:
go-version: "1.20"
- name: Check out code
uses: actions/checkout@v3
- name: Download dependencies
run: go mod download
env:
GO111MODULE: on
- name: Package release
run: .\release.ps1 -version ($Env:GITHUB_REF).trimstart('refs/tags/v')
working-directory: .\release\msi
id: package
env:
GO111MODULE: on
- name: Upload binary
uses: actions/upload-release-asset@v1
env:
Expand Down
71 changes: 71 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{ lib
, buildGoModule
, nix-gitignore
, installShellFiles
, makeWrapper
, bash
, coreutils
, git
, pandoc
, commit ? null
}:

let
pname = "gg-scm";
version = "1.3.0";
in buildGoModule {
inherit pname version;

src = let
root = ./.;
patterns = nix-gitignore.withGitignoreFile extraIgnores root;
extraIgnores = [ ".github" ".vscode" "*.nix" "flake.lock" ];
in builtins.path {
name = "${pname}-source";
path = root;
filter = nix-gitignore.gitignoreFilterPure (_: _: true) patterns root;
};
postPatch = ''
substituteInPlace cmd/gg/editor_unix.go \
--replace /bin/sh ${bash}/bin/sh
'';
subPackages = [ "cmd/gg" ];
ldflags = [
"-s" "-w"
"-X" "main.versionInfo=${version}"
] ++ lib.lists.optional (!builtins.isNull commit) [
"-X" "main.buildCommit=${commit}"
];

vendorHash = "sha256-2z3PdyJ2xq4R2uuwYreff2G/ZNgsPoFZ9UeQ0Ly3KhU=";

nativeBuildInputs = [ pandoc installShellFiles makeWrapper ];
nativeCheckInputs = [ bash coreutils git ];
buildInputs = [ bash git ];

postBuild = ''
pandoc --standalone --to man misc/gg.1.md -o misc/gg.1
'';

postInstall = ''
wrapProgram $out/bin/gg --suffix PATH : ${git}/bin
installManPage misc/gg.1
installShellCompletion --cmd gg \
--bash misc/gg.bash \
--zsh misc/_gg.zsh
'';

meta = with lib; {
mainProgram = "gg";
description = "Git with less typing";
longDescription = ''
gg is an alternative command-line interface for Git heavily inspired by Mercurial.
It's designed for less typing in common workflows,
making Git easier to use for both novices and advanced users alike.
'';
homepage = "https://gg-scm.io/";
changelog = "https://github.com/gg-scm/gg/blob/v${version}/CHANGELOG.md";
license = licenses.asl20;
maintainers = with maintainers; [ zombiezen ];
};
}
Loading

0 comments on commit 367d719

Please sign in to comment.