diff --git a/.github/workflows/frontend_deploy.yml b/.github/workflows/frontend_deploy.yml index 291089e..827a432 100644 --- a/.github/workflows/frontend_deploy.yml +++ b/.github/workflows/frontend_deploy.yml @@ -10,62 +10,89 @@ permissions: contents: read jobs: - # test: - # name: "Frontend Tests" - # environment: prod - # runs-on: ubuntu-latest - # steps: - # - name: Checkout - # uses: actions/checkout@v4 + test-e2e: + name: "Frontend E2E Tests" + environment: prod + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: "20" + working-directory: knowx + + - name: Install Dependencies + run: npm install + working-directory: knowx + + - name: Make envfile + uses: SpicyPizza/create-envfile@v2.0 + with: + envkey_API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }} + envkey_DB_URL: ${{ secrets.DB_URL }} + envkey_NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} + envkey_NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} + envkey_GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }} + envkey_GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }} + envkey_GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} + envkey_GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} + envkey_EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }} + envkey_EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }} + envkey_EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }} + envkey_EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }} + envkey_EMAIL_FROM: ${{ secrets.EMAIL_FROM }} + envkey_SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} + directory: knowx + + - name: Run Tests + uses: cypress-io/github-action@v6 + with: + build: npm run build + start: npm start + working-directory: knowx - # - name: Install Node - # uses: actions/setup-node@v4 - # with: - # node-version: '20' - # working-directory: knowx + - name: Send Deploy Failure Message + if: failure() + run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿ’ฅ Front Testing Failed" + + - name: Send Deploy Success Message + if: success() + run: | + curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿงช Front Testing Successful" - # - name: Install Dependencies - # run: npm install - # working-directory: knowx + unit-tests: + name: "Frontend Unit Tests" + runs-on: ubuntu-latest + defaults: + run: + working-directory: knowx + steps: + - name: Checkout + uses: actions/checkout@v4 - # - name: Make envfile - # uses: SpicyPizza/create-envfile@v2.0 - # with: - # envkey_API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }} - # envkey_DB_URL: ${{ secrets.DB_URL }} - # envkey_NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} - # envkey_NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} - # envkey_GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }} - # envkey_GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }} - # envkey_GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - # envkey_GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - # envkey_EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }} - # envkey_EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }} - # envkey_EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }} - # envkey_EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }} - # envkey_EMAIL_FROM: ${{ secrets.EMAIL_FROM }} - # envkey_SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} - # directory: knowx + - name: Node setup + uses: actions/setup-node@v4 + with: + node-version: 20 - # - name: Run Tests - # uses: cypress-io/github-action@v6 - # with: - # build: npm run build - # start: npm start - # working-directory: knowx + - name: install dependencies + run: npm install - # - name: Send Deploy Failure Message - # if: failure() - # run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿ’ฅ Front Testing Failed" + - name: run tests + run: npm run test:ci - # - name: Send Deploy Success Message - # if: success() - # run: | - # curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿงช Front Testing Successful" + # - name: Upload coverage reports to Codecov + # uses: codecov/codecov-action@v4.0.1 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # fail_ci_if_error: true - deploy: - # needs: test - name: "Deploy to AWS" + deploy-dev: + needs: test-e2e + name: "Deploy to AWS - DEV" environment: dev runs-on: ubuntu-latest steps: @@ -145,223 +172,92 @@ jobs: - name: Send Deploy Success Message if: success() run: | - curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=โœ… Frontend Deploy Successful" + curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=โœ… Frontend DEV Deploy Successful" url=${{ steps.extract_url.outputs.url }} - curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿš€ Deployment URL: $url" - - # dev_deploy: - # # needs: test - # name: "Deploy to AWS - DEV" - # environment: dev - # runs-on: ubuntu-latest - # steps: - # - name: Checkout - # uses: actions/checkout@v4 - - # - name: Cofigure AWS - # uses: aws-actions/configure-aws-credentials@v4 - # with: - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # role-duration-seconds: 1200 - # aws-region: us-east-1 - - # # - name: Caller Identity - # # run: aws sts get-caller-identity - - # # - name: Setup AWS - # # run: | - # # sudo mkdir ~/.aws - # # sudo chmod 777 ~/.aws - # # sudo printf "[default]\nregion = us-east-1" > ~/.aws/config.txt - # # sudo printf "[default]\naws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }}\naws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}" > ~/.aws/credentials.txt - - # - name: Install SST - # run: | - # wget https://github.com/sst/ion/releases/download/v0.0./sst-linux-amd64.deb - # sudo dpkg -i sst-linux-amd64.deb - # sst version - # working-directory: knowx - - # - name: Check secrets - # run: | - # echo $API_ROOT_ROUTE >> secrets.txt - # echo $DB_URL >> secrets.txt - # echo $NEXTAUTH_URL >> secrets.txt - # echo $NEXTAUTH_SECRET >> secrets.txt - # echo $GITHUB_ID >> secrets.txt - # echo $GITHUB_SECRET >> secrets.txt - # echo $GOOGLE_CLIENT_ID >> secrets.txt - # echo $GOOGLE_CLIENT_SECRET >> secrets.txt - # echo $EMAIL_SERVER_HOST >> secrets.txt - # echo $EMAIL_SERVER_PORT >> secrets.txt - # echo $EMAIL_SERVER_USER >> secrets.txt - # echo $EMAIL_SERVER_PASSWORD >> secrets.txt - # echo $EMAIL_FROM >> secrets.txt - # echo $SENDGRID_API_KEY >> secrets.txt - # env: - # API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }} - # DB_URL: ${{ secrets.DB_URL }} - # NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} - # NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} - # GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }} - # GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }} - # GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - # GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - # EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }} - # EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }} - # EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }} - # EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }} - # EMAIL_FROM: ${{ secrets.EMAIL_FROM }} - # SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} - - # - name: Copy Secrets - # run: | - # sst secret set APIRootRoute $API_ROOT_ROUTE --stage dev - # sst secret set DBUrl $DB_URL --stage dev - # sst secret set NextAuthUrl $NEXTAUTH_URL --stage dev - # sst secret set NextAuthSecret $NEXTAUTH_SECRET --stage dev - # sst secret set GithubId $GITHUB_ID --stage dev - # sst secret set GithubSecret $GITHUB_SECRET --stage dev - # sst secret set GoogleClientId $GOOGLE_CLIENT_ID --stage dev - # sst secret set GoogleClientSecret $GOOGLE_CLIENT_SECRET --stage dev - # sst secret set EmailServerHost $EMAIL_SERVER_HOST --stage dev - # sst secret set EmailServerPort $EMAIL_SERVER_PORT --stage dev - # sst secret set EmailServerUser $EMAIL_SERVER_USER --stage dev - # sst secret set EmailServerPassword $EMAIL_SERVER_PASSWORD --stage dev - # sst secret set EmailFrom $EMAIL_FROM --stage dev - # sst secret set SendgridApiKey $SENDGRID_API_KEY --stage dev - # working-directory: knowx - # env: - # API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }} - # DB_URL: ${{ secrets.DB_URL }} - # NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} - # NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} - # GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }} - # GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }} - # GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - # GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - # EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }} - # EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }} - # EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }} - # EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }} - # EMAIL_FROM: ${{ secrets.EMAIL_FROM }} - # SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} - - # - name: NPM install - # id: npm_install - # run: npm install - # working-directory: knowx - - # - name: AWS check - # run: curl http://169.254.169.254/latest/meta-data - # working-directory: knowx - - # - name: SST Deploy - # id: sst_deploy - # run: sudo sst deploy --stage dev - # working-directory: knowx - - # - name: Extract URL from Deployment Output - # id: extract_url - # run: | - # output=$(cat ${{ steps.deploy.outputs.deployment_output_path }}) - # urls=$(echo "$output" | grep -oE 'https?://[^ ]+') - # last_url=$(echo "$urls" | tail -n1) - # echo "url=$last_url" >> $GITHUB_OUTPUT - # working-directory: knowx + curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿš€ Deployment DEV URL: $url" - # - name: Send Deploy Failure Message - # if: failure() - # run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿšจ Frontend(DEV) Deploy Failed" - - # - name: Send Deploy Success Message - # if: success() - # run: | - # curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=โœ… Frontend(DEV) Deploy Successful" - # url=${{ steps.extract_url.outputs.url }} - # curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿš€ Deployment(DEV) URL: $url" - - # production_deploy: - # needs: dev_deploy - # name: "Deploy to AWS - PRODUCTION" - # environment: prod - # runs-on: ubuntu-latest - # steps: - # - name: Checkout - # uses: actions/checkout@v4 + deploy-prod: + needs: [test-e2e, deploy-dev] + name: "Deploy to AWS - PRODUCTION" + environment: dev + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 - # - name: Cofigure AWS - # uses: aws-actions/configure-aws-credentials@v4 - # with: - # aws-region: us-east-1 - # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - name: Cofigure AWS + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: us-east-1 + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # - name: Install SST - # run: | - # wget https://github.com/sst/ion/releases/download/v0.0.193/sst-linux-amd64.deb - # sudo dpkg -i sst-linux-amd64.deb - # sst version - # working-directory: knowx + - name: Install SST + run: | + ls + wget https://github.com/sst/ion/releases/download/v0.0.193/sst-linux-amd64.deb + sudo dpkg -i sst-linux-amd64.deb + sst version + - name: Copy Secrets + run: | + sst secret set APIRootRoute $API_ROOT_ROUTE --stage prod + sst secret set DBUrl $DB_URL --stage prod + sst secret set NextAuthUrl $NEXTAUTH_URL --stage prod + sst secret set NextAuthSecret $NEXTAUTH_SECRET --stage prod + sst secret set GithubId $GITHUB_ID --stage prod + sst secret set GithubSecret $GITHUB_SECRET --stage prod + sst secret set GoogleClientId $GOOGLE_CLIENT_ID --stage prod + sst secret set GoogleClientSecret $GOOGLE_CLIENT_SECRET --stage prod + sst secret set EmailServerHost $EMAIL_SERVER_HOST --stage prod + sst secret set EmailServerPort $EMAIL_SERVER_PORT --stage prod + sst secret set EmailServerUser $EMAIL_SERVER_USER --stage prod + sst secret set EmailServerPassword $EMAIL_SERVER_PASSWORD --stage prod + sst secret set EmailFrom $EMAIL_FROM --stage prod + sst secret set SendgridApiKey $SENDGRID_API_KEY --stage prod + working-directory: knowx + env: + API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }} + DB_URL: ${{ secrets.DB_URL }} + NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} + NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} + GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }} + GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }} + GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} + GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} + EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }} + EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }} + EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }} + EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }} + EMAIL_FROM: ${{ secrets.EMAIL_FROM }} + SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} - # - name: Copy Secrets - # run: | - # sst secret set APIRootRoute $API_ROOT_ROUTE --stage prod - # sst secret set DBUrl $DB_URL --stage prod - # sst secret set NextAuthUrl $NEXTAUTH_URL --stage prod - # sst secret set NextAuthSecret $NEXTAUTH_SECRET --stage prod - # sst secret set GithubId $GITHUB_ID --stage prod - # sst secret set GithubSecret $GITHUB_SECRET --stage prod - # sst secret set GoogleClientId $GOOGLE_CLIENT_ID --stage prod - # sst secret set GoogleClientSecret $GOOGLE_CLIENT_SECRET --stage prod - # sst secret set EmailServerHost $EMAIL_SERVER_HOST --stage prod - # sst secret set EmailServerPort $EMAIL_SERVER_PORT --stage prod - # sst secret set EmailServerUser $EMAIL_SERVER_USER --stage prod - # sst secret set EmailServerPassword $EMAIL_SERVER_PASSWORD --stage prod - # sst secret set EmailFrom $EMAIL_FROM --stage prod - # sst secret set SendgridApiKey $SENDGRID_API_KEY --stage prod - # working-directory: knowx - # env: - # API_ROOT_ROUTE: ${{ secrets.API_ROOT_ROUTE }} - # DB_URL: ${{ secrets.DB_URL }} - # NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} - # NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} - # GITHUB_ID: ${{ secrets.NEXTAUTH_GITHUB_ID }} - # GITHUB_SECRET: ${{ secrets.NEXTAUTH_GITHUB_SECRET }} - # GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - # GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - # EMAIL_SERVER_HOST: ${{ secrets.EMAIL_SERVER_HOST }} - # EMAIL_SERVER_PORT: ${{ secrets.EMAIL_SERVER_PORT }} - # EMAIL_SERVER_USER: ${{ secrets.EMAIL_SERVER_USER }} - # EMAIL_SERVER_PASSWORD: ${{ secrets.EMAIL_SERVER_PASSWORD }} - # EMAIL_FROM: ${{ secrets.EMAIL_FROM }} - # SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} + - name: NPM install + run: npm install + working-directory: knowx - # - name: Deploy - # id: deploy - # run: | - # npm install - # sudo sst deploy --stage prod > deployment_output.txt - # echo "deployment_output_path=deployment_output.txt" >> $GITHUB_OUTPUT - # working-directory: knowx + - name: Deploy + id: deploy + run: | + sst deploy --stage prod > deployment_output.txt + echo "deployment_output_path=deployment_output.txt" >> $GITHUB_OUTPUT + working-directory: knowx - # - name: Extract URL from Deployment Output - # id: extract_url - # run: | - # output=$(cat ${{ steps.deploy.outputs.deployment_output_path }}) - # urls=$(echo "$output" | grep -oE 'https?://[^ ]+') - # last_url=$(echo "$urls" | tail -n1) - # echo "url=$last_url" >> $GITHUB_OUTPUT - # working-directory: knowx + - name: Extract URL from Deployment Output + id: extract_url + run: | + output=$(cat ${{ steps.deploy.outputs.deployment_output_path }}) + urls=$(echo "$output" | grep -oE 'https?://[^ ]+') + last_url=$(echo "$urls" | tail -n1) + echo "url=$last_url" >> $GITHUB_OUTPUT + working-directory: knowx - # - name: Send Deploy Failure Message - # if: failure() - # run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿšจ Frontend(PROD) Deploy Failed" + - name: Send Deploy Failure Message + if: failure() + run: curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿšจ Frontend PROD Deploy Failed" - # - name: Send Deploy Success Message - # if: success() - # run: | - # curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=โœ… Frontend(PROD) Deploy Successful" - # url=${{ steps.extract_url.outputs.url }} - # curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿš€ Deployment(PROD) URL: $url" + - name: Send Deploy Success Message + if: success() + run: | + curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=โœ… Frontend PROD Deploy Successful" + url=${{ steps.extract_url.outputs.url }} + curl -s -X POST "${{ secrets.DISCORD_WEBHOOK }}" -d "content=๐Ÿš€ Deployment PROD URL: $url"