|  | 
|  | 1 | +name: Run Yarn Deduplicate on PR Command | 
|  | 2 | + | 
|  | 3 | +on: | 
|  | 4 | +  issue_comment: | 
|  | 5 | +    types: [created] | 
|  | 6 | + | 
|  | 7 | +jobs: | 
|  | 8 | +  run-yarn-deduplicate: | 
|  | 9 | +    if: ${{ github.event.issue.pull_request && github.event.comment.author_association == 'OWNER' && (github.event.comment.body == '/deduplicate' || github.event.comment.body == '/deduplicate fewer') }} | 
|  | 10 | +    runs-on: ubuntu-latest | 
|  | 11 | +    env: | 
|  | 12 | +      STRATEGY: ${{ contains(github.event.comment.body, 'fewer') && 'fewer' || 'highest' }} | 
|  | 13 | + | 
|  | 14 | +    steps: | 
|  | 15 | +      - name: Acknowlegde command and get ref | 
|  | 16 | +        uses: actions/github-script@v7 | 
|  | 17 | +        id: github-script | 
|  | 18 | +        with: | 
|  | 19 | +          script: | | 
|  | 20 | +            github.rest.issues.createComment({ | 
|  | 21 | +              issue_number: context.issue.number, | 
|  | 22 | +              owner: context.repo.owner, | 
|  | 23 | +              repo: context.repo.repo, | 
|  | 24 | +              body: 'Ok, trying to deduplicate using strategy `${{ env.STRATEGY }}`' | 
|  | 25 | +            }) | 
|  | 26 | +            return (await github.rest.pulls.get({ | 
|  | 27 | +              owner: context.repo.owner, | 
|  | 28 | +              repo: context.repo.repo, | 
|  | 29 | +              pull_number: context.issue.number | 
|  | 30 | +            })).data.head.ref | 
|  | 31 | +
 | 
|  | 32 | +      - name: Check out the repository | 
|  | 33 | +        uses: actions/checkout@v4 | 
|  | 34 | +        with: | 
|  | 35 | +          ref: ${{ fromJson(steps.github-script.outputs.result) }} | 
|  | 36 | + | 
|  | 37 | +      - name: 'Prepare workflow' | 
|  | 38 | +        uses: ./.github/actions/prepare | 
|  | 39 | + | 
|  | 40 | +      - name: Run yarn-deduplicate | 
|  | 41 | +        env: | 
|  | 42 | +          ARGS: ${{ contains(github.event.comment.body, 'fewer') && '--exclude @types/unist' || '' }} | 
|  | 43 | +        run: | | 
|  | 44 | +          yarn global add yarn-deduplicate | 
|  | 45 | +          yarn-deduplicate --strategy $STRATEGY $ARGS | 
|  | 46 | +          yarn | 
|  | 47 | +
 | 
|  | 48 | +      - name: Commit changes | 
|  | 49 | +        run: | | 
|  | 50 | +          git config --global user.name "github-actions[bot]" | 
|  | 51 | +          git config --global user.email "github-actions[bot]@users.noreply.github.com" | 
|  | 52 | +          git add yarn.lock | 
|  | 53 | +          git commit -m "chore(deps): Deduplicated dependencies using yarn-deduplicate" | 
|  | 54 | +
 | 
|  | 55 | +      - name: Push changes | 
|  | 56 | +        uses: ad-m/github-push-action@master | 
|  | 57 | +        with: | 
|  | 58 | +          github_token: ${{ secrets.PAT }} | 
|  | 59 | +          branch: ${{ fromJson(steps.github-script.outputs.result) }} | 
|  | 60 | + | 
|  | 61 | +      - name: Notify of failure | 
|  | 62 | +        uses: actions/github-script@v7 | 
|  | 63 | +        with: | 
|  | 64 | +          script: | | 
|  | 65 | +            github.rest.issues.createComment({ | 
|  | 66 | +              issue_number: context.issue.number, | 
|  | 67 | +              owner: context.repo.owner, | 
|  | 68 | +              repo: context.repo.repo, | 
|  | 69 | +              body: 'I failed :(' | 
|  | 70 | +            }) | 
|  | 71 | +        if: failure() | 
0 commit comments