From 6226e675c3b62a4b72192d673c238b369d3495ae Mon Sep 17 00:00:00 2001 From: AbhilashKD <124042593+AbhilashKD@users.noreply.github.com> Date: Wed, 28 Aug 2024 20:58:20 +0530 Subject: [PATCH] Update production-deployment.yaml --- .github/workflows/production-deployment.yaml | 27 +++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/production-deployment.yaml b/.github/workflows/production-deployment.yaml index e1b433d2..1a518434 100644 --- a/.github/workflows/production-deployment.yaml +++ b/.github/workflows/production-deployment.yaml @@ -3,9 +3,9 @@ on: push: tags: - 'v*' + jobs: deploy: - #if: github.event.pull_request.merged == true runs-on: ubuntu-latest timeout-minutes: 15 steps: @@ -16,9 +16,15 @@ jobs: - name: Set TAG environment variable id: get_tag - run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + run: | + # Extract the tag from the ref and set it as an environment variable + echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - name: Debug TAG value - run: echo "TAG value - ${{ env.TAG }}" + run: | + # Print the TAG value to ensure the correct tag is being used + echo "TAG value - ${{ env.TAG }}" + - name: Deploy Stack uses: appleboy/ssh-action@master with: @@ -27,16 +33,29 @@ jobs: key: ${{ secrets.SSH_KEY_PROD }} port: ${{ secrets.PORT_PROD }} script: | + # Assign the TAG value from the environment variable TAG="${{ env.TAG }}" + + # Define the target directory and environment file TARGET_DIR="${{ secrets.TARGET_DIR_PROD }}" ENVIRONMENT="$TARGET_DIR/.env" + + # Remove the existing .env file if it exists if [ -f "$ENVIRONMENT" ]; then - rm "$ENVIRONMENT" + rm "$ENVIRONMENT" fi + + # Create the target directory if it doesn't exist and write environment variables to .env mkdir -p "$TARGET_DIR" cat << EOF > "$ENVIRONMENT" ${{ secrets.PROD_ENV }} EOF + + # Navigate to the target directory cd ${{ secrets.TARGET_DIR_PROD }} + + # List the contents of the directory for verification ls -ltra + + # Run the deployment script with the correct TAG ./deploy.sh $TAG