Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove no longer needed hack #130

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/formatters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout pull request
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # compare against main
- name: Fetch master
run: |
git fetch
Expand Down
39 changes: 38 additions & 1 deletion test/formatters/apheleia-ft.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,53 @@ 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
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))
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 8 additions & 3 deletions test/formatters/build-image.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
6 changes: 0 additions & 6 deletions test/formatters/installers/prettier-ruby.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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