From 524b017689ff4f37cfff4ca9fbbe8f464c5f1446 Mon Sep 17 00:00:00 2001 From: Sushil Chaudhary Date: Thu, 7 Dec 2023 15:42:57 +0530 Subject: [PATCH] updated workflow --- .github/workflows/doc.nuxeo.com.yml | 116 ++++++++++++++++------------ 1 file changed, 66 insertions(+), 50 deletions(-) diff --git a/.github/workflows/doc.nuxeo.com.yml b/.github/workflows/doc.nuxeo.com.yml index bd18a009..ebaf0689 100644 --- a/.github/workflows/doc.nuxeo.com.yml +++ b/.github/workflows/doc.nuxeo.com.yml @@ -1,66 +1,82 @@ name: Build and Deploy Doc.Nuxeo.com -on: - workflow_dispatch -# schedule: -# - cron: '0 5 * * *' +on: + push: + branches: + - main + - development jobs: - build-and-deploy: + set-output: runs-on: doc + outputs: + my_env: ${{ needs.set-output.outputs.my_env }} + steps: + - name: Set Doc Environment based on branch name + id: test + run: | + TARGET_BRANCH=${{ github.ref }} + if [[ "$TARGET_BRANCH" == "refs/heads/main" ]]; then + echo "my_env=production" >> $GITHUB_ENV + echo "my_env=production" >> $GITHUB_PATH + elif [[ "$TARGET_BRANCH" == "refs/heads/development" ]]; then + echo "my_env=development" >> $GITHUB_ENV + echo "my_env=development" >> $GITHUB_PATH + else + echo "my_env=Wrong Environment" >> $GITHUB_ENV + fi + build-and-deploy: + needs: set-output + runs-on: doc + environment: + name: ${{ needs.set-output.outputs.my_env }} steps: - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '14' + uses: actions/checkout@v4 - - name: Check Versions - id: check-versions - run: | - RT="git $(git --version)" - RT+=" node version $(node --version)" - RT+=" npm version $(npm --version)" - RT+=" IP $(curl -s ipinfo.io/ip)" - echo "RT=${RT}" >> $GITHUB_ENV + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '14' - - name: Save runtime versions - run: echo "${RT}" > runtime-versions.txt + - name: Check Versions + id: check-versions + run: | + RT="git $(git --version)" + RT+=" node version $(node --version)" + RT+=" npm version $(npm --version)" + RT+=" IP $(curl -s ipinfo.io/ip)" + echo "RT=${RT}" >> $GITHUB_ENV - - name: Install dependencies - run: npm ci --registry="https://registry.npmjs.org" || npm install --registry="https://registry.npmjs.org" + - name: Save runtime versions + run: echo "${RT}" > runtime-versions.txt - - name: Build - run: ALGOLIA_KEY=${{ secrets.NX_TOKEN }} DEBUG_FILE_LEVEL='debug' npm start + - name: Install dependencies + run: npm ci --registry="https://registry.npmjs.org" || npm install --registry="https://registry.npmjs.org" - - name: Generate Nginx Redirects - run: bin/redirects-yml2nginx > redirects.txt + - name: Build + run: ALGOLIA_KEY=${{ secrets.NX_TOKEN }} DEBUG_FILE_LEVEL='debug' npm start - - name: Create empty redirects_pageid.txt - run: echo > redirects_pageid.txt + - name: Generate Nginx Redirects + run: | + bin/redirects-yml2nginx > redirects.txt + echo > redirects_pageid.txt - - name: Deploy to Server - uses: appleboy/ssh-action@v1.0.0 - with: - host: ${{ secrets.DOCTEST_IP }} - username: ${{ secrets.DOCTEST_USERNAME }} - key: ${{ secrets.DOCTEST_SSH_PRIVATE_KEY }} - script: | - rsync -Waxvuk --delete site/ /opt/www/doc/ - rsync redirects.txt /etc/nginx/redirects.txt - rsync redirects_pageid.txt /etc/nginx/redirects_pageid.txt - service nginx configtest - service nginx restart + - name: Deploy to Server + run: | + rsync -Waxvuk --delete site/ /opt/www/doc/ + rsync redirects.txt /etc/nginx/redirects.txt + rsync redirects_pageid.txt /etc/nginx/redirects_pageid.txt + service nginx configtest + service nginx restart - - name: Archive Artifacts - uses: actions/upload-artifact@v3 - with: - name: build-artifacts - path: | - redirects_pageid.* - redirects.* - *.txt - npm-debug.log + - name: Archive Artifacts + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: | + redirects_pageid.* + redirects.* + *.txt + npm-debug.log \ No newline at end of file