From 2f4c97e035a683b75a672b48d7d0b18da8d72b89 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Sat, 25 May 2024 17:00:27 +0200 Subject: [PATCH] ci: add integration tests and break out other checks to separate workflow --- .github/workflows/checks.yml | 18 +++++ .github/workflows/integration_tests.yml | 4 +- flake.nix | 99 ++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/checks.yml diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 000000000..b70685e0d --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,18 @@ +name: "Codebase Checks" + +# This workflow runs various checks (type checking, code checks) +# to ensure that Neorg is not breaking. + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + integration-test: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v10 + - name: Run Checks + run: nix flake check diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 783c3ef87..3fbb0d60c 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -1,7 +1,7 @@ name: "Nix-based Integration Test" # This workflow attempts to install Neorg with a kickstart config on all major OSes. -# Uses Nix + devenv for convenience. +# Uses Nix for reproducability. on: push: @@ -22,4 +22,4 @@ jobs: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@v10 - name: Run Checks - run: nix flake check + run: nix run .#integration-test diff --git a/flake.nix b/flake.nix index 416e7edf1..12d416668 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,5 @@ # General TODOS: # - Extract into modules for better readability -# - Readd integration tests # - Add comments explaining the more terse parts of the flake. { description = "Flake for Neorg development and testing"; @@ -91,6 +90,104 @@ }; }; + packages.integration-test = let + kickstart-config = + pkgs.writeScript "kickstart.lua" + '' + -- Adapted from https://github.com/folke/lazy.nvim#-installation + + -- Install lazy.nvim + local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + if not (vim.uv or vim.loop).fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) + end + vim.opt.rtp:prepend(lazypath) + + -- Set up both the traditional leader (for keymaps) as well as the local leader (for norg files) + vim.g.mapleader = " " + vim.g.maplocalleader = "," + + require("lazy").setup({ + { + "rebelot/kanagawa.nvim", -- neorg needs a colorscheme with treesitter support + config = function() + vim.cmd.colorscheme("kanagawa") + end, + }, + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + opts = { + ensure_installed = { "c", "lua", "vim", "vimdoc", "query" }, + highlight = { enable = true }, + }, + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end, + }, + { + "vhyrro/luarocks.nvim", + priority = 1000, + config = true, + }, + { + "nvim-neorg/neorg", + dependencies = { "luarocks.nvim" }, + config = function() + require("neorg").setup { + load = { + ["core.defaults"] = {}, + ["core.concealer"] = {}, + ["core.dirman"] = { + config = { + workspaces = { + notes = "~/notes", + }, + default_workspace = "notes", + }, + }, + }, + } + + vim.cmd.e("success") + + vim.wo.foldlevel = 99 + vim.wo.conceallevel = 2 + end, + } + }) + ''; + in + pkgs.writeShellApplication { + name = "neorg-integration-test"; + + runtimeInputs = with pkgs; [neovim-unwrapped tree-sitter lua5_1 wget kickstart-config]; + + text = '' + export NVIM_APPNAME="nvim-neorg" + + echo "* Hello World!" > example.norg + + nvim --headless -u ${kickstart-config} example.norg -c wq + + rm example.norg + + if [ ! -f success ]; then + echo "Integration test failed!" + exit 1 + fi + + rm success + ''; + }; + devShells.default = pkgs.mkShell { name = "neorg devShell";