Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
31 changes: 31 additions & 0 deletions .github/actions/setup-nix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Setup Nix
description: Install Nix, restore/save the Nix store cache, and run flake check.

inputs:
github-token:
description: Token passed to install-nix-action for authenticated fetches.
required: true

runs:
using: composite
steps:
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ inputs.github-token }}

- name: Cache Nix store
uses: nix-community/cache-nix-action@v7
with:
primary-key: nix-${{ runner.os }}-${{ hashFiles('flake.nix', 'flake.lock') }}
restore-prefixes-first-match: nix-${{ runner.os }}-
# Cap store at ~5 GiB on save so cache fits under GHA's 10 GB repo budget
gc-max-store-size-linux: 5368709120
purge: true
purge-prefixes: nix-${{ runner.os }}-
purge-created: 0
purge-primary-key: never

- name: Nix flake check
shell: bash
run: nix flake check
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@ jobs:
- name: Checkout
uses: actions/checkout@v7.0.0

- name: Install Go
uses: actions/setup-go@v6.5.0
with:
go-version-file: go.mod
cache: true
- name: Setup Nix
uses: ./.github/actions/setup-nix

- name: Check for vulnerabilities
run: go run golang.org/x/vuln/cmd/govulncheck@latest ./...
run: nix develop --command govulncheck ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
version: v2.12.2

- name: Build and Test
run: make
run: nix develop --command make
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ bin/.generate: $(go_files) bin/.vendor

fmt: bin/.generate $(go_files)
# Formatting files...
@go run golang.org/x/tools/cmd/goimports -w $(go_files)
@goimports -w $(go_files)

bin/.vet: bin/.generate $(go_files)
go vet ./...
@touch bin/.vet

bin/.fmtcheck: bin/.generate $(go_files)
# Checking format of Go files...
@GOIMPORTS=$$(go run golang.org/x/tools/cmd/goimports -l $(go_files)) && \
@GOIMPORTS=$$(goimports -l $(go_files)) && \
if [ "$$GOIMPORTS" != "" ]; then \
go run golang.org/x/tools/cmd/goimports -d $(go_files); \
goimports -d $(go_files); \
exit 1; \
fi
@touch bin/.fmtcheck
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ func main() {
}
```

## Development

The repo ships a [Nix flake](flake.nix) that pins the toolchain (Go, `golangci-lint`, `gotools`, `govulncheck`, GNU `make`) so local development matches CI. Combined with [direnv](https://direnv.net/), your shell automatically enters that environment when you `cd` into the repo.

### Setup

1. Install Nix with flakes enabled — the [Determinate Nix Installer](https://determinate.systems/nix-installer/) is the easiest option; the [official Nix installer](https://nixos.org/download/) works too but requires [enabling flakes manually](https://nixos.wiki/wiki/Flakes#Enable_flakes_permanently_in_NixOS).
2. Install [direnv](https://direnv.net/docs/installation.html) and hook it into your shell.
3. Install [nix-direnv](https://github.com/nix-community/nix-direnv) so direnv can load the flake's dev shell.
4. From the repo root, activate the environment:
```shell
direnv allow
```

Every subsequent `cd` into the repo brings up a shell with the pinned toolchain on `PATH`. Run `make` to execute the same checks CI runs.

## Releasing

Releases are published as Git tags of the form `vX.Y.Z`, so Go consumers pull a
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
description = "Flake for Redis Cloud Go API";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.gnumake

pkgs.go_1_25
pkgs.golangci-lint
pkgs.gotools
pkgs.govulncheck
];
};
}
);
}