Skip to content

Commit

Permalink
[Experiment] Replace a small shell script with go (#185)
Browse files Browse the repository at this point in the history
* Replace a simple bash script with golang

* Add simple go CI

* Replace `makers` with `cargo-make make`

* Replace cargo-make installer action with asdf

* Add trigger for make file
  • Loading branch information
kachick authored Jul 27, 2023
1 parent f6da56e commit f1470cd
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 19 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI - Go

on:
push:
branches:
- main
paths:
- '.github/workflows/ci-go.yml'
- '**.go'
- 'go.*'
- 'testdata/**'
- 'Makefile.toml'
pull_request:
paths:
- '.github/workflows/ci-go.yml'
- '**.go'
- 'go.*'
- 'testdata/**'
- 'Makefile.toml'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
# https://github.com/davidB/rust-cargo-make/pull/178 is the blocker, even if this action is recommended in cargo-make official docs
- uses: asdf-vm/actions/install@v2
with:
# Keep same version as used in *.nix
tool_versions: |
cargo-make 0.36.10
# - run: go test
- run: makers test-race
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: check format
run: go fmt ./... && git add --intent-to-add . && git diff --exit-code
- run: go vet ./...
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Keep same version as *.nix
# Keep same version as used in *.nix
- uses: crate-ci/[email protected]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
# Managed by home-manager
.config/fish/conf.d/
.config/fish/config.fish

dist/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"[fish]": {
"editor.defaultFormatter": "bmalehorn.vscode-fish"
},
"[go]": {
"editor.defaultFormatter": "golang.go"
},
"nix.serverPath": "nil",
"nix.enableLanguageServer": true,
"nix.serverSettings": {
Expand Down
17 changes: 16 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@ command = './scripts/fmt.bash'
alias = "lint"

[tasks.deps]
command = './scripts/print-deps.bash'
command = 'go'
args = [
'run',
'./cmd/print-deps',
]

[tasks.test-race]
command = 'go'
args = [
'build',
'-v',
'-race',
'-o',
'dist/print-deps',
'./...',
]
32 changes: 32 additions & 0 deletions cmd/print-deps/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"log"
"os/exec"
"strings"
)

func main() {
cmds := []struct {
path string
args []string
}{
{"go", []string{"version"}},
{"makers", []string{"--version"}},
{"nix", []string{"--version"}},
{"dprint", []string{"--version"}},
{"shellcheck", []string{"--version"}},
{"shfmt", []string{"--version"}},
{"fd", []string{"--version"}},
{"typos", []string{"--version"}},
{"gitleaks", []string{"version"}},
}

for _, cmd := range cmds {
output, err := exec.Command(cmd.path, cmd.args...).Output()
log.Printf("%s %s\n%s\n", cmd.path, strings.Join(cmd.args, " "), output)
if err != nil {
log.Fatalln(err)
}
}
}
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ pkgs.mkShell {
pkgs.coreutils
pkgs.fd
pkgs.typos
pkgs.go_1_20
];
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module print-deps

go 1.20
1 change: 1 addition & 0 deletions scripts/lint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ shellcheck ./**/*.bash
nixpkgs-fmt --check ./**/*.nix
typos . .github .config .vscode
gitleaks detect
go vet ./...
17 changes: 0 additions & 17 deletions scripts/print-deps.bash

This file was deleted.

0 comments on commit f1470cd

Please sign in to comment.