aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/.github/workflows/lint.yml
blob: c8d1b27162e3d7588aa1dcd9015139a9c95a78d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: UI Linter

on:
  workflow_run:
    workflows: ["UI Checker"]
    types:
      - completed
  workflow_dispatch:
    inputs:
      commit_message:
        description: "Commit Message"
        type: string
        required: false

jobs:
  check:
    if: |
      (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
      github.event_name == 'workflow_dispatch'
    runs-on: ubuntu-latest
    steps:
      - name: Check if it is a direct push
        id: check_push
        run: |
          if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
            if [[ "${{ github.event.workflow_run.event }}" == "pull_request" ]]; then
              echo "PR detected. Exiting."
              echo "is_pr=True" >> $GITHUB_OUTPUT
            else
              echo "Direct push or other event detected. Proceeding..."
              echo "is_pr=False" >> $GITHUB_OUTPUT
            fi
          else
            echo "Manual trigger detected. Proceeding..."
            echo "is_pr=False" >> $GITHUB_OUTPUT
          fi

      - name: Checkout repository
        if: steps.check_push.outputs.is_pr != 'True'
        uses: actions/checkout@v6
        with:
          show-progress: false
          persist-credentials: false

      - name: Install pnpm
        if: steps.check_push.outputs.is_pr != 'True'
        uses: pnpm/action-setup@v4
        with:
          version: 9
          run_install: true
          package_json_file: ui/package.json

      - name: Install Node.js
        if: steps.check_push.outputs.is_pr != 'True'
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: "pnpm"
          cache-dependency-path: ui/pnpm-lock.yaml

      - run: pnpm format
        working-directory: ui

      - run: pnpm lint:fix
        working-directory: ui

      - name: Commit changes
        id: commit_changes
        if: steps.check_push.outputs.is_pr != 'True'
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

          git add .

          if git diff-index --quiet HEAD --; then
            echo "No changes to commit"
          else
            commit_msg="${{ github.event.inputs.commit_message }}"
            if [ -z "$commit_msg" ]; then
              commit_msg="chore: Auto Templates Optimization"
            fi
            git commit -m "$commit_msg" -m "Triggered by ${{github.sha}}" -m "[skip changelog]"
            git pull origin $(git rev-parse --abbrev-ref HEAD) --unshallow --rebase
            echo "have_commits=True" >> $GITHUB_OUTPUT
          fi

      - name: Push changes
        if: steps.check_push.outputs.is_pr != 'True' && steps.commit_changes.outputs.have_commits == 'True' && github.repository_owner == 'MAA1999'
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: ${{ github.ref }}