Skip to content

Commit

Permalink
feat: setup dev shell using flakebox install
Browse files Browse the repository at this point in the history
  • Loading branch information
GetPsyched committed Jun 25, 2024
1 parent 635fda0 commit 8be5589
Show file tree
Hide file tree
Showing 11 changed files with 480 additions and 0 deletions.
1 change: 1 addition & 0 deletions .config/flakebox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp/
12 changes: 12 additions & 0 deletions .config/flakebox/bin/flakebox-in-each-cargo-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Run a given command in every directory that contains cargo workspace
# Right now it just scans for `Cargo.lock`

set -euo pipefail

find . -name Cargo.lock | while read -r path ; do
(
cd "$(dirname "$path")"
"$@"
)
done
1 change: 1 addition & 0 deletions .config/flakebox/id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d752795b0c685fbc54be836b6c4230b20d3c1bfd43afcdfec1a451f875585b13988fe9a84e24c816432ab5daca57d9960eaf47239a457855ead99210d25b80a7
32 changes: 32 additions & 0 deletions .config/flakebox/shellHook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
root="$(git rev-parse --show-toplevel)"
dot_git="$(git rev-parse --git-common-dir)"
if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi
# fix old bug
rm -f "${dot_git}/hooks/comit-msg"
rm -f "${dot_git}/hooks/commit-msg"
ln -sf "${root}/misc/git-hooks/commit-msg" "${dot_git}/hooks/commit-msg"

root="$(git rev-parse --show-toplevel)"
dot_git="$(git rev-parse --git-common-dir)"
if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi
# fix old bug
rm -f "${dot_git}/hooks/pre-comit"
rm -f "${dot_git}/hooks/pre-commit"
ln -sf "${root}/misc/git-hooks/pre-commit" "${dot_git}/hooks/pre-commit"

# set template
git config commit.template misc/git-hooks/commit-template.txt

if ! flakebox lint --silent; then
>&2 echo "ℹ️ Project recommendations detected. Run 'flakebox lint' for more info."
fi

if [ -n "${DIRENV_IN_ENVRC:-}" ]; then
# and not set DIRENV_LOG_FORMAT
if [ -n "${DIRENV_LOG_FORMAT:-}" ]; then
>&2 echo "💡 Set 'DIRENV_LOG_FORMAT=\"\"' in your shell environment variables for a cleaner output of direnv"
fi
fi

>&2 echo "💡 Run 'just' for a list of available 'just ...' helper recipes"
80 changes: 80 additions & 0 deletions .github/workflows/flakebox-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION

jobs:
build:
name: Build
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Build on ${{ matrix.host }}
run: nix build -L .#ci.mindmap
strategy:
matrix:
host:
- macos-x86_64
- macos-aarch64
- linux
include:
- host: linux
runs-on: ubuntu-latest
timeout: 60
- host: macos-x86_64
runs-on: macos-12
timeout: 60
- host: macos-aarch64
runs-on: macos-14
timeout: 60
timeout-minutes: ${{ matrix.timeout }}
flake:
name: Flake self-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Nix flake inputs
uses: DeterminateSystems/flake-checker-action@v5
with:
fail-mode: true
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Cargo Cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
path: ~/.cargo
- name: Commit Check
run: '# run the same check that git `pre-commit` hook does
nix develop --ignore-environment .#lint --command ./misc/git-hooks/pre-commit
'
name: CI
'on':
merge_group:
branches:
- master
- main
pull_request:
branches:
- master
- main
push:
branches:
- master
- main
tags:
- v*
workflow_dispatch: {}


# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION
35 changes: 35 additions & 0 deletions .github/workflows/flakebox-flakehub-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION

jobs:
flakehub-publish:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ (inputs.tag != null) && format('refs/tags/{0}', inputs.tag) || ''
}}
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Flakehub Push
uses: DeterminateSystems/flakehub-push@main
with:
name: ${{ github.repository }}
tag: ${{ inputs.tag }}
visibility: public
name: Publish to Flakehub
'on':
push:
tags:
- v?[0-9]+.[0-9]+.[0-9]+*
workflow_dispatch:
inputs:
tags:
description: The existing tag to publish to FlakeHub
required: true
type: string


# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION
5 changes: 5 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
group_imports = "StdExternalCrate"
wrap_comments = true
format_code_in_doc_comments = true
imports_granularity = "Module"
edition = "2021"
119 changes: 119 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION

alias b := build
alias c := check
alias t := test


[private]
default:
@just --list


# run `cargo build` on everything
build *ARGS="--workspace --all-targets":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo build {{ARGS}}

# run `cargo check` on everything
check *ARGS="--workspace --all-targets":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo check {{ARGS}}

# run all checks recommended before opening a PR
final-check: lint clippy
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo test --doc
just test

# run code formatters
format:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo fmt --all
nixpkgs-fmt $(echo **.nix)

# run lints (git pre-commit hook)
lint:
#!/usr/bin/env bash
set -euo pipefail
env NO_STASH=true $(git rev-parse --git-common-dir)/hooks/pre-commit

# run tests
test: build
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
cargo test

# run and restart on changes
watch *ARGS="-x run":
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f Cargo.toml ]; then
cd {{invocation_directory()}}
fi
env RUST_LOG=${RUST_LOG:-debug} cargo watch {{ARGS}}

# run `cargo clippy` on everything
clippy *ARGS="--locked --offline --workspace --all-targets":
cargo clippy {{ARGS}} -- --deny warnings --allow deprecated

# run `cargo clippy --fix` on everything
clippy-fix *ARGS="--locked --offline --workspace --all-targets":
cargo clippy {{ARGS}} --fix


# run `semgrep`
semgrep:
env SEMGREP_ENABLE_VERSION_CHECK=0 \
semgrep --error --no-rewrite-rule-ids --config .config/semgrep.yaml


# check typos
[no-exit-message]
typos *PARAMS:
#!/usr/bin/env bash
set -eo pipefail
export FLAKEBOX_GIT_LS
FLAKEBOX_GIT_LS="$(git ls-files)"
export FLAKEBOX_GIT_LS_TEXT
FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "^db/|\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico)\$")"


if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos {{PARAMS}} --file-list - --force-exclude ; then
>&2 echo "Typos found: Valid new words can be added to '.typos.toml'"
return 1
fi

# fix all typos
[no-exit-message]
typos-fix-all:
just typos -w

# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION
23 changes: 23 additions & 0 deletions misc/git-hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Sanitize file first, by removing leading lines that are empty or start with a hash,
# as `convco` currently does not do it automatically (but git will)
# TODO: next release of convco should be able to do it automatically
MESSAGE="$(
while read -r line ; do
# skip any initial comments (possibly from previous run)
if [ -z "${body_detected:-}" ] && { [[ "$line" =~ ^#.*$ ]] || [ "$line" == "" ]; }; then
continue
fi
body_detected="true"
echo "$line"
done < "$1"
)"
# convco fails on fixup!, so remove fixup! prefix
MESSAGE="${MESSAGE#fixup! }"
if ! convco check --from-stdin <<<"$MESSAGE" ; then
>&2 echo "Please follow conventional commits(https://www.conventionalcommits.org)"
>&2 echo "Use git recommit <args> to fix your commit"
exit 1
fi
2 changes: 2 additions & 0 deletions misc/git-hooks/commit-template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

# Explain *why* this change is being made width limit ->|
Loading

0 comments on commit 8be5589

Please sign in to comment.