-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
chore(websites): Setup preview site workflows #18924
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c4a083c
feat: add new preview site workflows
devindford e2de3d3
feat: combine workflows, update spellcheck to ignore file
devindford 4c242bf
feat: make reusable workflow
devindford 904af25
chore: add new workflow file to spellcheck exclude
devindford 51b24e5
fix: update workflow pathing
devindford eda2588
feat: update so we can run the workflow for forks on approval with th…
devindford 610d353
fix: update excludes text for new file
devindford a671681
merge master into devin.ford/WEB-4186
devindford ab48faa
fix: yaml syntax
devindford 36c5fbf
fix: syntax
devindford 07578a1
fix: github yaml errors
devindford 0151918
fix: spelling
devindford 8577084
fix: file naming
devindford 22eb7cf
chore: remove sync from types
devindford df636b9
Update .github/workflows/build_preview_sites.yml
devindford 38d47af
feat: update workflows with artifacts, remove netlify files
devindford 2a47dd9
fix: clean up workflows
devindford 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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Deploy Vector Preview Sites | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Call Build Preview"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
deploy_vector_preview_site: | ||
uses: ./.github/workflows/create_preview_sites.yml | ||
with: | ||
APP_ID: "d1a7j77663uxsc" | ||
APP_NAME: "vector.dev" | ||
|
||
deploy_rust_doc_preview_site: | ||
uses: ./.github/workflows/create_preview_sites.yml | ||
with: | ||
APP_ID: "d1hoyoksbulg25" | ||
APP_NAME: "Rust Doc" | ||
|
||
deploy_vrl_playground_preview_site: | ||
uses: ./.github/workflows/create_preview_sites.yml | ||
with: | ||
APP_ID: "d2lr4eds605rpz" | ||
APP_NAME: "VRL Playground" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: Create Preview Sites | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
APP_ID: | ||
description: "App ID for the associated website" | ||
required: true | ||
type: string | ||
APP_NAME: | ||
description: "Application name for the comment" | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
create_preview_site: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
# Get the artifacts with the PR number and branch name | ||
- name: Download artifact | ||
uses: actions/github-script@v3.1.0 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{ github.event.workflow_run.id }}, | ||
}); | ||
const matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0]; | ||
const download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
fs.writeFileSync('${{ github.workspace }}/pr.zip', Buffer.from(download.data)); | ||
|
||
# Extract the info from the artifact and set variables | ||
- name: Extract PR info from artifact | ||
run: | | ||
unzip pr.zip -d pr | ||
BRANCH_NAME=$(cat ./pr/PR_INFO | grep 'Branch Name' | cut -d ':' -f 2 | xargs) | ||
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/\.]/-/g') | ||
echo "SANITIZED_BRANCH_NAME=$SANITIZED_BRANCH_NAME" >> $GITHUB_ENV | ||
|
||
# Kick off the job in amplify | ||
- name: Deploy Site | ||
env: | ||
REQUEST_TOKEN: ${{ secrets.REQUEST_TOKEN }} | ||
REQUEST_MESSAGE: ${{ secrets.REQUEST_MESSAGE }} | ||
ENDPOINT: ${{ secrets.BUILDER_ENDPOINT }} | ||
run: | | ||
HMAC_KEY=$(echo -n $REQUEST_MESSAGE | openssl dgst -sha256 -hmac "$REQUEST_TOKEN" -binary | od -An -tx1 | tr -d ' \n'; echo) | ||
SIGNATURE="sha256=$HMAC_KEY" | ||
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-H "X-Hub-Signature: $SIGNATURE" \ | ||
-d "{\"app_id\": \"$APP_ID\", \"branch_name\": \"$SANITIZED_BRANCH_NAME\"}" \ | ||
"$ENDPOINT") | ||
|
||
# check the response code and fail if not 200 | ||
if [ "$RESPONSE_CODE" != "200" ]; then | ||
echo "Request failed with response code $RESPONSE_CODE" | ||
exit 1 | ||
fi | ||
|
||
# Add preview link to comment if all 3 sites successfully start | ||
- name: Comment Preview Link | ||
if: success() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
uses: actions/github-script@v3 | ||
with: | ||
script: | | ||
const prInfo = fs.readFileSync('./pr/PR_INFO', 'utf8'); | ||
const prInfoLines = prInfo.split('\n'); | ||
const issueNumber = parseInt(prInfoLines[0].split(': ')[1]); | ||
|
||
await github.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue_number, | ||
body: `Your preview site for the **${APP_NAME}** will be ready in a few minutes, please allow time for it to build. \n \n Heres your preview link: \n [${APP_NAME} preview](https://${SANITIZED_BRANCH_NAME}.${APP_ID}.amplifyapp.com)` | ||
}); | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Call Build Preview | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened] | ||
|
||
jobs: | ||
approval_check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Echo approval | ||
run: | | ||
echo "Workflow has been allowed to run for PR ${{ github.event.number }}. Setting artifacts and then continuing workflow runs" | ||
|
||
# Save the PR number and branch name to an artifact for use in subsequent jobs | ||
- name: Save PR number and Branch name | ||
run: | | ||
mkdir -p ./pr | ||
echo "PR Number: ${{ github.event.number }}" > ./pr/PR_INFO | ||
echo "Branch Name: ${{ github.head_ref }}" >> ./pr/PR_INFO | ||
|
||
# Upload the artifact | ||
- name: Upload PR information artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: pr | ||
path: pr/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit that I might have used different files for these like:
Just to make extracting the info easier (no grep/sed'ing required).