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

Correct workflow .yml to add format check to block unformatted PRs #12

Open
vtjeng opened this issue May 24, 2020 · 4 comments
Open

Correct workflow .yml to add format check to block unformatted PRs #12

vtjeng opened this issue May 24, 2020 · 4 comments

Comments

@vtjeng
Copy link

vtjeng commented May 24, 2020

I'd like to add a check to ensure that JuliaFormatter has been run on PRs submitted to my repo so that contributors (mostly myself) can't merge code that isn't properly formatted.

@domluna
Copy link
Collaborator

domluna commented May 25, 2020

  1. the latest version is ideal, that example just shows how to pick a different version.
  2. it's the PR, that workflow checks the PR is formatted. The workflow file in JuliaFormatter.jl is a little different because it's checking the JuliaFormatter.jl repo itself so it's a bit more involved. That being said that workflow was created a while ago so it may be overkill at this point.

@vtjeng
Copy link
Author

vtjeng commented May 25, 2020

Thanks! I ended up implementing a modified version of the .yml that pins a different version so that I could ensure that the commands run on CI and locally (when users are trying to fix their issues) would be the same.

Here's the PR and a sample error message.

@domluna
Copy link
Collaborator

domluna commented Jun 1, 2020

@vtjeng the latest version of JuliaFormatter now returns a bool from format or format_file that is true if the files are already formatted correctly, false otherwise. This should makes this check easier.

@vtjeng
Copy link
Author

vtjeng commented Jun 1, 2020

Thanks! I like the check as written

      - name: 'Check that running `format` is a no-op.'
        run: |
          julia -e '
          out = Cmd(`git diff --name-only`) |> read |> String
          if out == ""
              exit(0)
          else
              @error "Some files did not meet the formatting guidelines. Run ./scripts/format.sh to fix."
              write(stdout, "\nFiles not meeting formatting guidelines:\n")
              write(stdout, out)
              write(stdout, "\nRun ./scripts/format.sh to fix.")
              exit(1)
          end'

because it helps users identify which files aren't formatted properly, but I'll make sure to use that in other scripts I'm writing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants