From 6d2fae4d2749d893f5d027d5b4756e709a3847af Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 11 Oct 2020 03:56:30 -0300 Subject: Decouple testing with Nix Use Nix for build isolation not for test running. --- .build.yml | 1 - a-propos.md | 2 +- default.nix | 150 +++++++++------------------- nix/sources.json | 26 +++++ nix/sources.nix | 197 +++++++++++++++++++++++++++++++++++++ scripts/assert-content.sh | 25 ++--- scripts/assert-nixfmt.sh | 16 +++ scripts/assert-shellcheck.sh | 6 ++ scripts/assert-spelling.sh | 36 +++++++ scripts/assert-todos.sh | 12 +++ scripts/publish-env.sh | 4 - scripts/spelling/en.txt | 39 ++++++++ scripts/spelling/fr.txt | 8 ++ scripts/spelling/international.txt | 142 ++++++++++++++++++++++++++ scripts/spelling/pt.txt | 127 ++++++++++++++++++++++++ spelling/check-spelling.sh | 37 ------- spelling/en.txt | 39 -------- spelling/fr.txt | 8 -- spelling/international.txt | 142 -------------------------- spelling/pt.txt | 126 ------------------------ tests.sh | 12 +++ utils-i18n.nix | 52 ++++++++++ utils.nix | 105 -------------------- 23 files changed, 730 insertions(+), 582 deletions(-) create mode 100644 nix/sources.json create mode 100644 nix/sources.nix create mode 100755 scripts/assert-nixfmt.sh create mode 100755 scripts/assert-shellcheck.sh create mode 100755 scripts/assert-spelling.sh create mode 100755 scripts/assert-todos.sh delete mode 100644 scripts/publish-env.sh create mode 100644 scripts/spelling/en.txt create mode 100644 scripts/spelling/fr.txt create mode 100644 scripts/spelling/international.txt create mode 100644 scripts/spelling/pt.txt delete mode 100755 spelling/check-spelling.sh delete mode 100644 spelling/en.txt delete mode 100644 spelling/fr.txt delete mode 100644 spelling/international.txt delete mode 100644 spelling/pt.txt create mode 100755 tests.sh create mode 100644 utils-i18n.nix delete mode 100644 utils.nix diff --git a/.build.yml b/.build.yml index 2dce81d..ed27fd4 100644 --- a/.build.yml +++ b/.build.yml @@ -19,5 +19,4 @@ tasks: - docs: | cd website/ nix-build -A publishScript - source ./scripts/publish-env.sh ./result/bin/publish.sh diff --git a/a-propos.md b/a-propos.md index 661f25e..689da32 100644 --- a/a-propos.md +++ b/a-propos.md @@ -29,4 +29,4 @@ regrouper-les en utilisant LaTeX dans recueils de chansons. [Liste de pastebins]({% link pastebins.fr.md %}). -[Articles par catégory]({% link categories.fr.md %}). +[Articles par catégorie]({% link categories.fr.md %}). diff --git a/default.nix b/default.nix index b0cb35c..60e879b 100644 --- a/default.nix +++ b/default.nix @@ -1,114 +1,60 @@ let - pkgs = import (fetchTarball - "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { }; - dicts = rec { - mkDict = let - prefix = - "https://raw.githubusercontent.com/wooorm/dictionaries/61016e00e276f9bf5e52cbc6c02a45f2e49b2c7e/dictionaries"; - in { lang, dicSHA256, affSHA256 }: - let - dic = builtins.fetchurl { - url = "${prefix}/${lang}/index.dic"; - sha256 = dicSHA256; - }; - aff = builtins.fetchurl { - url = "${prefix}/${lang}/index.aff"; - sha256 = affSHA256; - }; - in pkgs.stdenv.mkDerivation { - name = "songbooks-dict-${lang}"; - builder = builtins.toFile "builder.sh" '' - source $stdenv/setup - install -dm755 $out/share/hunspell - install -m644 ${dic} $out/share/hunspell/${lang}.dic - install -m644 ${aff} $out/share/hunspell/${lang}.aff - runHook postInstall - ''; - }; - en = mkDict { - lang = "en"; - dicSHA256 = "1k4660ccwwpwac0rc7b8ih3vd24kxgvljkrakv2l1f72yfpw3bp2"; - affSHA256 = "0yvc2fhc03y0y1gwjyb20ifcrxnzm3ama1fri9r5gna092fz3qca"; - }; - pt = mkDict { - lang = "pt"; - dicSHA256 = "1z0kfxv8m361xhp4zwdlsn2ib8q3rnljj0b2s4482alyxpd00h9x"; - affSHA256 = "1ssj1g7qwh0lv3ajzvchwsfr7cgzrlqms28m1j3gm1y2avi50qhw"; - }; - fr = mkDict { - lang = "fr"; - dicSHA256 = "10p6jlk9j117mjd1z3dp3vfszcvxqha11kfvksqhvrq4ld9xwzbn"; - affSHA256 = "0d6k608h7gm1za3vdq1fhlwqzz2zxg1z0bx1bfvi0spg4a2mn09p"; - }; - }; - myHunspell = (pkgs.hunspellWithDicts (with dicts; [ en pt fr ])); -in rec { - utils = import ./utils.nix { - pkgs = pkgs; - src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; - baseName = "website"; - }; + niv-sources = import ./nix/sources.nix; + pkgs = import niv-sources.nixpkgs { }; + src = pkgs.nix-gitignore.gitignoreSource [ "!.git" ] ./.; + utils-i18n = pkgs.callPackage ./utils-i18n.nix { }; + jekyllEnv = pkgs.bundlerEnv { name = "jekyll-env"; gemfile = ./Gemfile; lockfile = ./Gemfile.lock; gemset = ./gemset.nix; }; - subtasks = rec { - hunspellCheck = utils.baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-hunspell"; - buildInputs = baseAttrs.buildInputs ++ [ myHunspell ]; - buildPhase = '' - patchShebangs . - ./spelling/check-spelling.sh "${subtasks.docs}" - touch $out - ''; - }); - assertContent = utils.baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-assert-content"; - buildInputs = baseAttrs.buildInputs ++ [ pkgs.jq ]; - buildPhase = '' - patchShebangs . - ./scripts/assert-content.sh "${subtasks.docs}/site.json" - touch $out - ''; - }); - docs = utils.baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-docs"; - buildInputs = [ jekyllEnv ]; - buildPhase = '' - patchShebangs . - jekyll build -d $out - ''; - }); - }; - test = utils.test [ - utils.formatNix - (utils.shellcheck null) - (utils.fixme [ - "utils.nix" - "TODOs.org" - "_pastebins/" - "_posts/" - "_tils/" - "drafts/" - "templates/" - ]) - subtasks.hunspellCheck - subtasks.assertContent - subtasks.docs + projectBuildInputs = with pkgs; [ + jekyllEnv + + nixfmt + git + shellcheck + jq + niv + (hunspellWithDicts (with utils-i18n.dicts; [ en pt fr ])) ]; - shell = pkgs.mkShell rec { - name = "website-shell"; - buildInputs = [ jekyllEnv myHunspell ]; +in rec { + site = pkgs.stdenv.mkDerivation { + inherit src; + name = "website-site"; + phases = [ "unpackPhase" "buildPhase" ]; + buildInputs = [ jekyllEnv ]; + buildPhase = '' + patchShebangs . + jekyll build -d $out + ''; }; - publishScript = utils.overwritingPublishScript { - docsDerivation = subtasks.docs; - overwrite = true; + test = pkgs.stdenv.mkDerivation { + inherit src; + name = "website-test"; + phases = [ "unpackPhase" "buildPhase" ]; + buildInputs = projectBuildInputs; + buildPhase = '' + patchShebangs . + ./tests.sh + touch $out + ''; }; - fastPublishScript = utils.overwritingPublishScript { - docsDerivation = subtasks.docs; - overwrite = false; + shell = pkgs.mkShell rec { + name = "website-shell"; + buildInputs = projectBuildInputs; }; - site = subtasks.docs; + publishScript = pkgs.writeShellScriptBin "publish.sh" '' + set -euo pipefail + SERVER_URL='root@euandre.org' + REMOTE_PATH='/home/user-data/www/default/' + OUT_DOCS='${site}' + ${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no "$SERVER_URL" rm -rf "$REMOTE_PATH/*" + ${pkgs.rsync}/bin/rsync -avzP \ + --rsh="ssh -o StrictHostKeyChecking=no" \ + "$OUT_DOCS/" \ + "$SERVER_URL:$REMOTE_PATH" + ''; } diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 0000000..c8fe824 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,26 @@ +{ + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "9d35b9e4837ab88517210b1701127612c260eccf", + "sha256": "0q50xhnm8g2yfyakrh0nly4swyygxpi0a8cb9gp65wcakcgvzvdh", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/9d35b9e4837ab88517210b1701127612c260eccf.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-unstable", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "420f89ceb267b461eed5d025b6c3c0e57703cc5c", + "sha256": "0c9kr76p6nmf4z2j2afgcddckbaxq6kxlmp1895h6qamm1c0ypb9", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/420f89ceb267b461eed5d025b6c3c0e57703cc5c.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 0000000..9f418ad --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,197 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let name' = sanitizeName name + "-src"; + in if spec.builtin or true then + builtins_fetchurl { + inherit (spec) url sha256; + name = name'; + } + else + pkgs.fetchurl { + inherit (spec) url sha256; + name = name'; + }; + + fetch_tarball = pkgs: name: spec: + let name' = sanitizeName name + "-src"; + in if spec.builtin or true then + builtins_fetchTarball { + name = name'; + inherit (spec) url sha256; + } + else + pkgs.fetchzip { + name = name'; + inherit (spec) url sha256; + }; + + fetch_git = name: spec: + let + ref = if spec ? ref then + spec.ref + else if spec ? branch then + "refs/heads/${spec.branch}" + else if spec ? tag then + "refs/tags/${spec.tag}" + else + abort + "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + in builtins.fetchGit { + url = spec.repo; + inherit (spec) rev; + inherit ref; + }; + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: + throw '' + [${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: + throw '' + [${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + (concatMapStrings (s: if builtins.isList s then "-" else s) + (builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name))); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = import + (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { + inherit system; + }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in if builtins.hasAttr "nixpkgs" sources then + sourcesNixpkgs + else if hasNixpkgsPath && !hasThisAsNixpkgsPath then + import { } + else + abort '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if !builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then + fetch_file pkgs name spec + else if spec.type == "tarball" then + fetch_tarball pkgs name spec + else if spec.type == "git" then + fetch_git name spec + else if spec.type == "local" then + fetch_local spec + else if spec.type == "builtin-tarball" then + fetch_builtin-tarball name + else if spec.type == "builtin-url" then + fetch_builtin-url name + else + abort + "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars + (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in if ersatz == "" then drv else ersatz; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or (f: set: + with builtins; + listToAttrs (map (attr: { + name = attr; + value = f attr set.${attr}; + }) (attrNames set))); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: + if first > last then + [ ] + else + builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: + map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let inherit (builtins) lessThan nixVersion fetchTarball; + in if lessThan nixVersion "1.12" then + fetchTarball + ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let inherit (builtins) lessThan nixVersion fetchurl; + in if lessThan nixVersion "1.12" then + fetchurl + ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs (name: spec: + if builtins.hasAttr "outPath" spec then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); }) + config.sources; + + # The "config" used by the fetchers + mkConfig = { sourcesFile ? + if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if isNull sourcesFile then + { } + else + builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem, pkgs ? mkPkgs sources system }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in mkSources (mkConfig { }) // { + __functor = _: settings: mkSources (mkConfig settings); +} diff --git a/scripts/assert-content.sh b/scripts/assert-content.sh index a0d661f..e694580 100755 --- a/scripts/assert-content.sh +++ b/scripts/assert-content.sh @@ -8,23 +8,8 @@ red() { echo -e "${red}${1}${end}"; } ## Constant definitions -JSON="${1:-}" -[[ -z "${JSON}" ]] && { - red 'Missing input JSON file.' - cat < - - Arguments - SITE_JSON_PATH Path to the site.json file which contains data and metadata about pages of the site. - -Examples: - $0 _site/site.json - $0 result/site.json - $0 \$(nix-build -A subtasks.docs)/site.json -EOF - exit 2 -} +jekyll build +JSON='_site/site.json' LANGS=(en pt fr) IGNORED_PAGES=(site.json sitemap.xml *.atom) @@ -138,6 +123,11 @@ for til in $(jq -r '.tils[] | @base64' "${JSON}"); do assert-frontmatter "$til" 'post' '_tils' done +echo Linting slides... >&2 +for slide in $(jq -r '.slides[] | @base64' "${JSON}"); do + assert-frontmatter "$slide" 'post' '_slides' +done + echo Asserting unique refs... >&2 KNOWN_IDS=() assert-unique-ref() { @@ -163,5 +153,6 @@ assert-unique-ref() { assert-unique-ref "$(jq -r '.pages[] | @base64' "${JSON}")" assert-unique-ref "$(jq -r '.articles[] | @base64' "${JSON}")" assert-unique-ref "$(jq -r '.tils[] | @base64' "${JSON}")" +assert-unique-ref "$(jq -r '.slides[] | @base64' "${JSON}")" echo Done. >&2 diff --git a/scripts/assert-nixfmt.sh b/scripts/assert-nixfmt.sh new file mode 100755 index 0000000..7a68fa9 --- /dev/null +++ b/scripts/assert-nixfmt.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +format() { + nix_file="${1}" + diff <(nixfmt < "${nix_file}") "${nix_file}" || { + echo "The file '${nix_file}' is unformatted. To fix it, run:" + echo " nixfmt ${nix_file}" + exit 1 + } +} +export -f format + +find . -type f -name '*.nix' -print0 | xargs -0 -I% bash -c "format %" diff --git a/scripts/assert-shellcheck.sh b/scripts/assert-shellcheck.sh new file mode 100755 index 0000000..e24c29c --- /dev/null +++ b/scripts/assert-shellcheck.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +git ls-files | grep '\.sh$' | xargs shellcheck diff --git a/scripts/assert-spelling.sh b/scripts/assert-spelling.sh new file mode 100755 index 0000000..caaecfa --- /dev/null +++ b/scripts/assert-spelling.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +export LANG=C.UTF-8 + +for DICT in scripts/spelling/*.txt; do + diff <(sort "$DICT") "$DICT" || { + echo "The $DICT dictionary is unsorted. To fix it, run:" >&2 + echo " LANG=C.UTF-8 sort docs/$DICT | sponge docs/$DICT" >&2 + exit 1 + } +done + +OUT="$(mktemp)" +shopt -s globstar +jekyll build +for f in _site/**/*.html; do + if ! grep -E '^_site/pastebin' <(echo "$f") > /dev/null; then + if ! grep -E '^_site/vendor/' <(echo "$f") > /dev/null; then + l="$(head -n2 "$f" | tail -n1 | cut -d\" -f2)" + hunspell -u3 -H -d "$l" -p <(cat scripts/spelling/international.txt "scripts/spelling/$l.txt") "$f" | tee -a "$OUT" + fi + fi +done + +if [[ -s "$OUT" ]]; then + printf "\nvvv Mispelled words detected by hunspell.\n\n" + sort < "$OUT" | uniq + printf "\n^^^\n" >&2 + exit 1 +else + echo "No spelling errors detected" + exit 0 +fi diff --git a/scripts/assert-todos.sh b/scripts/assert-todos.sh new file mode 100755 index 0000000..a59b4cd --- /dev/null +++ b/scripts/assert-todos.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +# shellcheck disable=2046 +if grep -R FIXME $(git ls-files) | \ + grep -Ev '^(vendor/|.git/|scripts/assert-todos.sh|templates)'; then + echo "Found dangling FIXME markers on the project." + echo "You should write them down properly on TODOs.org." + exit 1 +fi diff --git a/scripts/publish-env.sh b/scripts/publish-env.sh deleted file mode 100644 index d5e8be2..0000000 --- a/scripts/publish-env.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -export SERVER_URL=root@euandre.org -export DOCS_SERVER_PATH="/home/user-data/www/default/" diff --git a/scripts/spelling/en.txt b/scripts/spelling/en.txt new file mode 100644 index 0000000..bebfc76 --- /dev/null +++ b/scripts/spelling/en.txt @@ -0,0 +1,39 @@ +Patches +Rollout +Slides +aren +autocommit +backend +behaviour +couldn +cronjobs +curation +declaratively +decrypting +didn +doesn +duplications +embeddable +filesystem +filesystems +isn +maintainence +oday +portuguese +portuguse +pre +programmatically +realising +reimplementation +repo +reproducibility +scriptable +shouldn +symlinks +syncable +só +tradeoffs +untrusted +ve +wasn +wouldn diff --git a/scripts/spelling/fr.txt b/scripts/spelling/fr.txt new file mode 100644 index 0000000..aa09184 --- /dev/null +++ b/scripts/spelling/fr.txt @@ -0,0 +1,8 @@ +' +AJA +dimanche +earned +oday +ppris +só +ujourd'hui diff --git a/scripts/spelling/international.txt b/scripts/spelling/international.txt new file mode 100644 index 0000000..3536249 --- /dev/null +++ b/scripts/spelling/international.txt @@ -0,0 +1,142 @@ +144p +1D +250GB +2D +2nix +32GB +500GB +81F90EC3CD356060 +8GB +André +Atom +B1 +BN +BSON +BY +BY-SA +Bitbucket +CI +CLI +Cantrill +Clojure +CouchDB +DVCS +Datomic +EuAndreh +F +FFI +FTS +Fastmail +GADTs +GPLv +GPLv3 +GTK +GitLab +Gmail +GuixSD +HN +HTTPS +Halloway +Haskell +IndexedDB +JS +JSON +Joyent +L1 +LaTeX +Lerna +LilyPond +LiquidHaskell +Mailutils +Matroska +Mentat +Merkle +NPM +Nextcloud +NixOS +POSIX +Pastebin +PouchDB +README +RSS +Raku +Reddit +SA +SSD +Sourcehut +Spacemacs +StackOverflow +Staltz +TAB +TBs +TOML +TypeScript +UI +URL +VPN +WebAssembly +Yandex +YouTube +Zig +boneco +brainer +buildGoModule +cargo2nix +carte +cgit +ci +clojure +datalog +datom +datoms +dl +edn +en +euandreh +eval +fr +gcrypt +gt +guix +guixbuild +h1 +h6 +hinarioespirita +html +i5 +i7 +ify +intbytes +ish +jekyll +jemoji +js +kramdown +libre +lockfile +lockfiles +lt +merkle +myrepos +nixos +no-brainer +node2nix +noinform +npm +org +pastebin +pastebins +plaintext +progn +pt +sbcl +songbooks +sourcehut +sr +swift2nix +systemd +touchpad +v8 +xyz +youtube +à diff --git a/scripts/spelling/pt.txt b/scripts/spelling/pt.txt new file mode 100644 index 0000000..65d4ac8 --- /dev/null +++ b/scripts/spelling/pt.txt @@ -0,0 +1,127 @@ +Abaixo +Agosto +Anna +Aprendi +Atualizado +Blog +Cópia +H +HEA +I +L +Lista +Me +Patches +Postado +Postagens +Quando +T +Usar +Visite +Website +achar +arquivo +artigos +buscar +categoria +chegar +comece +comentário +como +completar +conhecimentos +contatar +criar +código +da +dados +de +desta +diretamente +direto +discussão +discussões +distribuir +do +dobráveis +dou eu +e +earned +email +empacotá +encontra +engasgo +entrada +envelope +escreva +escrever +escrevo +esforço +estou +eu +existentes +extra +fazer +ficou +formatos +gerar +impressão +inglês +interessantes +internet +intervalos +jeito +las +licenciado +licença +log +los +mandar +mande +me +mensagem +na +navegador +no +nome +normalmente +novo +o +oday +oje +ordená +os +padrão +para +parar +pessoal +por +post +postagens +prendi +procurando +procure +produção +projetos +pública +público +relacionados +reler +religioso +se +significa +simples +sobre +tempo +texto +timestamp +transpor +u +usando +usar +versão +versões +vindas +Ícone +é +úteis diff --git a/spelling/check-spelling.sh b/spelling/check-spelling.sh deleted file mode 100755 index 3ddfd2a..0000000 --- a/spelling/check-spelling.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail - -HTML_DIR="${1:-}" -[[ -z "${HTML_DIR}" ]] && { - echo 'Undefined input HTML_DIR.' >&2 - exit 2 -} - -# Required by =sort= and =hunspell= -export LANG=C.UTF-8 - -for DICT in spelling/*.txt; do - diff <(sort "$DICT" | uniq) "$DICT" || { - echo "The $DICT dictionary is unsorted. To fix it, run:" >&2 - echo " LANG=C.UTF-8 sort $DICT | uniq | sponge $DICT" >&2 - exit 1 - } -done - -rm -f spelling.txt -shopt -s globstar -for f in "${HTML_DIR}"/**/*.html; do - if ! grep -E '/pastebin(/|s.html)' <(echo "$f") > /dev/null; then - l="$(head -n2 "$f" | tail -n1 | cut -d\" -f2)" - hunspell -u3 -H -d "$l" -p <(cat spelling/international.txt "spelling/$l.txt") "$f" | tee -a spelling.txt - fi -done - -if [[ -s spelling.txt ]]; then - printf "\nvvv Mispelled words detected by hunspell.\n\n" >&2 - sort < spelling.txt | uniq >&2 - printf "\n^^^\n" >&2 - exit 1 -else - echo "No words mispelled" >&2 -fi diff --git a/spelling/en.txt b/spelling/en.txt deleted file mode 100644 index bebfc76..0000000 --- a/spelling/en.txt +++ /dev/null @@ -1,39 +0,0 @@ -Patches -Rollout -Slides -aren -autocommit -backend -behaviour -couldn -cronjobs -curation -declaratively -decrypting -didn -doesn -duplications -embeddable -filesystem -filesystems -isn -maintainence -oday -portuguese -portuguse -pre -programmatically -realising -reimplementation -repo -reproducibility -scriptable -shouldn -symlinks -syncable -só -tradeoffs -untrusted -ve -wasn -wouldn diff --git a/spelling/fr.txt b/spelling/fr.txt deleted file mode 100644 index aa09184..0000000 --- a/spelling/fr.txt +++ /dev/null @@ -1,8 +0,0 @@ -' -AJA -dimanche -earned -oday -ppris -só -ujourd'hui diff --git a/spelling/international.txt b/spelling/international.txt deleted file mode 100644 index 3536249..0000000 --- a/spelling/international.txt +++ /dev/null @@ -1,142 +0,0 @@ -144p -1D -250GB -2D -2nix -32GB -500GB -81F90EC3CD356060 -8GB -André -Atom -B1 -BN -BSON -BY -BY-SA -Bitbucket -CI -CLI -Cantrill -Clojure -CouchDB -DVCS -Datomic -EuAndreh -F -FFI -FTS -Fastmail -GADTs -GPLv -GPLv3 -GTK -GitLab -Gmail -GuixSD -HN -HTTPS -Halloway -Haskell -IndexedDB -JS -JSON -Joyent -L1 -LaTeX -Lerna -LilyPond -LiquidHaskell -Mailutils -Matroska -Mentat -Merkle -NPM -Nextcloud -NixOS -POSIX -Pastebin -PouchDB -README -RSS -Raku -Reddit -SA -SSD -Sourcehut -Spacemacs -StackOverflow -Staltz -TAB -TBs -TOML -TypeScript -UI -URL -VPN -WebAssembly -Yandex -YouTube -Zig -boneco -brainer -buildGoModule -cargo2nix -carte -cgit -ci -clojure -datalog -datom -datoms -dl -edn -en -euandreh -eval -fr -gcrypt -gt -guix -guixbuild -h1 -h6 -hinarioespirita -html -i5 -i7 -ify -intbytes -ish -jekyll -jemoji -js -kramdown -libre -lockfile -lockfiles -lt -merkle -myrepos -nixos -no-brainer -node2nix -noinform -npm -org -pastebin -pastebins -plaintext -progn -pt -sbcl -songbooks -sourcehut -sr -swift2nix -systemd -touchpad -v8 -xyz -youtube -à diff --git a/spelling/pt.txt b/spelling/pt.txt deleted file mode 100644 index 2befc17..0000000 --- a/spelling/pt.txt +++ /dev/null @@ -1,126 +0,0 @@ -Abaixo -Agosto -Anna -Aprendi -Atualizado -Blog -Cópia -H -HEA -I -L -Lista -Me -Patches -Postado -Postagens -Quando -T -Usar -Visite -Website -achar -arquivo -artigos -buscar -chegar -comece -comentário -como -completar -conhecimentos -contatar -criar -código -da -dados -de -desta -diretamente -direto -discussão -discussões -distribuir -do -dobráveis -dou eu -e -earned -email -empacotá -encontra -engasgo -entrada -envelope -escreva -escrever -escrevo -esforço -estou -eu -existentes -extra -fazer -ficou -formatos -gerar -impressão -inglês -interessantes -internet -intervalos -jeito -las -licenciado -licença -log -los -mandar -mande -me -mensagem -na -navegador -no -nome -normalmente -novo -o -oday -oje -ordená -os -padrão -para -parar -pessoal -por -post -postagens -prendi -procurando -procure -produção -projetos -pública -público -relacionados -reler -religioso -se -significa -simples -sobre -tempo -texto -timestamp -transpor -u -usando -usar -versão -versões -vindas -Ícone -é -úteis diff --git a/tests.sh b/tests.sh new file mode 100755 index 0000000..46f1f0e --- /dev/null +++ b/tests.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" + +set -x + +./scripts/assert-spelling.sh +./scripts/assert-nixfmt.sh +./scripts/assert-shellcheck.sh +./scripts/assert-todos.sh + +./scripts/assert-content.sh diff --git a/utils-i18n.nix b/utils-i18n.nix new file mode 100644 index 0000000..379cd3b --- /dev/null +++ b/utils-i18n.nix @@ -0,0 +1,52 @@ +{ pkgs }: rec { + sphinx-intl = with pkgs.python3.pkgs; + buildPythonPackage rec { + pname = "sphinx-intl"; + version = "2.0.1"; + src = fetchPypi { + inherit pname version; + sha256 = "1d1q0sanjp4nkfvhsxi75zf3xjyyi8nzxvl3v7l0jy9ld70nwnmj"; + }; + propagatedBuildInputs = with pkgs.python3Packages; [ Babel click sphinx ]; + }; + dicts = rec { + mkDict = let + prefix = + "https://raw.githubusercontent.com/wooorm/dictionaries/61016e00e276f9bf5e52cbc6c02a45f2e49b2c7e/dictionaries"; + in { lang, dicSHA256, affSHA256 }: + let + dic = builtins.fetchurl { + url = "${prefix}/${lang}/index.dic"; + sha256 = dicSHA256; + }; + aff = builtins.fetchurl { + url = "${prefix}/${lang}/index.aff"; + sha256 = affSHA256; + }; + in pkgs.stdenv.mkDerivation { + name = "x-bindgen-dict-${lang}"; + builder = builtins.toFile "builder.sh" '' + source $stdenv/setup + install -dm755 $out/share/hunspell + install -m644 ${dic} $out/share/hunspell/${lang}.dic + install -m644 ${aff} $out/share/hunspell/${lang}.aff + runHook postInstall + ''; + }; + en = mkDict { + lang = "en"; + dicSHA256 = "1k4660ccwwpwac0rc7b8ih3vd24kxgvljkrakv2l1f72yfpw3bp2"; + affSHA256 = "0yvc2fhc03y0y1gwjyb20ifcrxnzm3ama1fri9r5gna092fz3qca"; + }; + pt = mkDict { + lang = "pt"; + dicSHA256 = "1z0kfxv8m361xhp4zwdlsn2ib8q3rnljj0b2s4482alyxpd00h9x"; + affSHA256 = "1ssj1g7qwh0lv3ajzvchwsfr7cgzrlqms28m1j3gm1y2avi50qhw"; + }; + fr = mkDict { + lang = "fr"; + dicSHA256 = "10p6jlk9j117mjd1z3dp3vfszcvxqha11kfvksqhvrq4ld9xwzbn"; + affSHA256 = "0d6k608h7gm1za3vdq1fhlwqzz2zxg1z0bx1bfvi0spg4a2mn09p"; + }; + }; +} diff --git a/utils.nix b/utils.nix deleted file mode 100644 index 5bcbb10..0000000 --- a/utils.nix +++ /dev/null @@ -1,105 +0,0 @@ -{ pkgs, src, baseName }: rec { - baseTask = pkgs.stdenv.mkDerivation { - name = "${baseName}-task"; - src = src; - buildInputs = [ ]; - phases = "unpackPhase buildPhase"; - buildPhase = '' - echo "ERROR: base task buildPhase not overriden." - exit 1 - ''; - }; - shellcheck = ignoredFindPattern: - baseTask.overrideAttrs (baseAttrs: rec { - name = "${baseAttrs.name}-shellcheck"; - buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ]; - ignoredPattern = - if ignoredFindPattern == null then "" else ignoredFindPattern; - buildPhase = '' - find . -type f \( -name '*.sh' -and -regextype egrep ! -regex '${ignoredPattern}' \) -print0 | xargs -0 shellcheck -x - touch $out - ''; - }); - formatNix = baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-nixfmt"; - buildInputs = baseAttrs.buildInputs ++ [ pkgs.nixfmt ]; - buildPhase = '' - format() { - nix_file="$1" - diff <(nixfmt < "$nix_file") "$nix_file" || { - echo "The $nix_file is unformatted. To fix it, run:" - echo " nixfmt $nix_file" - exit 1 - } - } - export -f format - find . -type f -name '*.nix' -print0 | xargs -0 -I{} bash -c "format {}" \; - touch $out - ''; - }); - fixme = ignoredFiles: - baseTask.overrideAttrs (baseAttrs: rec { - name = "${baseAttrs.name}-fixme"; - buildInputs = baseAttrs.buildInputs ++ [ pkgs.ag ]; - ignoredPattern = pkgs.lib.fold (a: b: " --ignore ${a} ${b}") "" - (if ignoredFiles == null then [ - "utils.nix" - "TODOs.org" - ] else - ignoredFiles); - buildPhase = '' - ag FIXME ${ignoredPattern} || { - touch $out - exit 0 - } - echo " Found dangling FIXME markers on the project." - echo " You should write them down properly on TODOs.org." - exit 1 - ''; - }); - readmeOrg = title: - baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-readme-docs"; - buildInputs = [ pkgs.pandoc ]; - buildPhase = '' - pandoc README.org -o $out --css docs/README.css --to=html5 --self-contained --metadata title="${title}" - ''; - }); - test = testDerivations: - baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-test"; - buildPhase = '' - echo "Ran tests for:" - for d in ${builtins.toString testDerivations}; do - echo " $d" - done - echo "All tests passed!" - touch $out - ''; - }); - shellEnvironmentBuild = shellBuildInputs: - baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-shell-build-inputs"; - buildPhase = '' - echo "Can build shell environment for shellBuildInputs!" - echo noop > $out - ''; - }); - shellEnvironment = shellBuildInputs: - pkgs.mkShell { - name = "${baseName}-shell"; - buildInputs = shellBuildInputs; - }; - overwritingPublishScript = { docsDerivation, overwrite ? true }: - pkgs.writeShellScriptBin "publish.sh" '' - set -euo pipefail - OUT_DOCS="${docsDerivation}" - ${ - if overwrite then "" else "# " - }${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no "$SERVER_URL" rm -rf "$DOCS_SERVER_PATH/*" - ${pkgs.rsync}/bin/rsync -avzP \ - --rsh="ssh -o StrictHostKeyChecking=no" \ - "$OUT_DOCS/" \ - "$SERVER_URL:$DOCS_SERVER_PATH" - ''; -} -- cgit v1.2.3