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
15 changes: 10 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@ jobs:
- "**/*.sql"
- "go.mod"
- "go.sum"
- "Makefile"

- name: Install Nix
if: steps.filter.outputs.source_code == 'true'
uses: DeterminateSystems/nix-installer-action@main

- name: Format check
if: steps.filter.outputs.source_code == 'true'
run: nix develop -c bash -c "make fmt && git diff --exit-code"
run: nix develop .#ci -c bash -c "make fmt && git diff --exit-code"

- name: Check
if: steps.filter.outputs.source_code == 'true'
run: nix develop -c make check
run: nix develop .#ci -c make check

- name: Sql check
if: steps.filter.outputs.source_code == 'true'
run: nix develop -c make check-sql
run: nix develop .#ci -c make check-sql

- name: Build
if: steps.filter.outputs.source_code == 'true'
run: nix develop -c make build
run: nix develop .#ci -c make build

- name: Generated files check
if: steps.filter.outputs.source_code == 'true'
run: nix develop .#ci -c bash -c "make generate && git diff --exit-code"

- name: Test
if: steps.filter.outputs.source_code == 'true'
run: nix develop -c make test
run: nix develop .#ci -c make test
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ GO_DEPS := $(GO_SOURCES) go.mod go.sum
MIGRATE_DIR := sql/migrations
DB_URL := sqlite3://dev.db

DOCS_DEPS := $(wildcard internal/api/handlers/*.go)
DOCS_TARGET := internal/api/docs/docs.go
SQLC_DEPS := $(wildcard sql/migrations/*.sql) $(wildcard sql/queries/*.sql)
SQLC_TARGET := internal/api/dbmodels/models.go

Expand All @@ -25,7 +23,7 @@ build: api cli ## Build the api and cli binaries

api: $(BIN_DIR)/$(API_NAME) ## Build the api binary

$(BIN_DIR)/$(API_NAME): $(GO_DEPS) $(SQLC_TARGET)
$(BIN_DIR)/$(API_NAME): $(GO_DEPS) sqlc
@mkdir -p $(BIN_DIR)
go build -ldflags "-X main.Version=$(VERSION)" -o $(BIN_DIR)/$(API_NAME) ./cmd/$(API_NAME)

Expand All @@ -35,19 +33,21 @@ $(BIN_DIR)/$(CLI_NAME): $(GO_DEPS)
@mkdir -p $(BIN_DIR)
go build -ldflags "-X cli.Version=$(VERSION)" -o $(BIN_DIR)/$(CLI_NAME) ./cmd/$(CLI_NAME)

generate: $(DOCS_TARGET) $(SQLC_TARGET) ## Generate all necessary files with
generate: swag sqlc ## Generate all necessary files

$(DOCS_TARGET): $(DOCS_DEPS)
swag: ## Generate OpenAPI docs
swag init -d cmd/acmcsuf-api,internal/api/handlers,internal/api/dbmodels -o internal/api/docs --parseDependency

sqlc: $(SQLC_TARGET) ## Generate dbmodels package with sqlc

$(SQLC_TARGET): $(SQLC_DEPS)
sqlc generate

fmt: ## Format all go files
@go fmt ./...

check: ## Run static analysis on all go files
staticcheck -f stylish ./...
staticcheck -f stylish ./...

test: check ## Run all tests
go test ./...
Expand Down
18 changes: 11 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@
package = pkgs.callPackage ./nix/package.nix {
version = version;
};

acmcsuf-api = {
type = "app";
program = "${package}/bin/acmcsuf-api";
};
acmcsuf-cli = {
type = "app";
program = "${package}/bin/acmcsuf-cli";
};
in {
packages.default = package;
devShells.default = pkgs.callPackage ./nix/shell.nix {};
devShells = {
default = pkgs.callPackage ./nix/shell.nix {};
full = pkgs.callPackage ./nix/shell.nix {full = true;};
ci = pkgs.callPackage ./nix/shell.nix {isCI = true;};
};

packages.default = package;
apps = {
default = acmcsuf-api;
acmcsuf-api = acmcsuf-api;
acmcsuf-cli = {
type = "app";
program = "${package}/bin/acmcsuf-cli";
};
acmcsuf-cli = acmcsuf-cli;
};
}
);
Expand Down
4 changes: 2 additions & 2 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
buildGoModule,
}:
buildGoModule {
name = "acmcsuf-api";
pname = "acmcsuf-api";
src = ../.;
version = version;
vendorHash = "sha256-qr5wgHUKVv+Sv7TQGgOX9zRx9O6OgqFA16xwBTSysb4=";
vendorHash = "sha256-XCzKPPjCbO2Kp9XGZ94PpPedyJhFAs+ys+gna66jDSE=";
subPackages = ["cmd/acmcsuf-api" "cmd/acmcsuf-cli"];
ldflags = ["-X main.Version=${version}"];

Expand Down
79 changes: 43 additions & 36 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
{
mkShell,
lib,
go,
gopls,
delve,
sqlc,
air,
sqlfluff,
gnumake,
curl,
xh,
jq,
go-swag,
cobra-cli,
go-tools,
go-migrate,
sqlite,
sqlite-web,
}:

let
go-migrate-sqlite = go-migrate.overrideAttrs (oldAttrs: {
tags = [ "sqlite3" ];
});
isCI ? false,
full ? false,
}: let
go-migrate-sqlite = go-migrate.overrideAttrs (oldAttrs: {
tags = ["sqlite3"];
});
in
mkShell {
packages = [
go
gopls # Go language server
go-tools
delve # Go debugger
sqlc # compiles SQL queries to Go code
air # run dev server with hot reload
sqlfluff # SQL linter
gnumake
curl
xh
jq
go-swag
cobra-cli
go-migrate-sqlite
sqlite
sqlite-web
];
mkShell {
packages =
[
go
gopls # Go language server
go-tools
sqlc # compiles SQL queries to Go code
sqlfluff # SQL linter
gnumake
go-swag
]
# Dev tools not required in CI go here
++ lib.optionals (!isCI) [
air # run dev server with hot reload
xh
go-migrate-sqlite
sqlite
cobra-cli
delve # Go debugger
]
# Heavyweight or rarely used tools go here
++ lib.optionals full [
sqlite-web
];

env = {
GOROOT = "${go}/share/go";
};

shellHook = ''
if [ ! -f .env ]; then
echo ".env file not found! Creating one from .env.example for you..."
cp .env.example .env
fi
echo -e "\e[32mLoaded nix dev shell\e[0m"
export GOROOT="${go}/share/go"
'';
}
shellHook = lib.optionalString (!isCI) ''
if [ ! -f .env ]; then
echo ".env file not found! Creating one from .env.example for you..."
cp .env.example .env
fi
echo -e "\e[32mLoaded nix dev shell\e[0m"
'';
}