|
| 1 | +name: Redirects Workflow |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: [main] |
| 5 | + types: [opened, synchronize, labeled] |
| 6 | +env: |
| 7 | + DIFF_DIRECTORIES: 'src/pages src/fragments' |
| 8 | +jobs: |
| 9 | + onPrOpen: |
| 10 | + name: Check if redirects are needed on PR opened |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.event.action == 'opened' |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v3 |
| 16 | + with: |
| 17 | + # Minimal depth 2 so we can checkout the commit before possible merge commit. |
| 18 | + fetch-depth: 2 |
| 19 | + - name: Get count of deleted files |
| 20 | + env: |
| 21 | + GITHUB_PULL_REQUEST_HEAD_SHA: ${{ github.pull_request.head.sha }} |
| 22 | + run: | |
| 23 | + git fetch origin main |
| 24 | + echo "DELETED_FILES_ON_OPENED=$(git diff --name-status --diff-filter=D origin/main -- ${{ env.DIFF_DIRECTORIES }} ${{ env.GITHUB_PULL_REQUEST_HEAD_SHA }} -- ${{ env.DIFF_DIRECTORIES }} | wc -l)" >> $GITHUB_ENV |
| 25 | + echo "Deleted file count: ${{ env.DELETED_FILES_ON_OPENED }}" |
| 26 | + - name: Fail status check if there are deleted files |
| 27 | + if: ${{ env.DELETED_FILES_ON_OPENED > 0 }} |
| 28 | + run: exit 1 |
| 29 | + onPrSync: |
| 30 | + name: Check if redirects are needed on PR sync |
| 31 | + runs-on: ubuntu-latest |
| 32 | + if: github.event.action == 'synchronize' |
| 33 | + steps: |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v3 |
| 36 | + with: |
| 37 | + # Minimal depth 2 so we can checkout the commit before possible merge commit. |
| 38 | + fetch-depth: 2 |
| 39 | + - name: Get count of deleted files from last sync |
| 40 | + env: |
| 41 | + GITHUB_EVENT_BEFORE: ${{ github.event.before }} |
| 42 | + GITHUB_EVENT_AFTER: ${{ github.event.after }} |
| 43 | + run: | |
| 44 | + git fetch origin ${{ github.event.before }} --depth=1 |
| 45 | + echo "DELETED_FILES_ON_SYNC=$(git diff --name-status --diff-filter=D ${{ env.GITHUB_EVENT_BEFORE}} -- ${{ env.DIFF_DIRECTORIES }} ${{ env.GITHUB_EVENT_AFTER }} -- ${{ env.DIFF_DIRECTORIES }} | wc -l)" >> $GITHUB_ENV |
| 46 | + echo "Deleted file count: ${{ env.DELETED_FILES_ON_SYNC }}" |
| 47 | + - name: Fail status check if there are deleted files |
| 48 | + if: ${{ env.DELETED_FILES_ON_SYNC > 0 }} |
| 49 | + run: exit 1 |
| 50 | + failStatusCheck: |
| 51 | + name: Fail status check if redirects have not been added |
| 52 | + runs-on: ubuntu-latest |
| 53 | + if: contains(github.event.pull_request.labels.*.name, 'redirects-needed') |
| 54 | + steps: |
| 55 | + - name: Exit with error |
| 56 | + run: exit 1 |
0 commit comments