Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Use Nix flake for development (#17)
Browse files Browse the repository at this point in the history
* Clarify CI role with the name

* Use Nix flake

* Avoid to depend own dependent config as the test fixture
  • Loading branch information
kachick committed Jul 15, 2023
1 parent 9565c3e commit e4e11f2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use_nix
use flake
19 changes: 11 additions & 8 deletions .github/workflows/ci-dev.yml → .github/workflows/ci-nix.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name: CI - Development Environment
name: CI - Nix
on:
push:
branches: [main]
paths:
- '.github/workflows/ci-dev.yml'
- '.github/workflows/ci-nix.yml'
- '*.nix'
- 'flake.*'
- 'Taskfile.yml'
pull_request:
paths:
- '.github/workflows/ci-dev.yml'
- '.github/workflows/ci-nix.yml'
- '*.nix'
- 'flake.*'
- 'Taskfile.yml'
schedule:
# Every 10:42 JST
Expand All @@ -25,8 +27,9 @@ jobs:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix-build
- name: Log current versions
run: nix-shell --run 'task versions'
- name: Run main task
run: nix-shell --run 'task'
- name: Print nixpkgs version
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
- run: nix flake check
- run: nix develop --command echo 'This step should be done before any other "nix develop" steps because of measuring Nix build time'
- run: nix develop --command task versions
- run: nix develop --command task
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ go.work

# goreleaser generates to
dist/

.direnv/
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
## Setup

1. Install [Nix](https://nixos.org/) package manager
2. Run `nix-shell` or `nix-shell --command 'zsh'`
2. Run `nix develop` or `direnv allow` in project root
3. You can use development tools

```console
> nix-shell
(prepared bash)
> nix develop
(prepared shell)

> task fmt
task: [fmt] dprint fmt
Expand Down
35 changes: 34 additions & 1 deletion core_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
package core

import "testing"
import (
"os"
"testing"
)

func TestGetCurrentVersion(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("failed to get current working directory: %v", err)
}
t.Cleanup(func() {
err := os.Chdir(cwd)
if err != nil {
t.Fatalf("failed to rollback working directory: %v", err)
}
})
err = os.Chdir("testdata")
if err != nil {
t.Fatalf("failed to walk through testdata directory: %v", err)
}

got, err := GetCurrentVersion("default.nix")
if err != nil {
t.Fatalf("Getting the version has been failed: %s", err.Error())
Expand All @@ -28,6 +46,21 @@ func TestGetLastVersion(t *testing.T) {
}

func TestTargetPath(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("failed to get current working directory: %v", err)
}
t.Cleanup(func() {
err := os.Chdir(cwd)
if err != nil {
t.Fatalf("failed to rollback working directory: %v", err)
}
})
err = os.Chdir("testdata")
if err != nil {
t.Fatalf("failed to walk through testdata directory: %v", err)
}

got, err := GetTargetPath()
if err != nil {
t.Fatalf("Failed to get target files: %s", err.Error())
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.

27 changes: 27 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/e57b65abbbf7a2d5786acc86fdf56cde060ed026";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = with pkgs;
mkShell {
buildInputs = [
go_1_20
nil
nixpkgs-fmt
dprint
actionlint
go-task
goreleaser
typos
];
};
});
}
5 changes: 0 additions & 5 deletions default.nix → testdata/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
pkgs.mkShell {
buildInputs = [
pkgs.go_1_20
pkgs.nil
pkgs.nixpkgs-fmt
pkgs.dprint
pkgs.actionlint
pkgs.go-task
pkgs.goreleaser
pkgs.typos
];
}

0 comments on commit e4e11f2

Please sign in to comment.