Test Haskell toolchain configuration documentation #23
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: cli | |
| on: | |
| pull_request: | |
| paths: | |
| - 'cli/**' | |
| - '.github/workflows/ormolu.yml' | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'cli/**' | |
| - '.github/workflows/ormolu.yml' | |
| issue_comment: | |
| types: [created] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| stack: | |
| name: ${{ matrix.os }} / stack test | |
| runs-on: ${{ matrix.os }} | |
| if: github.event_name != 'issue_comment' | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install system dependencies (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libpcre3-dev | |
| - name: Install system dependencies (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| brew install pcre | |
| - uses: freckle/stack-action@v5 | |
| with: | |
| working-directory: cli | |
| stack-build-arguments: --fast # i.e. disabling --pedantic | |
| hlint: | |
| name: HLint | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'issue_comment' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: haskell-actions/hlint-setup@v2 | |
| - uses: haskell-actions/hlint-run@v2 | |
| with: | |
| path: cli/ | |
| # mostly interested in seeing these when reviewing PRs | |
| fail-on: never | |
| ormolu: | |
| name: Ormolu (comment "apply ormolu" to fix) | |
| # Only run for PR comments when they contain "apply ormolu" | |
| if: | | |
| github.event_name != 'issue_comment' || | |
| ( github.event.issue.pull_request && | |
| contains(github.event.comment.body, 'apply ormolu') | |
| ) | |
| runs-on: ubuntu-latest | |
| steps: | |
| # we need an app token for pushing changes to retrigger CI | |
| - uses: actions/create-github-app-token@v2 | |
| id: app-token | |
| with: | |
| app-id: ${{ vars.ORMOLU_APP_ID }} | |
| private-key: ${{ secrets.ORMOLU_APP_PRIVATE_KEY }} | |
| - name: Setup git user info | |
| run: | | |
| app_name='${{ steps.app-token.outputs.app-slug }}[bot]' | |
| app_id="$(gh api "/users/$app_name" --jq .id)" | |
| app_email="${user_id}+${app_name}@users.noreply.github.com" | |
| git config --global user.name "$app_name" | |
| git config --global user.email "$app_email" | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| - name: Get PR branch (for comment trigger) | |
| if: github.event_name == 'issue_comment' | |
| id: pr-info | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.app-token.outputs.token }} | |
| script: | | |
| const pr = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.issue.number | |
| }); | |
| return pr.data.head.ref; | |
| - name: Add reaction to comment | |
| if: github.event_name == 'issue_comment' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ steps.app-token.outputs.token }} | |
| script: | | |
| await github.rest.reactions.createForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id, | |
| content: 'eyes' | |
| }); | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref || steps.comment-pr-info.outputs.head_ref }} | |
| token: ${{ steps.app-token.outputs.token }} | |
| - uses: haskell-actions/run-ormolu@v17 | |
| with: | |
| mode: ${{ github.event_name == 'issue_comment' && 'inplace' || 'check' }} | |
| pattern: | | |
| cli/**/*.hs | |
| - name: Commit and push changes (for comment trigger) | |
| if: github.event_name == 'issue_comment' | |
| run: | | |
| comment='Apply ormolu formatting | |
| Triggered by PR comment from `@${{ github.event.comment.user.login }}` | |
| ' | |
| if git diff --quiet; then | |
| echo "No formatting changes needed" | |
| else | |
| git commit -am "$comment" | |
| git push | |
| fi |