diff --git a/.github/workflows/amplify-preview.yaml b/.github/workflows/amplify-preview.yaml index 5beb9ab..308e13e 100644 --- a/.github/workflows/amplify-preview.yaml +++ b/.github/workflows/amplify-preview.yaml @@ -12,10 +12,13 @@ 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 @@ -23,88 +26,7 @@ jobs: 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} - -
Preview details - - - **LAST_UPDATED_AT**: ${updatedAt} - - **JOB_ID**: ${jobId} - - **JOB_STATUS**: ${jobStatus} - - **COMMIT_ID**: ${commitId} - -
- `; - - 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" diff --git a/amplify.yml b/amplify.yml new file mode 100644 index 0000000..ab7d404 --- /dev/null +++ b/amplify.yml @@ -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/**/* \ No newline at end of file