Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Netlify Preview URL #32

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading