Skip to content

Instantly share code, notes, and snippets.

@achisholm
Created December 15, 2022 12:52
Show Gist options
  • Save achisholm/2d1f1379792964c346d5db36a9b1d4b0 to your computer and use it in GitHub Desktop.
Save achisholm/2d1f1379792964c346d5db36a9b1d4b0 to your computer and use it in GitHub Desktop.

Revisions

  1. achisholm created this gist Dec 15, 2022.
    26 changes: 26 additions & 0 deletions deploy-preview-links.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    name: Create Netlify deploy preview links
    on:
    pull_request:
    types:
    - opened
    paths:
    - 'dev/**/*.html'
    - 'dev/**/*.htm'
    jobs:
    create-deploy-preview-links:
    runs-on: ubuntu-latest
    steps:
    - name: Check out repository code
    uses: actions/checkout@v3
    with:
    fetch-depth: 0
    - name: Post a list of Netlify preview URLs to the raised pull request
    run: |
    # Build a list of changed HTML files in /dev & post a comment to the PR
    pr_number=$(echo $GITHUB_REF | cut -f3 -d/)
    for file in $(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -E "^dev.*\.html?$" | sed "s/^dev\///g")
    do
    echo "https://${GITHUB_HEAD_REF}--tlc-dev.netlify.app/$file"
    done | gh pr comment $pr_number --body-file -
    env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}