-
-
Notifications
You must be signed in to change notification settings - Fork 442
[WIP] Workflow for Preview System #1931
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
840da5e
Adding preview with Vercel
lukdog 805be6c
Avoiding concurrent preview generation in order to keep cache safe
lukdog 71c6b2e
Goodbye Vercel! Hello Netlify
lukdog 045f62b
Filtering pr - building preview only on specific labels
lukdog 960dba9
Refining concurrency for preview workflow
lukdog 5dce1f5
Adding preview also for main branch
lukdog 98aebe1
Changing comment strategy
lukdog 2ba6146
Updating README file
lukdog 0a9536b
Update README.md
lukdog 11635c4
Using right cache also for preview
lukdog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
name: Preview Deployment | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, labeled] | ||
|
||
concurrency: | ||
group: netlify-${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
run: | ||
if: contains(github.event.pull_request.labels.*.name, 'preview') || ${{ github.ref_name == 'main' }} | ||
runs-on: ubuntu-latest | ||
concurrency: | ||
group: netlify | ||
cancel-in-progress: false | ||
env: | ||
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} | ||
APP_ENV: prod | ||
BRANCH_NAME: ${{ github.ref_name }} | ||
|
||
steps: | ||
|
||
- name: Find PR Preview Comment | ||
if: github.event_name == 'pull_request' | ||
uses: peter-evans/find-comment@v1 | ||
id: deploy-preview-comment | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: "github-actions[bot]" | ||
body-includes: "Preview Deployment" | ||
|
||
- name: Update Comment if exists | ||
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0 | ||
uses: peter-evans/[email protected] | ||
with: | ||
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} | ||
edit-mode: replace | ||
body: | | ||
## Preview Deployment | ||
Waiting for deployment to complete... | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: "npm" | ||
cache-dependency-path: "**/package-lock.json" | ||
|
||
- name: Render Datasheets | ||
run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh | ||
|
||
- name: Copy Static Files | ||
run: | | ||
mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts | ||
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \; | ||
find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \; | ||
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \; | ||
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \; | ||
|
||
- name: Gatsby main cache | ||
uses: actions/cache@v4 | ||
id: gatsby-cache-folder | ||
with: | ||
path: .cache | ||
key: ${{ runner.os }}-cache-gatsbyV2-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-cache-gatsbyV2- | ||
|
||
- name: Gatsby Public Folder | ||
uses: actions/cache@v4 | ||
id: gatsby-public-folder | ||
with: | ||
path: public/ | ||
key: ${{ runner.os }}-public-gatsbyV2-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-public-gatsbyV2- | ||
|
||
- run: npm install | ||
- run: npm run build | ||
|
||
- name: Install Netlify | ||
run: npm install [email protected] -g | ||
|
||
- name: Deploy to Netlify Preview | ||
if: github.event_name == 'pull_request' | ||
run: | | ||
netlify deploy \ | ||
--dir public \ | ||
--site ${{ secrets.NETLIFY_SITE_ID }} \ | ||
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ | ||
--json \ | ||
> deploy_output.json | ||
|
||
- name: Deploy to Netlify Prod | ||
if: github.event_name != 'pull_request' | ||
run: | | ||
netlify deploy \ | ||
--prod \ | ||
--dir public \ | ||
--site ${{ secrets.NETLIFY_SITE_ID }} \ | ||
--auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ | ||
--json \ | ||
> deploy_output.json | ||
|
||
- name: Generate URL Preview | ||
if: github.event_name == 'pull_request' | ||
id: url_preview | ||
run: | | ||
NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json) | ||
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Create PR Preview Comment | ||
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id == 0 | ||
uses: peter-evans/[email protected] | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
## Preview Deployment | ||
🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }} | ||
📍 Commit SHA: ${{ github.sha }} | ||
|
||
- name: Update PR Preview Comment | ||
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0 | ||
uses: peter-evans/[email protected] | ||
with: | ||
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} | ||
edit-mode: replace | ||
body: | | ||
## Preview Deployment | ||
🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }} | ||
📍 Commit SHA: ${{ github.sha }} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.