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

amplify-preview: use shared workflow #24

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
98 changes: 10 additions & 88 deletions .github/workflows/amplify-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,99 +12,21 @@ jobs:
runs-on: ubuntu-latest
environment: docs-amplify
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Checkout shared-workflow
uses: actions/checkout@v4
with:
repository: gravitational/shared-workflows
ref: taras/amplify-preview-job
sparse-checkout: |
.github/actions
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
with:
aws-region: us-west-2
role-to-assume: ${{ vars.IAM_ROLE }}

- name: Describe Amplify branch
id: get_amplify_branch
env:
AMPLIFY_APP_IDS: ${{ vars.AMPLIFY_APP_IDS}}
BRANCH_NAME: ${{ steps.extract_branch.outputs.branch }}
shell: bash
run: |
IFS=, app_id_array=($AMPLIFY_APP_IDS)
for app_id in "${app_id_array[@]}"; do
branch_info=$(aws amplify get-branch --app-id ${app_id} --branch-name ${BRANCH_NAME} --query 'branch')
if [ $? -eq 0 ]; then
echo "PREVIEW_URL=https://$(jq -r '.displayName' <<< "$branch_info").$app_id.amplifyapp.com" >> $GITHUB_OUTPUT
echo "CREATE_TIME=$(jq -r '.createTime' <<< "$branch_info")" >> $GITHUB_OUTPUT
echo "UPDATE_TIME=$(jq -r '.updateTime' <<< "$branch_info")" >> $GITHUB_OUTPUT
echo "JOB_ID=$(jq -r '.activeJobId' <<< "$branch_info")" >> $GITHUB_OUTPUT
echo "APP_ID=${app_id}" >> $GITHUB_OUTPUT
break
fi
done
- name: Describe Amplify Deployment
id: get_amplify_job
env:
APP_ID: ${{ steps.get_amplify_branch.outputs.APP_ID }}
JOB_ID: ${{ steps.get_amplify_branch.outputs.JOB_ID }}
BRANCH_NAME: ${{ steps.extract_branch.outputs.branch }}
shell: bash
continue-on-error: true
run: |
job_info=$(aws amplify get-job --app-id ${APP_ID} --branch-name ${BRANCH_NAME} --job-id ${JOB_ID} --query 'job.summary')
echo "JOB_STATUS=$(jq -r '.status' <<< "$job_info")" >> $GITHUB_OUTPUT
echo "COMMIT_ID=$(jq -r '.commitId' <<< "$job_info")" >> $GITHUB_OUTPUT
- uses: actions/github-script@v7
env:
PREVIEW_URL: ${{ steps.get_amplify_branch.outputs.PREVIEW_URL }}
UPDATE_TIME: ${{ steps.get_amplify_branch.outputs.UPDATE_TIME }}
JOB_ID: ${{ steps.get_amplify_branch.outputs.JOB_ID }}
JOB_STATUS: ${{ steps.get_amplify_job.outputs.JOB_STATUS }}
COMMIT_ID: ${{ steps.get_amplify_job.outputs.COMMIT_ID }}
- uses: ./.github/actions/amplify-preview
with:
script: |
const previewUrl = process.env.PREVIEW_URL;
const jobId = process.env.JOB_ID;
const jobStatus = process.env.JOB_STATUS || "unknown";
const updatedAt = process.env.UPDATE_TIME;
const commitId = process.env.COMMIT_ID;
const commentBody = `![🤖](https://a0.awsstatic.com/libra-css/images/site/fav/favicon.ico) Amplify preview here: ${previewUrl}
<details><summary>Preview details</summary>
- **LAST_UPDATED_AT**: ${updatedAt}
- **JOB_ID**: ${jobId}
- **JOB_STATUS**: ${jobStatus}
- **COMMIT_ID**: ${commitId}
</details>
`;
const prProps = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
};
const comments = (await github.rest.issues.listComments(prProps))?.data;
const existingComment = comments?.find((comment) =>
comment.user.login === "github-actions[bot]" && comment.body.includes("Amplify preview here"));
if (existingComment == null) {
console.log("Posting new comment ${existingComment.id}")
github.rest.issues.createComment({
...prProps,
body: commentBody,
})
} else {
console.log("Found existing comment ${existingComment.id}")
github.rest.issues.updateComment({
...prProps,
body: commentBody,
comment_id: existingComment.id,
})
}
app_ids: ${{ vars.AMPLIFY_APP_IDS }}
create_branches: "false"
23 changes: 23 additions & 0 deletions amplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 1
frontend:
phases:
preBuild:
commands:
- yarn
- echo "Setting up swap space..."
- sudo fallocate -l 40G /swapfile
- sudo chmod 600 /swapfile
- sudo mkswap /swapfile
- sudo swapon /swapfile
- sudo swapon -s
- echo "✅ Done setting up swap space!"
build:
commands:
- yarn build --out-dir build//docusaurus
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Loading