Created
December 15, 2022 12:52
-
-
Save achisholm/2d1f1379792964c346d5db36a9b1d4b0 to your computer and use it in GitHub Desktop.
GitHub Action to post a list of deploy previews for modified web pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment