diff --git a/.github/workflows/aws_auto_release.yml b/.github/workflows/aws_auto_release.yml index f536d63..5524e16 100644 --- a/.github/workflows/aws_auto_release.yml +++ b/.github/workflows/aws_auto_release.yml @@ -155,7 +155,7 @@ jobs: if: steps.auth_check.outputs.is_authorized == 'true' && steps.check.outputs.should_release == 'true' uses: actions/setup-node@v4 with: - node-version: 20.10 + node-version: ${{ vars.node_version }} - name: Calculate new version with cumulative bumps if: steps.auth_check.outputs.is_authorized == 'true' && steps.check.outputs.should_release == 'true' diff --git a/.github/workflows/aws_dev_release.yml b/.github/workflows/aws_dev_release.yml index 602a41e..520d06e 100644 --- a/.github/workflows/aws_dev_release.yml +++ b/.github/workflows/aws_dev_release.yml @@ -45,22 +45,39 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: 20.10 + node-version: ${{ vars.node_version }} cache: 'npm' - run: npm i - - run: CI=false npm run build - + - name: Build + run: | + set +e + CI=false npm run build 2>&1 | tee /tmp/build.log + BUILD_EXIT=${PIPESTATUS[0]} + set -e + if [ $BUILD_EXIT -ne 0 ] || grep -q "npm ERR!" /tmp/build.log; then + echo "::error::Build failed" + exit 1 + fi + - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: platforms: arm64,amd64 - + + - name: Get role ARN + id: get_role + env: + ARN_JSON: ${{ secrets.AWS_ROLE_ARN }} + run: | + arn=$(echo "$ARN_JSON" | jq -r '.dev') + echo "::add-mask::$arn" + echo "arn=$arn" >> $GITHUB_OUTPUT - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: - role-to-assume: arn:aws:iam::368076259134:role/github-actions-role + role-to-assume: ${{ steps.get_role.outputs.arn }} aws-region: us-east-1 - + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 @@ -79,7 +96,7 @@ jobs: tags: | type=raw,value=${{ github.event.repository.name }} - + - name: Build and push multi-platform images to ECR uses: docker/build-push-action@v5 @@ -103,10 +120,18 @@ jobs: matrix: service: ${{ fromJson(needs.Build.outputs.service) }} steps: + - name: Get role ARN + id: get_role + env: + ARN_JSON: ${{ secrets.AWS_ROLE_ARN }} + run: | + arn=$(echo "$ARN_JSON" | jq -r '.dev') + echo "::add-mask::$arn" + echo "arn=$arn" >> $GITHUB_OUTPUT - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: - role-to-assume: arn:aws:iam::368076259134:role/github-actions-role + role-to-assume: ${{ steps.get_role.outputs.arn }} aws-region: us-east-1 - name: deploy diff --git a/.github/workflows/aws_prod_release.yml b/.github/workflows/aws_prod_release.yml index 664027e..9750314 100644 --- a/.github/workflows/aws_prod_release.yml +++ b/.github/workflows/aws_prod_release.yml @@ -46,25 +46,42 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: 20.10 + node-version: ${{ vars.node_version }} cache: 'npm' - run: git config --global user.email devops@topia.io - run: git config --global user.name Devops - run: npm version --no-git-tag-version ${{ github.event.release.tag_name }} - run: npm i - - run: CI=false npm run build - + - name: Build + run: | + set +e + CI=false npm run build 2>&1 | tee /tmp/build.log + BUILD_EXIT=${PIPESTATUS[0]} + set -e + if [ $BUILD_EXIT -ne 0 ] || grep -q "npm ERR!" /tmp/build.log; then + echo "::error::Build failed" + exit 1 + fi + - name: Set up QEMU uses: docker/setup-qemu-action@v3.0.0 with: platforms: arm64,amd64 - + + - name: Get role ARN + id: get_role + env: + ARN_JSON: ${{ secrets.AWS_ROLE_ARN }} + run: | + arn=$(echo "$ARN_JSON" | jq -r '.dev') + echo "::add-mask::$arn" + echo "arn=$arn" >> $GITHUB_OUTPUT - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: - role-to-assume: arn:aws:iam::368076259134:role/github-actions-role + role-to-assume: ${{ steps.get_role.outputs.arn }} aws-region: us-east-1 - + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 @@ -106,13 +123,21 @@ jobs: matrix: service: ${{ fromJson(needs.Build.outputs.service) }} steps: + - name: Get role ARN + id: get_role + env: + ARN_JSON: ${{ secrets.AWS_ROLE_ARN }} + run: | + arn=$(echo "$ARN_JSON" | jq -r '.prod') + echo "::add-mask::$arn" + echo "arn=$arn" >> $GITHUB_OUTPUT - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: - role-to-assume: arn:aws:iam::471112828260:role/github-actions-role + role-to-assume: ${{ steps.get_role.outputs.arn }} aws-region: us-east-1 - name: deploy run: | - aws ecs update-service --cluster ${{ env.ECS_Cluster }} --service topia-${{ env.ENV }}-${{ matrix.service }}0 --force-new-deployment - + aws ecs update-service --cluster ${{ env.ECS_Cluster }} --service topia-${{ env.ENV }}-${{ matrix.service }}0 --force-new-deployment + diff --git a/Dockerfile b/Dockerfile index dbb3959..1aeccbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=linux/arm64 node:20.10-alpine3.19 +FROM node:22-alpine WORKDIR /app ADD build ./build ADD package* ./ diff --git a/src/controllers/handleDropPiece.ts b/src/controllers/handleDropPiece.ts index d266053..00df6e1 100644 --- a/src/controllers/handleDropPiece.ts +++ b/src/controllers/handleDropPiece.ts @@ -98,8 +98,17 @@ export const handleDropPiece = async (req: Request, res: Response) => { const gameText = droppedAssets[0]; if (!shouldUpdateGame) { - if (gameText) await gameText.updateCustomTextAsset({}, text); - throw text; + if (gameText) { + await gameText.updateCustomTextAsset({}, text).catch((error) => + errorHandler({ + error, + functionName: "handleDropPiece", + message: "Error updating game text asset", + }), + ); + } + await keyAsset.updateDataObject({ turnCount: turnCount + 1 }); + return console.log("Drop piece invalid: ", text); } const promises = []; @@ -196,7 +205,16 @@ export const handleDropPiece = async (req: Request, res: Response) => { } promises.push(keyAsset.updateDataObject(updatedData, { analytics })); - if (gameText) promises.push(gameText.updateCustomTextAsset({}, text)); + if (gameText) + promises.push( + gameText.updateCustomTextAsset({}, text).catch((error) => + errorHandler({ + error, + functionName: "handleDropPiece", + message: "Error updating game text asset", + }), + ), + ); await Promise.all(promises); } catch (error) { diff --git a/src/controllers/handlePlayerSelection.ts b/src/controllers/handlePlayerSelection.ts index 6ced770..1c1352d 100644 --- a/src/controllers/handlePlayerSelection.ts +++ b/src/controllers/handlePlayerSelection.ts @@ -64,8 +64,17 @@ export const handlePlayerSelection = async (req: Request, res: Response) => { const playerText = droppedAssets.find((droppedAsset) => droppedAsset.uniqueName === `player${playerId}Text`); if (!shouldUpdateGame) { - if (gameText) gameText.updateCustomTextAsset({}, text); - throw text; + if (gameText) { + await gameText.updateCustomTextAsset({}, text).catch((error) => + errorHandler({ + error, + functionName: "handlePlayerSelection", + message: "Error updating game text asset", + }), + ); + } + await keyAsset.updateDataObject({ playerCount: playerCount + 1 }); + return console.log("Player selection invalid: ", text); } const promises = []; @@ -81,8 +90,26 @@ export const handlePlayerSelection = async (req: Request, res: Response) => { }, ), ); - if (playerText) promises.push(playerText.updateCustomTextAsset({}, username)); - if (gameText) promises.push(gameText.updateCustomTextAsset({}, text)); + if (playerText) + promises.push( + playerText.updateCustomTextAsset({}, username).catch((error) => + errorHandler({ + error, + functionName: "handlePlayerSelection", + message: "Error updating player text asset", + }), + ), + ); + if (gameText) + promises.push( + gameText.updateCustomTextAsset({}, text).catch((error) => + errorHandler({ + error, + functionName: "handlePlayerSelection", + message: "Error updating game text asset", + }), + ), + ); await Promise.all(promises); } catch (error) { await keyAsset.updateDataObject({ playerCount: playerCount + 1 });