Skip to content

Commit

Permalink
Merge pull request #77 from taku0/add_linter
Browse files Browse the repository at this point in the history
Add GitHub Actions for tests and linters
  • Loading branch information
gregghz authored Jan 23, 2023
2 parents ddb3e58 + 8fbc1a9 commit fddd747
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
((emacs-lisp-mode . ((package-lint-main-file . "kotlin-mode.el")
(eval . (checkdoc-minor-mode))
(indent-tabs-mode . nil)
(fill-column . 80)
(tab-width . 8)
(sentence-end-double-space . t)
(emacs-lisp-docstring-fill-column . 75)
(elisp-lint-indent-specs . ((kotlin-mode--save-mark-and-excursion . 0))))))
27 changes: 27 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run Tests

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
build:
runs-on: ubuntu-latest
continue-on-error: ${{matrix.version == 'snapshot'}}

strategy:
matrix:
# Cask does't support Emacs 24.
version: ['25.1', '25.2', '25.3', '26.1', '26.2', '26.3', '27.1', '27.2', '28.1', '28.2', 'snapshot']

steps:
- uses: actions/checkout@v3
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.version }}
- name: Run linters
run: ./scripts/run_linter.sh
- name: Run tests
run: ./scripts/run_test.sh
3 changes: 2 additions & 1 deletion Cask
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
(development
(depends-on "ecukes")
(depends-on "ert-expectations")
(depends-on "ert-runner"))
(depends-on "ert-runner")
(depends-on "elisp-lint"))
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ clean:

test:
## Tests the package.
$(CASK) exec $(EMACS) --batch -q \
--eval "(add-to-list 'load-path \""$(shell readlink -f .)"\")" \
--eval "(add-to-list 'load-path \""$(shell readlink -f .)"/test\")" \
-f batch-byte-compile \
*.el
cask exec ert-runner -L . -L test
CASK="${CASK}" EMACS="${EMACS}" scripts/run_test.sh

test_in_docker:
## Tests the package in Docker.
CASK="${CASK}" EMACS="${EMACS}" scripts/run_test_in_docker.sh

lint:
## Run linters.
CASK="${CASK}" EMACS="${EMACS}" scripts/run_linter.sh

lint_in_docker:
## Run linters in Docker.
CASK="${CASK}" EMACS="${EMACS}" scripts/run_linter_in_docker.sh
4 changes: 0 additions & 4 deletions kotlin-mode-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
;; Copyright (C) 2019 taku0

;; Authors: taku0 (http://github.com/taku0)
;; Keywords: languages
;; Package-Requires: ((emacs "24.3"))
;; Version: 0.0.1
;; URL: https://github.com/Emacs-Kotlin-Mode-Maintainers/kotlin-mode

;; This file is not part of GNU Emacs.

Expand Down
2 changes: 0 additions & 2 deletions kotlin-mode-lexer.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

;; Author: Shodai Yokoyama ([email protected])
;; taku0 (http://github.com/taku0)
;; Keywords: languages
;; Package-Requires: ((emacs "24.3"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down
12 changes: 11 additions & 1 deletion kotlin-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,20 @@ START and END define region within current buffer."
(interactive)
(kotlin-do-and-repl-focus 'kotlin-send-buffer))

(defmacro kotlin-mode--save-mark-and-excursion (&rest body)
"Polyfill of `save-mark-and-excursion' for <25.1.
For argument BODY, see `save-mark-and-excursion'."
(declare (indent 0) (debug t))
(let ((save-mark-and-excursion (if (fboundp 'save-mark-and-excursion)
#'save-mark-and-excursion
#'save-excursion)))
(cons save-mark-and-excursion body)))

(defun kotlin-send-block ()
"Send block to Kotlin interpreter."
(interactive)
(save-mark-and-excursion
(kotlin-mode--save-mark-and-excursion
(mark-paragraph)
(kotlin-send-region (region-beginning) (region-end))))

Expand Down
18 changes: 18 additions & 0 deletions scripts/invoke_cask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# A little wrapper for Cask. Used in Makefile.
# If ${CASK} is executable, use it.
# Otherwise, download the Cask to .cask/cask if not exists, then execute it.

if command -v "${CASK}" > /dev/null
then
"${CASK}" "$@"
elif command -v .cask/cask/bin/cask > /dev/null
then
.cask/cask/bin/cask "$@"
else
mkdir -p .cask || exit 1
git clone --depth 1 https://github.com/cask/cask.git .cask/cask || exit 1
chmod a+x .cask/cask/bin/cask || exit 1
.cask/cask/bin/cask "$@"
fi
19 changes: 19 additions & 0 deletions scripts/run_linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# Run linter. Used in Makefile.

if ! [ -d ".cask/$(./scripts/invoke_cask.sh eval '(princ emacs-version)')/elpa/elisp-lint-"* ]
then
./scripts/invoke_cask.sh install || exit 1
fi

./scripts/invoke_cask.sh emacs --version || exit 1
rm -f *.elc test/*.elc || exit 1
rm -f *-autoloads.el || exit 1
./scripts/invoke_cask.sh emacs --batch -Q \
-l elisp-lint.el \
--eval '(setq elisp-lint--debug t)' \
-f elisp-lint-files-batch \
*.el || exit 1
rm -f *.elc test/*.elc || exit 1
rm -f *-autoloads.el || exit 1
21 changes: 21 additions & 0 deletions scripts/run_linter_in_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# Run linter in Docker. Used in Makefile.

# Cask does't support Emacs 24.
for version in 28 27 26 25 # 24
do
docker \
run \
--rm \
--volume="$(pwd)":/src \
--user="$(id -u):$(id -g)" \
--workdir="/src" \
--env=ELDEV_DIR=/src/.eldev \
--env=HOME=/tmp \
silex/emacs:${version} \
bash -c "/src/scripts/run_linter.sh" \
|| exit 1
done

echo "done"
16 changes: 16 additions & 0 deletions scripts/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# Run tests. Used in Makefile.

if ! [ -d ".cask/$(./scripts/invoke_cask.sh eval '(princ emacs-version)')/elpa/ert-runner-"* ]
then
./scripts/invoke_cask.sh install || exit 1
fi

./scripts/invoke_cask.sh emacs --version || exit 1
./scripts/invoke_cask.sh emacs --batch -q \
--eval "(add-to-list 'load-path \"$(readlink -f .)\")" \
--eval "(add-to-list 'load-path \"$(readlink -f .)/test\")" \
-f batch-byte-compile \
*.el test/*.el || exit 1
./scripts/invoke_cask.sh exec ert-runner -L . -L test
23 changes: 23 additions & 0 deletions scripts/run_test_in_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# Run tests in Docker. Used in Makefile.

# Cask does't support Emacs 24.
for version in 28 27 26 25 # 24
do
rm -f *.elc test/*.elc
rm -f *-autoloads.el
docker \
run \
--rm \
--volume="$(pwd)":/src \
--user="$(id -u):$(id -g)" \
--workdir="/src" \
--env=ELDEV_DIR=/src/.eldev \
--env=HOME=/tmp \
silex/emacs:${version} \
bash -c "/src/scripts/run_test.sh" \
|| exit 1
done

echo "done"

0 comments on commit fddd747

Please sign in to comment.