diff --git a/.github/workflows/formatters.yml b/.github/workflows/formatters.yml index b114eea2..4df38b69 100644 --- a/.github/workflows/formatters.yml +++ b/.github/workflows/formatters.yml @@ -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 diff --git a/test/formatters/apheleia-ft.el b/test/formatters/apheleia-ft.el index b560441b..77f8115e 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 a118d12b..3c3d4612 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 611f5c63..0be3df07 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