Skip to content

Commit

Permalink
Show Netlify Preview URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCode92 authored Jan 10, 2025
1 parent 28aacb2 commit 510ebe8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/build.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
- main
env:
BRANCH_NAME: ${{ github.ref_name }}
permissions:
pull-requests: write
jobs:
lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -68,6 +70,8 @@ jobs:
deploy:
runs-on: ubuntu-latest
needs: build
outputs:
NETLIFY_PREVIEW_URL: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }}
steps:
- name: Get build artifacts
uses: actions/download-artifact@v4
Expand All @@ -87,7 +91,15 @@ jobs:
--dir dist \
--site ${{ secrets.NETLIFY_SITE_ID }} \
--auth ${{ secrets.NETLIFY_API_TOKEN }} \
$prod_flag
$prod_flag \
--json \
> deploy_output.json
- name: Generate URL Preview
id: url_preview
if: ${{ env.BRANCH_NAME != 'main' }}
run: |
NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json)
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT"
report:
runs-on: ubuntu-latest
needs: [lint, build]
Expand All @@ -97,3 +109,22 @@ jobs:
run: |
echo "Something went wrong!"
echo "${{ toJson(github)}}"
preview_url:
runs-on: ubuntu-latest
needs: deploy
if: ${{ github.ref_name != 'main' }}
steps:
- name: Output URL
run: echo ${{ needs.deploy.outputs.NETLIFY_PREVIEW_URL }}
- name: Comment URL Preview on PR
uses: actions/github-script@v7
env:
NETLIFY_PREVIEW_URL: ${{ needs.deploy.outputs.NETLIFY_PREVIEW_URL }}
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🚀 Preview URL: ' + process.env.NETLIFY_PREVIEW_URL
})
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"gitlens.codeLens.recentChange.enabled": false,
"gitlens.codeLens.authors.enabled": false,
"material-icon-theme.files.associations": {
".tool-versions": "nodejs_alt"
".tool-versions": "nodejs_alt",
"_redirects": "netlify"
},
"material-icon-theme.folders.associations": {
"actions": "gh-workflows",
Expand Down
1 change: 1 addition & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200

0 comments on commit 510ebe8

Please sign in to comment.