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

feat: add github actions #387

Closed
wants to merge 19 commits into from
Closed
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
99 changes: 99 additions & 0 deletions .github/workflows/aws-amplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Deploy Next.js to AWS Amplify
RaoHai marked this conversation as resolved.
Show resolved Hide resolved

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 }}
S3_BUCKET: ${{ vars.S3_BUCKET }}
NEXT_STANDALONE: "true"

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: Zip Build Folder
run: zip -r build.zip .next/standalone .next/static
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: |
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 }}"
source_url="s3://${{ env.S3_BUCKET }}/builds/${{ github.sha }}.zip"

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: |
cat deployment.json


21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
17 changes: 17 additions & 0 deletions amplify/.config/project-config.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
8 changes: 8 additions & 0 deletions amplify/README.md
Original file line number Diff line number Diff line change
@@ -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/.
27 changes: 27 additions & 0 deletions amplify/backend/backend-config.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
10 changes: 10 additions & 0 deletions amplify/backend/tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"Key": "user:Stack",
"Value": "{project-env}"
},
{
"Key": "user:Application",
"Value": "{project-name}"
}
]
1 change: 1 addition & 0 deletions amplify/backend/types/amplify-dependent-resources-ref.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type AmplifyDependentResourcesAttributes = {}
64 changes: 64 additions & 0 deletions amplify/cli.json
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions amplify/hooks/README.md
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions amplify/team-provider-info.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading