|
1 | 1 | name: Validate Folder Structure |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + pull_request_target: |
5 | 5 | branches: |
6 | 6 | - main |
7 | 7 |
|
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + pull-requests: write |
| 11 | + |
8 | 12 | concurrency: |
9 | | - group: folder-structure-${{ github.head_ref || github.run_id }} |
| 13 | + group: folder-structure-${{ github.event.pull_request.number || github.run_id }} |
10 | 14 | cancel-in-progress: true |
11 | 15 |
|
12 | 16 | jobs: |
13 | 17 | structure: |
14 | 18 | runs-on: ubuntu-latest |
15 | 19 | steps: |
16 | | - - name: Checkout repository |
| 20 | + - name: Checkout base repository |
17 | 21 | uses: actions/checkout@v4 |
18 | 22 | with: |
19 | 23 | fetch-depth: 0 |
20 | 24 |
|
| 25 | + - name: Cache validation script |
| 26 | + run: cp .github/scripts/validate-structure.js "$RUNNER_TEMP/validate-structure.js" |
| 27 | + |
| 28 | + - name: Fetch pull request head |
| 29 | + env: |
| 30 | + PR_REMOTE_URL: https://x-access-token:${{ github.token }}@github.com/${{ github.event.pull_request.head.repo.full_name }}.git |
| 31 | + PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} |
| 32 | + run: | |
| 33 | + git remote remove pr >/dev/null 2>&1 || true |
| 34 | + git remote add pr "$PR_REMOTE_URL" |
| 35 | + git fetch pr "$PR_HEAD_REF":pr-head --depth=1 |
| 36 | + git checkout pr-head |
| 37 | +
|
21 | 38 | - name: Use Node.js 18 |
22 | 39 | uses: actions/setup-node@v4 |
23 | 40 | with: |
24 | 41 | node-version: 18 |
25 | 42 |
|
26 | 43 | - name: Validate folder layout |
27 | | - run: node .github/scripts/validate-structure.js |
| 44 | + id: validate |
| 45 | + continue-on-error: true |
| 46 | + run: node "$RUNNER_TEMP/validate-structure.js" origin/${{ github.event.pull_request.base.ref }}...HEAD |
28 | 47 |
|
29 | 48 | - name: Close pull request on failure |
30 | | - if: ${{ failure() && github.event_name == 'pull_request' }} |
| 49 | + if: ${{ steps.validate.outcome == 'failure' }} |
31 | 50 | uses: actions/github-script@v6 |
32 | 51 | with: |
33 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + github-token: ${{ github.token }} |
34 | 53 | script: | |
35 | 54 | await github.rest.pulls.update({ |
36 | 55 | owner: context.repo.owner, |
37 | 56 | repo: context.repo.repo, |
38 | 57 | pull_number: context.payload.pull_request.number, |
39 | 58 | state: 'closed' |
40 | 59 | }); |
| 60 | +
|
| 61 | + - name: Mark job as failed if validation failed |
| 62 | + if: ${{ steps.validate.outcome == 'failure' }} |
| 63 | + run: exit 1 |
0 commit comments