How to return success within the same job?

On a repository have I set up a GitHub Action to create deployment previews of Pull requests.

Since some PRs may only change files within the .github folder, which itself has no impact on the deployment, would I like the action to simply skip the deployment and return a successful run instead.

I can’t use the paths-ignore setting for the action because of it being required for Pull request approval (I have branch-protection enabled and the action is a required check).

So what would be the easiest way?

My full workflow file.

name: Pull request Deploy preview

on:
  pull_request_target:
    types:
      - opened
      - reopened
      - synchronize

jobs:
  deploy-preview:
    name: Create Deploy-Preview
    runs-on: ubuntu-latest
    steps:
      - uses: peter-evans/find-comment@v2
        id: find-comment
        name: Find Comment
        with:
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: gh-pages-deploy
      - uses: peter-evans/create-or-update-comment@v2
        id: comment
        name: Create initial comment
        with:
          body: |-
            ## Deploy Preview
            
            Building preview of Pull request. Please wait...
          comment-id: ${{ steps.find-comment.outputs.comment-id }}
          issue-number: ${{ github.event.pull_request.number }}
          token: ${{ secrets.BOT }}
          edit-mode: replace
      - uses: actions/checkout@v3
        name: Checkout Code
        with:
          ref: refs/pull/${{ github.event.pull_request.number }}/merge
      - uses: actions/setup-python@v3
        name: Setup Python
        with:
          python-version: 3.7
      - name: Install depencencies
        run: |
          python -m pip install --upgrade pip setuptools
          python -m pip install -r requirements.txt
      - name: Build docs
        run: mkdocs build
      - uses: peaceiris/actions-gh-pages@v3
        name: Deploy pages
        with:
          personal_token: ${{ secrets.BOT }}
          publish_dir: ./site
          destination_dir: ./${{ github.repository }}/${{ github.event.pull_request.number }}
          external_repository: gh-pages-deploy/Deploy-Previews
          commit_message: 'Pushing deploy preview for Pull request ${{ github.repository }}#${{ github.event.pull_request.number }}'
      - name: Delay comment update by 30 seconds # Allows the Pages deploy to finish.
        run: sleep 30s
        shell: bash
      - uses: peter-evans/create-or-update-comment@v2
        name: Update comment.
        with:
          body: |-
            ## Deploy Preview
            
            Deploy-Preview complete!
            
            | Name   | Link                                                                                                               |
            | ------ | ------------------------------------------------------------------------------------------------------------------ |
            | Commit | ${{ github.event.pull_request.head.sha }}                                                                          |
            | Link   | https://gh-pages-deploy.github.io/Deploy-Previews/${{ github.repository }}/${{ github.event.pull_request.number }} |
            | Logs   | ${{ github.server_url }}/${{ github.repository }}/actions/run/${{ github.run_id }}                                 |
          comment-id: ${{ steps.comment.outputs.comment-id }}
          edit-mode: replace
          token: ${{ secrets.BOT }}
      - if: ${{ failure() }}
        uses: peter-evans/create-or-update-comment@v2
        name: Update comment.
        with:
          body: |-
            ## Deploy Preview
            
            Deploy-Preview failed!
            
            | Name   | Link                                                                                               |
            | ------ | -------------------------------------------------------------------------------------------------- |
            | Commit | ${{ github.event.pull_request.head.sha }}                                                          |
            | Logs   | ${{ github.server_url }}/${{ github.repository }}/actions/run/${{ github.run_id }}                 |
          comment-id: ${{ steps.comment.outputs.comment-id }}
          edit-mode: replace
          token: ${{ secrets.BOT }}

https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks

So if I read this correctly would it work like this?

deploy-preview.yml

name: Pull request Deploy preview

on:
  pull_request_target:
    type:
      - opened
      - reopened
      - synchronize
    paths-ignore:
      - '.github/**'
      - '!docs/**'
      - '*.md'
      - 'LICENSE'

jobs:
  deploy-preview:
    runs-on: ubuntu-latest
    steps:
      # All the deploy steps here...

deploy-preview-skip.yml

name: Pull request Deploy preview

on:
  pull_request_target:
    type:
      - opened
      - reopened
      - synchronize
    paths:
      - '.github/**'
      - '!docs/**'
      - '*.md'
      - 'LICENSE'

jobs:
  deploy-preview:
    runs-on: ubuntu-latest
    steps:
      - run: 'echo "Skipping Deploy preview..."'

Just want to make sure I understand the paths and paths-ignore syntax correctly.

looks about right

The syntaxes for paths: and paths-ignore: are identical

Ya that’s seems correct. I had to do something similar in on of my projects/repos. If you haven’t got it working let us know. I’m happy to take a look.