tamasfe / taplo

A TOML toolkit written in Rust
https://taplo.tamasfe.dev
MIT License
1.41k stars 111 forks source link

Github Action / running taplo in CI #470

Open jbergstroem opened 1 year ago

jbergstroem commented 1 year ago

It's easy enough to get taplo running in CI. Something like this should work (and version can be maintained with a regex in renovatebot):

  taplo:
    name: Taplo
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Taplo
        env:
          version: "0.8.1"
        run: |
          curl -Ls "https://github.com/tamasfe/taplo/releases/download/${{ env.version }}/taplo-full-linux-x86_64.gz" | \
          gzip -d > taplo && \
          chmod +x taplo && \
          sudo mv taplo /usr/local/bin/taplo
      - name: Run Taplo
        run: taplo validate --colors never --no-schema

..that said. The very helpful CLI output is very complicated to parse with a problem matcher.

One way to improve this could be to support a custom output template, similar to actionlint. Another approach could be to have a custom format specifically catering problem matchers (which also could serve as a way get improved editor support).

Edit: For people just arriving, the better approach to this problem is to check if GITHUB_ACTIONS is set to true in the environment and emit github actions-consumable output.

ia0 commented 1 year ago

Thanks for the suggestion!

I'm personally not convinced by sophisticated output (others may disagree). I just use Taplo in CI like this, i.e. by formatting then diffing using git (which has a nice unsophisticated output). (This is also related to #416 when CI as a use-case for Taplo was mentioned.)

That said, I'm not against this feature if someone is ready to design and implement it and someone else is ready to review it.

panekj commented 1 year ago

I think we could output https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message when GITHUB_CI is set (or whichever envvar GitHub used).

jbergstroem commented 1 year ago

Was just coming back to suggest that! Probably the best approach.

when GITHUB_CI is set (or whichever envvar GitHub used).

Thinking either GITHUB_ACTIONS on its own or together with CI? https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

panekj commented 1 year ago

Thinking either GITHUB_ACTIONS on its own

This should be sufficient.

uncenter commented 8 months ago

I'm not entirely sure what the goal of this issue was but I think it would be great if we could turn @jbergstroem's original YAML code into a proper action and publish it.

uncenter commented 8 months ago

I've adapted it into an action! https://github.com/uncenter/setup-taplo Tested and works on ubuntu-latest, macos-latest, and windows-latest runners.

panekj commented 2 months ago

I'm not entirely sure what the goal of this issue was

The goal is outlined in original post, support for GitHub specific features such as code annotations from CI run.

Taplo as GitHub action is tracked in #326