aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest/formatters/apheleia-ft.el39
-rwxr-xr-xtest/formatters/build-image.bash11
-rw-r--r--test/formatters/installers/prettier-ruby.bash6
3 files changed, 46 insertions, 10 deletions
diff --git a/test/formatters/apheleia-ft.el b/test/formatters/apheleia-ft.el
index b560441..77f8115 100755
--- a/test/formatters/apheleia-ft.el
+++ b/test/formatters/apheleia-ft.el
@@ -56,6 +56,39 @@ already in memory on the current branch."
(goto-char (point-min))
(read (current-buffer)))))
+(defun apheleia-ft--get-changed-files-for-pull-request ()
+ "Return list of files (relative to repo root) changed in this PR.
+This means added, removed, or changed compared to main."
+ (let ((stderr-file (make-temp-file "apheleia-ft-stderr-")))
+ (with-temp-buffer
+ (let ((exit-status
+ (call-process
+ "git" nil (list (current-buffer) stderr-file) nil
+ "diff" "--name-only" "origin/main...HEAD")))
+ (unless (zerop exit-status)
+ (with-temp-buffer
+ (insert-file-contents stderr-file)
+ (princ (buffer-string)))
+ (error
+ (concat
+ "Failed to 'git diff --name-only "
+ "origin/main...HEAD', got exit status %S")
+ exit-status)))
+ (split-string (buffer-string)))))
+
+(defun apheleia-ft--get-formatters-with-changed-scripts ()
+ "Return list of formatter symbols whose scripts were touched in this PR.
+This means their install scripts are different from how they
+appear on main. This may include formatters that were removed
+relative to main."
+ (save-match-data
+ (let ((formatters nil))
+ (dolist (file (apheleia-ft--get-changed-files-for-pull-request))
+ (when (string-match
+ "\\`test/formatters/installers/\\([^./]+\\)\\.bash\\'" file)
+ (push (intern (match-string 1 file)) formatters)))
+ formatters)))
+
(defun apheleia-ft--get-formatters-for-pull-request ()
"Return list of formatter string names that were touched in this PR.
This means their commands in `apheleia-formatters' are different
@@ -63,10 +96,13 @@ from how they appear on main, or they were added relative to
main."
(let ((old-formatters (apheleia-ft--get-formatters-from-ref "origin/main"))
(new-formatters apheleia-formatters)
+ (formatters-with-changed-scripts
+ (apheleia-ft--get-formatters-with-changed-scripts))
(touched-formatters nil))
(map-do
(lambda (formatter command)
- (unless (equal command (alist-get formatter old-formatters))
+ (unless (and (equal command (alist-get formatter old-formatters))
+ (not (memq formatter formatters-with-changed-scripts)))
(push (symbol-name formatter) touched-formatters)))
new-formatters)
touched-formatters))
@@ -273,6 +309,7 @@ environment variable, defaulting to all formatters."
out-temp-file)
((guard (stringp arg))
arg)
+ (`npx arg)
(_ (eval arg))))
command))
(setq command (delq 'npx command))
diff --git a/test/formatters/build-image.bash b/test/formatters/build-image.bash
index a118d12..3c3d461 100755
--- a/test/formatters/build-image.bash
+++ b/test/formatters/build-image.bash
@@ -17,6 +17,11 @@ if [[ "$OSTYPE" != darwin* ]] && [[ "$EUID" != 0 ]]; then
docker=(sudo -E "${docker[@]}")
fi
-exec "${docker[@]}" build . \
- -t "apheleia-formatters:${TAG:-latest}" \
- --build-arg "FORMATTERS=${FORMATTERS:-}"
+no_cache=()
+if [[ -n "${NO_CACHE:-}" ]]; then
+ no_cache=("--no-cache")
+fi
+
+exec "${docker[@]}" build . \
+ -t "apheleia-formatters:${TAG:-latest}" \
+ --build-arg "FORMATTERS=${FORMATTERS:-}" "${no_cache[@]}"
diff --git a/test/formatters/installers/prettier-ruby.bash b/test/formatters/installers/prettier-ruby.bash
index 611f5c6..0be3df0 100644
--- a/test/formatters/installers/prettier-ruby.bash
+++ b/test/formatters/installers/prettier-ruby.bash
@@ -4,12 +4,6 @@ apt-get install -y ruby ruby-dev gcc
# Install the plugin
npm install -g prettier @prettier/plugin-ruby
-# Have to install from source because release not tagged yet
-# https://github.com/ruby-syntax-tree/syntax_tree-rbs/pull/34
-# https://stackoverflow.com/a/11767563
-gem install specific_install
-gem specific_install -l https://github.com/ruby-syntax-tree/syntax_tree-rbs.git
-
# These are required dependencies documented at
# https://www.npmjs.com/package/@prettier/plugin-ruby
gem install prettier_print syntax_tree syntax_tree-haml syntax_tree-rbs