From d5727623586abc442fdb30a96f1b448c8f1cea95 Mon Sep 17 00:00:00 2001 From: tituschewxj Date: Tue, 8 Oct 2024 23:37:40 +0800 Subject: [PATCH] fix: use env --- .github/workflows/test.yml | 52 +++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0175c08f00..daba10a7e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Docker Compose Pipeline +name: Docker Compose Testing Pipeline on: push: @@ -13,7 +13,6 @@ on: jobs: test: runs-on: ubuntu-latest - environment: testing steps: - name: Checkout code @@ -25,43 +24,56 @@ jobs: sudo apt-get install -y docker-compose - name: Create Environment Files + env: + QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }} + USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }} + DB_CLOUD_URI: ${{ secrets.USER_SERVICE_DB_CLOUD_URI }} + USER_SERVICE_PORT: ${{ vars.USER_SERVICE_PORT }} run: | cd ./apps/frontend - echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=${{ vars.QUESTION_SERVICE_URL }}" >> .env - echo "NEXT_PUBLIC_USER_SERVICE_URL=${{ vars.USER_SERVICE_URL }}" >> .env + echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env + echo "NEXT_PUBLIC_USER_SERVICE_URL=$USER_SERVICE_URL" >> .env cd ../question-service - echo "FIREBASE_CREDENTIAL_PATH=${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}" >> .env - echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env + echo "FIREBASE_CREDENTIAL_PATH=$FIREBASE_CREDENTIAL_PATH" >> .env + echo "JWT_SECRET=$JWT_SECRET >> .env cd ../user-service - echo "DB_CLOUD_URI=${{ vars.USER_SERVICE_DB_CLOUD_URI }}" >> .env - echo "PORT=${{ vars.USER_SERVICE_PORT }}" >> .env - echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env + echo "DB_CLOUD_URI=$DB_CLOUD_URI" >> .env + echo "PORT=$USER_SERVICE_PORT" >> .env + echo "JWT_SECRET=$JWT_SECRET" >> .env + + - name: Create Database Credential Files + env: + FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }} + FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }} + run: | + cd ./apps/question-service + echo "$FIREBASE_JSON" > "./$FIREBASE_CREDENTIAL_PATH" - name: Build and Run Services run: | cd ./apps docker-compose up --build -d - - name: Clean up environment files - run: | - rm ./apps/frontend/.env - rm ./apps/question-service/.env - rm ./apps/user-service/.env - - name: Run Tests + env: + FRONTEND_URL: ${{ vars.FRONTEND_URL }} + USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }} + QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }} run: | # check if non-error status code received - curl --fail ${{ vars.FRONTEND_URL }} - curl --fail ${{ vars.USER_SERVICE_URL }} + curl --fail $FRONTEND_URL + curl --fail $USER_SERVICE_URL # check if any response received - curl -s -o /dev/null ${{ vars.QUESTION_SERVICE_URL }} + curl -s -o /dev/null $QUESTION_SERVICE_URL # We can add more tests here - - name: Stop Services + - name: Clean up run: | - cd .apps + cd ./apps docker-compose down