Skip to content

Commit

Permalink
Merge pull request #171 from kachick/dev-with-nix
Browse files Browse the repository at this point in the history
Pin bash and asdf-vm versions with Nix for stable development
  • Loading branch information
kachick authored Mar 23, 2024
2 parents 8ae2ff2 + 0e491ad commit 5b2d088
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

use flake
17 changes: 10 additions & 7 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/setup@v3
- uses: DeterminateSystems/nix-installer-action@v10
- run: nix develop --command echo 'This step should be done before any other "nix develop" steps because of measuring Nix build time'
- run: |
asdf plugin-add cargo-make https://github.com/kachick/asdf-cargo-make.git
asdf plugin update cargo-make ${{ github.ref }} # https://github.com/asdf-vm/asdf/issues/1201
asdf install cargo-make
makers help
makers setup
makers check
nix develop --command bash -c '
asdf plugin-add cargo-make https://github.com/kachick/asdf-cargo-make.git
asdf plugin update cargo-make ${{ github.ref }} # https://github.com/asdf-vm/asdf/issues/1201
asdf install cargo-make
makers help
makers setup
makers check
'
1 change: 1 addition & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
with:
# https://spdx.org/licenses/
allow-licenses: MIT, BSD-3-Clause, BSD-2-Clause, 0BSD, Unlicense, ISC, Apache-2.0
allow-dependencies-licenses: pkg:githubactions/DeterminateSystems/nix-installer-action
23 changes: 18 additions & 5 deletions .github/workflows/merge-bot-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@ permissions:
# actions: read # For private repositories

jobs:
dependabot:
judge-dependabot:
timeout-minutes: 5
runs-on: ubuntu-latest
outputs:
merge: ${{ steps.conclusion.outputs.merge }}
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
id: dependabot
uses: dependabot/fetch-metadata@v2.0.0
- name: Judge
id: conclusion
if: >-
steps.dependabot.outputs.update-type != 'version-update:semver-major' ||
contains(steps.dependabot.outputs.dependency-names, 'DeterminateSystems')
run: echo -n 'merge=true' | tee -a "$GITHUB_OUTPUT"
dependabot:
needs: [judge-dependabot]
if: ${{ needs.judge-dependabot.outputs.merge == 'true' }}
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Wait other jobs
if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}}
uses: kachick/wait-other-jobs@v2
timeout-minutes: 30
with:
retry-method: 'equal_intervals'
min-interval-seconds: '15'
- name: Approve and merge
if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}}
run: gh pr review --approve "$PR_URL" && gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Contributing

Maintaining this repository assumes that you are not using old versions of bash such as 3.x, which is included in MacOS\
I recommend using the [Nix package manager](https://nixos.org/) to prepare base environments.\
This repository contains the [flake.nix](flake.nix).

After installing asdf, running below command in this repo finishes setups.

```console
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Tested also [mise](https://github.com/jdx/mise).

# Dependencies

- `asdf-vm` or `mise`
- `bash`, `curl`, `unzip`: generic POSIX utilities.

This plugin requires `unzip` to be installed.
Expand Down
2 changes: 1 addition & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"https://plugins.dprint.dev/json-0.19.2.wasm",
"https://plugins.dprint.dev/markdown-0.16.4.wasm",
"https://plugins.dprint.dev/toml-0.6.1.wasm",
"https://plugins.dprint.dev/prettier-0.36.0.json@5cc11bcb86b783ba9e33d171ee5caefe413a6ee31a4f1521592ccb28363412af"
"https://plugins.dprint.dev/prettier-0.39.0.json@896b70f29ef8213c1b0ba81a93cee9c2d4f39ac2194040313cd433906db7bc7c"
]
}
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.

41 changes: 41 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
inputs = {
# Candidate channels
# - https://github.com/kachick/anylang-template/issues/17
# - https://discourse.nixos.org/t/differences-between-nix-channels/13998
# How to update the revision
# - `nix flake update --commit-lock-file` # https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-update.html
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
formatter = pkgs.nixpkgs-fmt;
devShells.default = with pkgs;
mkShell {
buildInputs = [
# - Use newest bash to avoid darwin old bash problems. For example #139
# - Avoid https://github.com/NixOS/nix/issues/730#issuecomment-162323824
bashInteractive

# Keep minimum tools in nix layer, this repository should depend them with the asdf or mise itself(.tool-versions)
# So written here should be also clarified in [depedndencies](README.md#Dependencies)
curl
unzip
asdf-vm
# Also do not specify mise to avoid conflict with asdf
# mise
];

shellHook = ''
. "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh"
'';
};
}
);
}
5 changes: 4 additions & 1 deletion scripts/format.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

set -euxo pipefail

# This option don't work in old bash as 3.x that installed in macOS
shopt -s globstar

shfmt --language-dialect bash --write \
./**/*
./**/*.bash bin/**/*

dprint fmt
5 changes: 4 additions & 1 deletion scripts/lint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

set -euxo pipefail

# This option don't work in old bash as 3.x that installed in macOS
shopt -s globstar

shellcheck --shell=bash --external-sources \
bin/* --source-path=lib/ \
lib/* \
scripts/*

shfmt --language-dialect bash --diff \
./**/*
./**/*.bash bin/**/*

dprint check

Expand Down

0 comments on commit 5b2d088

Please sign in to comment.