From 1400ab8a77c6cec18e3988ab6e46b99337d1ec42 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Fri, 13 Sep 2024 16:57:36 +0800 Subject: [PATCH 01/19] feat: add github actions --- .github/workflows/aws-amplify.yml | 93 +++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/aws-amplify.yml diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml new file mode 100644 index 00000000..3197d796 --- /dev/null +++ b/.github/workflows/aws-amplify.yml @@ -0,0 +1,93 @@ +name: Deploy Next.js to AWS Amplify + +on: + pull_request: + branches: [ "main" ] + paths: + - .github/workflows/aws-amplify.yml + - client/** + - assistant/** + +env: + AWS_REGION: ${{ vars.AWS_REGION }} + NEXT_PUBLIC_API_DOMAIN: ${{ vars.NEXT_PUBLIC_API_DOMAIN }} + AMPLIFY_APP_ID: ${{ vars.AMPLIFY_APP_ID }} + +permissions: + id-token: write + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Cache node modules + uses: actions/cache@v2 + with: + path: client/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('client/**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Node ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::654654285942:role/Github-OIDC + audience: sts.amazonaws.com + aws-region: ${{ env.AWS_REGION }} + + - name: Configure Amplify CLI + run: npm install -g @aws-amplify/cli + + - name: Install Dependencies + run: npm install + working-directory: ./client # 仅在 ./client 目录下安装 Next.js 项目的依赖项 + + - name: Build Amplify App + run: npm run build + working-directory: ./client # 仅在 ./client 目录下构建 Next.js 应用程序 + + - name: Configure Amplify + run: amplify configure + + - name: Deploy to Amplify + run: | + aws amplify create-branch --stage PULL_REQUEST --app-id ${{ env.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} || true + echo "Checking for pending job on branch ${{ github.head_ref }}" + while true; do + jobs=$( + aws amplify list-jobs \ + --app-id ${{ env.AMPLIFY_APP_ID }} \ + --branch-name "${{ github.head_ref }}" \ + --output "json" --no-paginate + ) + pending_jobs=$(echo $jobs | jq '.jobSummaries | map(select(.status | IN("FAILED", "SUCCEED", "CANCELLED") | not))') + pending_job_count=$(echo $pending_jobs | jq 'length') + echo "Pending Jobs: $pending_job_count" + + if [ "$pending_job_count" -gt 0 ]; then + echo "$pending_job_count Pending Job(s) found on branch ${{ github.head_ref }}. Waiting..." + sleep 10 + else + echo "All Pending Jobs done... Proceeding" + break + fi + done + + echo "Starting Amplify Job" + aws amplify start-job \ + --app-id ${{ env.AMPLIFY_APP_ID }} \ + --branch-name ${{ github.head_ref }} \ + --job-type RELEASE \ No newline at end of file From 89cc5346d535de07e3a9ccf72bee7c1b3f1412a3 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Fri, 13 Sep 2024 17:36:08 +0800 Subject: [PATCH 02/19] feat: add github actions --- .github/workflows/aws-amplify.yml | 31 +-------- .gitignore | 21 ++++++ .vscode/settings.json | 11 +++- amplify/.config/project-config.json | 17 +++++ amplify/README.md | 8 +++ amplify/backend/backend-config.json | 27 ++++++++ .../amplifyhosting-template.json | 39 +++++++++++ amplify/backend/tags.json | 10 +++ .../amplify-dependent-resources-ref.d.ts | 1 + amplify/cli.json | 64 +++++++++++++++++++ amplify/hooks/README.md | 7 ++ amplify/team-provider-info.json | 23 +++++++ package.json | 1 + 13 files changed, 231 insertions(+), 29 deletions(-) create mode 100644 amplify/.config/project-config.json create mode 100644 amplify/README.md create mode 100644 amplify/backend/backend-config.json create mode 100644 amplify/backend/hosting/amplifyhosting/amplifyhosting-template.json create mode 100644 amplify/backend/tags.json create mode 100644 amplify/backend/types/amplify-dependent-resources-ref.d.ts create mode 100644 amplify/cli.json create mode 100644 amplify/hooks/README.md create mode 100644 amplify/team-provider-info.json diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 3197d796..16a821be 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -62,32 +62,7 @@ jobs: - name: Configure Amplify run: amplify configure - - name: Deploy to Amplify + - name: Deploy Built Artifacts to Amplify run: | - aws amplify create-branch --stage PULL_REQUEST --app-id ${{ env.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} || true - echo "Checking for pending job on branch ${{ github.head_ref }}" - while true; do - jobs=$( - aws amplify list-jobs \ - --app-id ${{ env.AMPLIFY_APP_ID }} \ - --branch-name "${{ github.head_ref }}" \ - --output "json" --no-paginate - ) - pending_jobs=$(echo $jobs | jq '.jobSummaries | map(select(.status | IN("FAILED", "SUCCEED", "CANCELLED") | not))') - pending_job_count=$(echo $pending_jobs | jq 'length') - echo "Pending Jobs: $pending_job_count" - - if [ "$pending_job_count" -gt 0 ]; then - echo "$pending_job_count Pending Job(s) found on branch ${{ github.head_ref }}. Waiting..." - sleep 10 - else - echo "All Pending Jobs done... Proceeding" - break - fi - done - - echo "Starting Amplify Job" - aws amplify start-job \ - --app-id ${{ env.AMPLIFY_APP_ID }} \ - --branch-name ${{ github.head_ref }} \ - --job-type RELEASE \ No newline at end of file + amplify publish --yes + working-directory: ./client \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5beaa9be..79e6b279 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,24 @@ next-env.d.ts dist/ lui/src/style.css +#amplify-do-not-edit-begin +amplify/\#current-cloud-backend +amplify/.config/local-* +amplify/logs +amplify/mock-data +amplify/mock-api-resources +amplify/backend/amplify-meta.json +amplify/backend/.temp +build/ +dist/ +node_modules/ +aws-exports.js +awsconfiguration.json +amplifyconfiguration.json +amplifyconfiguration.dart +amplify-build-config.json +amplify-gradle-config.json +amplifytools.xcconfig +.secret-* +**.sample +#amplify-do-not-edit-end diff --git a/.vscode/settings.json b/.vscode/settings.json index a04d963d..720dcd64 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,15 @@ { + "files.exclude": { + "amplify/.config": true, + "amplify/**/*-parameters.json": true, + "amplify/**/amplify.state": true, + "amplify/**/transform.conf.json": true, + "amplify/#current-cloud-backend": true, + "amplify/backend/amplify-meta.json": true, + "amplify/backend/awscloudformation": true + }, "prettier.configPath": "./client/.prettierrc.js", "python.analysis.extraPaths": [ "./server" ] -} +} \ No newline at end of file diff --git a/amplify/.config/project-config.json b/amplify/.config/project-config.json new file mode 100644 index 00000000..46849036 --- /dev/null +++ b/amplify/.config/project-config.json @@ -0,0 +1,17 @@ +{ + "projectName": "petercar", + "version": "3.1", + "frontend": "javascript", + "javascript": { + "framework": "react", + "config": { + "SourceDir": "client/src", + "DistributionDir": "client/.next", + "BuildCommand": "npm run-script build:client", + "StartCommand": "npm run-script start" + } + }, + "providers": [ + "awscloudformation" + ] +} \ No newline at end of file diff --git a/amplify/README.md b/amplify/README.md new file mode 100644 index 00000000..46165a9c --- /dev/null +++ b/amplify/README.md @@ -0,0 +1,8 @@ +# Getting Started with Amplify CLI +This directory was generated by [Amplify CLI](https://docs.amplify.aws/cli). + +Helpful resources: +- Amplify documentation: https://docs.amplify.aws. +- Amplify CLI documentation: https://docs.amplify.aws/cli. +- More details on this folder & generated files: https://docs.amplify.aws/cli/reference/files. +- Join Amplify's community: https://amplify.aws/community/. diff --git a/amplify/backend/backend-config.json b/amplify/backend/backend-config.json new file mode 100644 index 00000000..66082962 --- /dev/null +++ b/amplify/backend/backend-config.json @@ -0,0 +1,27 @@ +{ + "hosting": { + "amplifyhosting": { + "providerPlugin": "awscloudformation", + "service": "amplifyhosting", + "type": "manual" + } + }, + "parameters": { + "AMPLIFY_hosting_amplifyhosting_appId": { + "usedBy": [ + { + "category": "hosting", + "resourceName": "amplifyhosting" + } + ] + }, + "AMPLIFY_hosting_amplifyhosting_type": { + "usedBy": [ + { + "category": "hosting", + "resourceName": "amplifyhosting" + } + ] + } + } +} \ No newline at end of file diff --git a/amplify/backend/hosting/amplifyhosting/amplifyhosting-template.json b/amplify/backend/hosting/amplifyhosting/amplifyhosting-template.json new file mode 100644 index 00000000..eed188c1 --- /dev/null +++ b/amplify/backend/hosting/amplifyhosting/amplifyhosting-template.json @@ -0,0 +1,39 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"Amplify\",\"createdWith\":\"12.12.6\",\"stackType\":\"hosting-amplifyhosting\",\"metadata\":{}}", + "Parameters": { + "env": { + "Type": "String" + }, + "appId": { + "Type": "String" + }, + "type": { + "Type": "String" + } + }, + "Conditions": { + "isManual": { + "Fn::Equals": [ + { + "Ref": "type" + }, + "manual" + ] + } + }, + "Resources": { + "AmplifyBranch": { + "Condition": "isManual", + "Type": "AWS::Amplify::Branch", + "Properties": { + "BranchName": { + "Ref": "env" + }, + "AppId": { + "Ref": "appId" + } + } + } + } +} \ No newline at end of file diff --git a/amplify/backend/tags.json b/amplify/backend/tags.json new file mode 100644 index 00000000..b9321d71 --- /dev/null +++ b/amplify/backend/tags.json @@ -0,0 +1,10 @@ +[ + { + "Key": "user:Stack", + "Value": "{project-env}" + }, + { + "Key": "user:Application", + "Value": "{project-name}" + } +] \ No newline at end of file diff --git a/amplify/backend/types/amplify-dependent-resources-ref.d.ts b/amplify/backend/types/amplify-dependent-resources-ref.d.ts new file mode 100644 index 00000000..074b15bc --- /dev/null +++ b/amplify/backend/types/amplify-dependent-resources-ref.d.ts @@ -0,0 +1 @@ +export type AmplifyDependentResourcesAttributes = {} \ No newline at end of file diff --git a/amplify/cli.json b/amplify/cli.json new file mode 100644 index 00000000..bd63c719 --- /dev/null +++ b/amplify/cli.json @@ -0,0 +1,64 @@ +{ + "features": { + "graphqltransformer": { + "addmissingownerfields": true, + "improvepluralization": false, + "validatetypenamereservedwords": true, + "useexperimentalpipelinedtransformer": true, + "enableiterativegsiupdates": true, + "secondarykeyasgsi": true, + "skipoverridemutationinputtypes": true, + "transformerversion": 2, + "suppressschemamigrationprompt": true, + "securityenhancementnotification": false, + "showfieldauthnotification": false, + "usesubusernamefordefaultidentityclaim": true, + "usefieldnameforprimarykeyconnectionfield": false, + "enableautoindexquerynames": true, + "respectprimarykeyattributesonconnectionfield": true, + "shoulddeepmergedirectiveconfigdefaults": false, + "populateownerfieldforstaticgroupauth": true, + "subscriptionsinheritprimaryauth": false + }, + "frontend-ios": { + "enablexcodeintegration": true + }, + "auth": { + "enablecaseinsensitivity": true, + "useinclusiveterminology": true, + "breakcirculardependency": true, + "forcealiasattributes": false, + "useenabledmfas": true + }, + "codegen": { + "useappsyncmodelgenplugin": true, + "usedocsgeneratorplugin": true, + "usetypesgeneratorplugin": true, + "cleangeneratedmodelsdirectory": true, + "retaincasestyle": true, + "addtimestampfields": true, + "handlelistnullabilitytransparently": true, + "emitauthprovider": true, + "generateindexrules": true, + "enabledartnullsafety": true, + "generatemodelsforlazyloadandcustomselectionset": false + }, + "appsync": { + "generategraphqlpermissions": true + }, + "latestregionsupport": { + "pinpoint": 1, + "translate": 1, + "transcribe": 1, + "rekognition": 1, + "textract": 1, + "comprehend": 1 + }, + "project": { + "overrides": true + } + }, + "debug": { + "shareProjectConfig": true + } +} \ No newline at end of file diff --git a/amplify/hooks/README.md b/amplify/hooks/README.md new file mode 100644 index 00000000..8fb601ea --- /dev/null +++ b/amplify/hooks/README.md @@ -0,0 +1,7 @@ +# Command Hooks + +Command hooks can be used to run custom scripts upon Amplify CLI lifecycle events like pre-push, post-add-function, etc. + +To get started, add your script files based on the expected naming convention in this directory. + +Learn more about the script file naming convention, hook parameters, third party dependencies, and advanced configurations at https://docs.amplify.aws/cli/usage/command-hooks diff --git a/amplify/team-provider-info.json b/amplify/team-provider-info.json new file mode 100644 index 00000000..d3153a5f --- /dev/null +++ b/amplify/team-provider-info.json @@ -0,0 +1,23 @@ +{ + "dev": { + "awscloudformation": { + "AuthRoleName": "amplify-petercar-dev-3ff13-authRole", + "UnauthRoleArn": "arn:aws:iam::654654285942:role/amplify-petercar-dev-3ff13-unauthRole", + "AuthRoleArn": "arn:aws:iam::654654285942:role/amplify-petercar-dev-3ff13-authRole", + "Region": "ap-northeast-1", + "DeploymentBucketName": "amplify-petercar-dev-3ff13-deployment", + "UnauthRoleName": "amplify-petercar-dev-3ff13-unauthRole", + "StackName": "amplify-petercar-dev-3ff13", + "StackId": "arn:aws:cloudformation:ap-northeast-1:654654285942:stack/amplify-petercar-dev-3ff13/9ee156a0-71b2-11ef-8fc2-0a3f5177c90f", + "AmplifyAppId": "d1fj2j4bwhzjbr" + }, + "categories": { + "hosting": { + "amplifyhosting": { + "appId": "d1fj2j4bwhzjbr", + "type": "manual" + } + } + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 9fa1bbae..49e3c362 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "bootstrap": "cd client && yarn && cd ../assistant && yarn && cd ../server && bash setup_python.sh", "client": "cd client && yarn run dev", + "build:client": "cd client && yarn run build", "assistant": "cd assistant && yarn run dev", "server": "cd server && ./venv/bin/python3 -m uvicorn main:app --reload", "env:pull": "cd server && ./venv/bin/python3 scripts/envs.py pull", From 9cc54defc50a932e9fdd2942183b955e6b0e6471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 21:24:21 +0800 Subject: [PATCH 03/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 16a821be..c6f5baf0 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -60,7 +60,7 @@ jobs: working-directory: ./client # 仅在 ./client 目录下构建 Next.js 应用程序 - name: Configure Amplify - run: amplify configure + run: amplify init - name: Deploy Built Artifacts to Amplify run: | From e07c1ab172fb7acfb374232212bcd418b39b7713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 21:38:13 +0800 Subject: [PATCH 04/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index c6f5baf0..0d0db962 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -59,10 +59,12 @@ jobs: run: npm run build working-directory: ./client # 仅在 ./client 目录下构建 Next.js 应用程序 - - name: Configure Amplify - run: amplify init - - - name: Deploy Built Artifacts to Amplify - run: | - amplify publish --yes - working-directory: ./client \ No newline at end of file + - name: deploy PR preview + uses: yinlinchen/amplify-preview-actions@master + with: + branch_name: ${GITHUB_HEAD_REF} + amplify_command: deploy + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + AmplifyAppId: ${{ env.AMPLIFY_APP_ID }} + AWS_REGION: ${{ env.AWS_REGION }} \ No newline at end of file From 0e8b5b7f8537eb15b10c9980cc7a7d429b39500a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 21:51:16 +0800 Subject: [PATCH 05/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 0d0db962..9cd6fe2c 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -59,12 +59,15 @@ jobs: run: npm run build working-directory: ./client # 仅在 ./client 目录下构建 Next.js 应用程序 - - name: deploy PR preview - uses: yinlinchen/amplify-preview-actions@master + - name: Zip Build Folder + run: zip -r build.zip ./.next + working-directory: ./client + + - name: Deploy to Amplify + uses: luisgreen/amplify_deployment@main with: - branch_name: ${GITHUB_HEAD_REF} - amplify_command: deploy - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - AmplifyAppId: ${{ env.AMPLIFY_APP_ID }} - AWS_REGION: ${{ env.AWS_REGION }} \ No newline at end of file + appId: ${{ vars.AMPLIFY_APP_ID }} + branchName: ${GITHUB_HEAD_REF} + artifactPath: './build.zip' + region: ${{ env.AWS_REGION }} + working-directory: ./client \ No newline at end of file From fc1113246d85ad037be4b72fa458126c5e9f18b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 21:56:41 +0800 Subject: [PATCH 06/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 9cd6fe2c..94685dfd 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -68,6 +68,6 @@ jobs: with: appId: ${{ vars.AMPLIFY_APP_ID }} branchName: ${GITHUB_HEAD_REF} - artifactPath: './build.zip' + artifactPath: './client/build.zip' region: ${{ env.AWS_REGION }} - working-directory: ./client \ No newline at end of file + \ No newline at end of file From 099b6b2250bd8191ada26904ccef387ce7956c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 22:04:00 +0800 Subject: [PATCH 07/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 94685dfd..69c632c2 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -63,11 +63,11 @@ jobs: run: zip -r build.zip ./.next working-directory: ./client - - name: Deploy to Amplify - uses: luisgreen/amplify_deployment@main - with: - appId: ${{ vars.AMPLIFY_APP_ID }} - branchName: ${GITHUB_HEAD_REF} - artifactPath: './client/build.zip' - region: ${{ env.AWS_REGION }} + - name: Publish to Amplify + run: | + aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name main --output json > deployment.json + DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') + ZIP_FILE=./client/build.zip + aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name main --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE + aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name main --job-id $DEPLOYMENT_ID \ No newline at end of file From 4647a1692af3cc7f4f1a6a10680635e38ce318a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 22:15:20 +0800 Subject: [PATCH 08/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 69c632c2..8cf8f65e 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -65,9 +65,9 @@ jobs: - name: Publish to Amplify run: | - aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name main --output json > deployment.json + aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --output json > deployment.json DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') ZIP_FILE=./client/build.zip - aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name main --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE - aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name main --job-id $DEPLOYMENT_ID + aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE + aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --job-id $DEPLOYMENT_ID \ No newline at end of file From 5c2779e8b635f29f99093d5478363dc14b07ccbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 22:19:07 +0800 Subject: [PATCH 09/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 8cf8f65e..e8d493b4 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -65,9 +65,9 @@ jobs: - name: Publish to Amplify run: | - aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --output json > deployment.json + aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --output json > deployment.json DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') ZIP_FILE=./client/build.zip - aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE - aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --job-id $DEPLOYMENT_ID + aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE + aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --job-id $DEPLOYMENT_ID \ No newline at end of file From 22fd3aceb615e69bdf0a136ad514773609c442de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 22:25:40 +0800 Subject: [PATCH 10/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index e8d493b4..c00f76c3 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -65,9 +65,9 @@ jobs: - name: Publish to Amplify run: | - aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --output json > deployment.json + aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name dev --output json > deployment.json DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') ZIP_FILE=./client/build.zip - aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE - aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --job-id $DEPLOYMENT_ID + aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name dev --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE + aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name dev --job-id $DEPLOYMENT_ID \ No newline at end of file From c706ea8a4258a4e5125d8fa4ca876650c9756ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 23:07:19 +0800 Subject: [PATCH 11/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index c00f76c3..8cf8f65e 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -65,9 +65,9 @@ jobs: - name: Publish to Amplify run: | - aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name dev --output json > deployment.json + aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --output json > deployment.json DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') ZIP_FILE=./client/build.zip - aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name dev --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE - aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name dev --job-id $DEPLOYMENT_ID + aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE + aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --job-id $DEPLOYMENT_ID \ No newline at end of file From 09d274166f0e2cc07974b1edd87065748374d303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 23:10:46 +0800 Subject: [PATCH 12/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 8cf8f65e..ee8273c7 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -65,9 +65,9 @@ jobs: - name: Publish to Amplify run: | - aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --output json > deployment.json - DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') + aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ GITHUB_HEAD_REF }} --output json > deployment.json + DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') ZIP_FILE=./client/build.zip - aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE - aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${github_head_ref} --job-id $DEPLOYMENT_ID + aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ GITHUB_HEAD_REF }} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE + aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ GITHUB_HEAD_REF }} --job-id $DEPLOYMENT_ID \ No newline at end of file From bb8349730ed011f1cc3e05b52d99caa3a88123bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 23:14:22 +0800 Subject: [PATCH 13/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index ee8273c7..2ae6a02e 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -65,9 +65,9 @@ jobs: - name: Publish to Amplify run: | - aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ GITHUB_HEAD_REF }} --output json > deployment.json + aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --output json > deployment.json DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') ZIP_FILE=./client/build.zip - aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ GITHUB_HEAD_REF }} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE - aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ GITHUB_HEAD_REF }} --job-id $DEPLOYMENT_ID + aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE + aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --job-id $DEPLOYMENT_ID \ No newline at end of file From 115d6fb1005fba11e1ad98c1c2438fc5d41121c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 23:25:10 +0800 Subject: [PATCH 14/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 2ae6a02e..bdc3b53b 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -63,11 +63,30 @@ jobs: run: zip -r build.zip ./.next working-directory: ./client - - name: Publish to Amplify + - name: Check if branch exists in Amplify + id: check_branch run: | - aws amplify create-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --output json > deployment.json - DEPLOYMENT_ID=$(cat deployment.json | jq -r '.jobId') - ZIP_FILE=./client/build.zip - aws amplify upload-files --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --deployment-id $DEPLOYMENT_ID --source $ZIP_FILE - aws amplify start-deployment --app-id ${{ vars.AMPLIFY_APP_ID }} --branch-name ${{ github.head_ref }} --job-id $DEPLOYMENT_ID + branch_name="${{ github.head_ref }}" + app_id="${{ vars.AMPLIFY_APP_ID }} + + branch_exists=$(aws amplify list-branches --app-id $app_id --query "branches[?branchName=='$branch_name'].branchName" --output text) + + if [ -z "$branch_exists" ]; then + echo "Branch $branch_name does not exist. Creating branch..." + aws amplify create-branch --app-id $app_id --branch-name $branch_name + else + echo "Branch $branch_name already exists." + fi + + - name: Start Amplify deployment + run: | + branch_name="${{ github.head_ref }}" + app_id="${{ vars.AMPLIFY_APP_ID }} + + aws amplify start-deployment --app-id $app_id --branch-name $branch_name --output json > deployment.json + + - name: Output deployment details + run: | + cat deployment.json + \ No newline at end of file From 2c376a4c77bcea2b5a97ebc2e0d5c4fa64bd71c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 23:29:17 +0800 Subject: [PATCH 15/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index bdc3b53b..e676d708 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -67,7 +67,7 @@ jobs: id: check_branch run: | branch_name="${{ github.head_ref }}" - app_id="${{ vars.AMPLIFY_APP_ID }} + app_id="${{ vars.AMPLIFY_APP_ID }}" branch_exists=$(aws amplify list-branches --app-id $app_id --query "branches[?branchName=='$branch_name'].branchName" --output text) @@ -81,7 +81,7 @@ jobs: - name: Start Amplify deployment run: | branch_name="${{ github.head_ref }}" - app_id="${{ vars.AMPLIFY_APP_ID }} + app_id="${{ vars.AMPLIFY_APP_ID }}" aws amplify start-deployment --app-id $app_id --branch-name $branch_name --output json > deployment.json From 1a5d3c4bf9f1756200df4f39033be1150c7f9f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 23:34:56 +0800 Subject: [PATCH 16/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index e676d708..7af65de4 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -83,7 +83,7 @@ jobs: branch_name="${{ github.head_ref }}" app_id="${{ vars.AMPLIFY_APP_ID }}" - aws amplify start-deployment --app-id $app_id --branch-name $branch_name --output json > deployment.json + aws amplify start-deployment --app-id $app_id --branch-name $branch_name --file ./client/build.zip --output json > deployment.json - name: Output deployment details run: | From fc28a676b23de3ef506e50a88be57e29a8ca73f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Fri, 13 Sep 2024 23:40:37 +0800 Subject: [PATCH 17/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 7af65de4..10a0484b 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -12,6 +12,7 @@ env: AWS_REGION: ${{ vars.AWS_REGION }} NEXT_PUBLIC_API_DOMAIN: ${{ vars.NEXT_PUBLIC_API_DOMAIN }} AMPLIFY_APP_ID: ${{ vars.AMPLIFY_APP_ID }} + S3_BUCKET: ${{ vars.S3_BUCKET }} permissions: id-token: write @@ -63,6 +64,10 @@ jobs: run: zip -r build.zip ./.next working-directory: ./client + - name: Upload Build to S3 + run: | + aws s3 cp ./client/build.zip s3://${{ env.S3_BUCKET }}/builds/${{ github.sha }}.zip + - name: Check if branch exists in Amplify id: check_branch run: | @@ -82,8 +87,9 @@ jobs: run: | branch_name="${{ github.head_ref }}" app_id="${{ vars.AMPLIFY_APP_ID }}" + source_url="s3://${{ env.S3_BUCKET }}/builds/${{ github.sha }}.zip" - aws amplify start-deployment --app-id $app_id --branch-name $branch_name --file ./client/build.zip --output json > deployment.json + aws amplify start-deployment --app-id $app_id --branch-name $branch_name --source-url $source_url --output json > deployment.json - name: Output deployment details run: | From 2f563d36f314301dda8bfc068982ccf2cfdd2b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Sat, 14 Sep 2024 00:04:07 +0800 Subject: [PATCH 18/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 10a0484b..33b65ca9 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -13,6 +13,7 @@ env: NEXT_PUBLIC_API_DOMAIN: ${{ vars.NEXT_PUBLIC_API_DOMAIN }} AMPLIFY_APP_ID: ${{ vars.AMPLIFY_APP_ID }} S3_BUCKET: ${{ vars.S3_BUCKET }} + NEXT_STANDALONE: "true" permissions: id-token: write From 209d6edfc37a5e259f669e28046567a17f58c1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Sat, 14 Sep 2024 00:09:26 +0800 Subject: [PATCH 19/19] Update aws-amplify.yml --- .github/workflows/aws-amplify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws-amplify.yml b/.github/workflows/aws-amplify.yml index 33b65ca9..6c87c805 100644 --- a/.github/workflows/aws-amplify.yml +++ b/.github/workflows/aws-amplify.yml @@ -62,7 +62,7 @@ jobs: working-directory: ./client # 仅在 ./client 目录下构建 Next.js 应用程序 - name: Zip Build Folder - run: zip -r build.zip ./.next + run: zip -r build.zip .next/standalone .next/static working-directory: ./client - name: Upload Build to S3