Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix shell and refactor actions #249

Merged
merged 11 commits into from
Apr 30, 2024
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
98 changes: 19 additions & 79 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,31 @@ on:
pull_request:

jobs:
golangci-lint:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: cachix/install-nix-action@v26
with:
go-version: "^1.22"
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout=10m
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Run linters
run: |
nix develop --ignore-environment --command task install-webui
nix develop --ignore-environment --keep HOME . --command task lint

go-test:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: cachix/install-nix-action@v26
with:
go-version: "^1.22"
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
run: go test -v ./...

webui-lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: webui
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- run: npm ci
- run: npm run eslint:check

webui-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: webui
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- run: npm ci
- name: Run headless test
uses: coactions/setup-xvfb@v1
with:
run: npm test
working-directory: webui

prettier:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prettify code
uses: creyD/prettier_action@v4.3
with:
prettier_options: --check .
run: |
nix develop --ignore-environment --command task install-webui
nix develop --ignore-environment --keep HOME . --command task test

# This job runs all code generations and builds the WebUI, to check that everything is correctly committed
generated:
Expand All @@ -99,35 +58,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check nothing changed
run: git diff --exit-code
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v5
with:
go-version: "^1.22"
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Setup protoc
uses: arduino/setup-protoc@v3
- uses: cachix/install-nix-action@v26
with:
version: "23.4"
- name: Install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.33.0
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Install web app, apply database migrations, generate code and build web app
run: |
(cd webui && npm ci); \
task migrate; \
task gen; \
task build-webui
nix develop --ignore-environment --command task install-webui
nix develop --ignore-environment --keep HOME --keep POSTGRES_PASSWORD . --command task migrate
nix develop --ignore-environment --keep HOME --keep POSTGRES_PASSWORD . --command task gen
nix develop --ignore-environment . --command task build-webui
env:
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_NAME: bitmagnet
- name: Check nothing changed
run: git diff --exit-code
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.env*
.env
.env.*
.direnv
.idea
/data
/bitmagnet
Expand Down
45 changes: 32 additions & 13 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,36 @@ tasks:

lint:
cmds:
- golangci-lint run
- task lint-golangci
- task lint-webui
- task lint-prettier

lint-golangci:
cmds:
- golangci-lint run --timeout=10m

lint-webui:
dir: ./webui
cmds:
- npm run lint

lint-prettier:
cmds:
- prettier --check .

test:
cmds:
- go test ./...
- task test-go
- task test-webui

test-go:
cmds:
- go test -v ./...

test-webui:
dir: ./webui
cmds:
- npm test

migrate:
cmds:
Expand All @@ -39,6 +64,11 @@ tasks:
- bundle install
- bundle exec jekyll build

install-webui:
dir: ./webui
cmds:
- npm ci

serve-webui:
dir: ./webui
cmds:
Expand Down Expand Up @@ -84,14 +114,3 @@ tasks:
- goose -s create {{.NAME}} sql
vars:
NAME: migration

install-protoc:
cmds:
- |
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v{{.VERSION}}/protoc-{{.VERSION}}-{{.PLATFORM}}.zip
sudo unzip -o protoc-{{.VERSION}}-{{.PLATFORM}}.zip -d /usr/local bin/protoc
sudo unzip -o protoc-{{.VERSION}}-{{.PLATFORM}}.zip -d /usr/local 'include/*'
rm -f protoc-{{.VERSION}}-{{.PLATFORM}}.zip
vars:
VERSION: 23.4
PLATFORM: osx-x86_64
3 changes: 2 additions & 1 deletion bitmagnet.io/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ GEM

PLATFORMS
arm64-darwin-22
arm64-darwin-23

DEPENDENCIES
jekyll (~> 4.3)
Expand All @@ -91,4 +92,4 @@ DEPENDENCIES
webrick (~> 1.8)

BUNDLED WITH
2.4.10
2.5.7
4 changes: 4 additions & 0 deletions bitmagnet.io/internals-development/tech-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Some key libraries used include:

Using [Angular Material components](https://material.angular.io/). The web UI is embedded in the GoLang binary and served by the Gin web framework, and hence the build artifacts are committed into the repository.

## Nix dev shell

The repository includes a Nix shell for a reproducible development environment. To use the shell, simply [install Nix](https://nixos.org/download/) then run `nix develop` (or better still, use [nix-direnv](https://github.com/nix-community/nix-direnv) to use the included shell automatically.

## Other tooling

- The repository includes a [Taskfile](https://taskfile.dev/) containing several useful development scripts
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.

31 changes: 31 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
description = "A basic flake with a shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = {
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
formatter = pkgs.alejandra;
devShells = {
default = pkgs.mkShell {
packages = with pkgs; [
bundler
go_1_22
go-task
golangci-lint
jekyll
nodejs_20
nodePackages.prettier
protobuf
protoc-gen-go
];
};
};
});
}
2 changes: 1 addition & 1 deletion internal/protobuf/bitmagnet.pb.go

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

3 changes: 2 additions & 1 deletion webui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
"@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],
"scripts": []
"scripts": [],
"karmaConfig": "karma.conf.js"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion webui/dist/bitmagnet/index.html

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions webui/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

process.env.CHROME_BIN = require("puppeteer").executablePath();

module.exports = function (config) {
config.set({
basePath: "",
frameworks: ["jasmine", "@angular-devkit/build-angular"],
plugins: [
require("karma-jasmine"),
require("karma-chrome-launcher"),
require("karma-jasmine-html-reporter"),
require("karma-coverage"),
require("@angular-devkit/build-angular/plugins/karma"),
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: config.singleRun, // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
dir: require("path").join(__dirname, "./coverage/bitmagnet"),
subdir: ".",
reporters: [{ type: "html" }, { type: "text-summary" }],
},
reporters: ["progress", "kjhtml"],
browsers: ["ChromeHeadless"],
restartOnFileChange: true,
});
};
Loading
Loading