diff --git a/.github/workflows/build-and-deploy.yaml b/.github/workflows/build-and-deploy.yaml new file mode 100644 index 0000000..aefb3a4 --- /dev/null +++ b/.github/workflows/build-and-deploy.yaml @@ -0,0 +1,76 @@ +name: Build and deploy + +on: + push: + branches: [main, develop] + workflow_dispatch: + +jobs: + build: + runs-on: sg + steps: + - run: echo Hello ${{ github.ref }}. + # - name: Checkout repository + # uses: actions/checkout@v3 + # with: + # ref: ${{ github.ref }} + + # - name: Setup Node.js environment + # uses: actions/setup-node@v3 + # with: + # node-version: 18.x + + # - name: Restore Cache + # id: cache-node_modules + # uses: actions/cache@v3 + # with: + # path: node_modules + # key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.yaml') }} + + # - name: Install dependency + # run: npm install + + # - name: List the state of node modules + # if: ${{ steps.cache-node_modules.outputs.cache-hit != 'true' }} + # continue-on-error: true + # run: npm list + + # - name: Build + # run: npm run build + + # - name: Archive file + # uses: TheDoctor0/zip-release@0.7.1 + # with: + # filename: thq-${{ github.sha }}.zip + # exclusions: '/*node_modules/*' + + # - name: Archive production artifacts + # uses: actions/upload-artifact@v3 + # with: + # name: thq-${{ github.sha }}.zip + # path: ./thq-${{ github.sha }}.zip + + deploy-to-testnet: + runs-on: sg + if: ${{ github.event.workflow_run.conclusion == 'success' && github.ref_name == 'develop' }} + environment: testnet + strategy: + matrix: + target: [SERVER_1, SERVER_2] + steps: + - run: echo Hello ${{ github.ref }}. + # - name: Download Artifact + # uses: actions/download-artifact@v3 + # with: + # name: thq-${{ github.sha }}.zip + + # - name: Unzip artifact + # run: rm -rf ./dist && unzip -q thq-${{ github.sha }}.zip -d ./dist + + # - name: Deploy to server contract + # run: ls -la ./dist && rsync -a ./dist/ ${{ vars[matrix.target] }}:/mnt/ckb/ckb-time-generator + + # - name: Restart pm2 on server contract + # run: ssh ${{ vars[matrix.target] }} 'source ~/.zshrc && cd /mnt/ckb/ckb-time-generator && npm install --omit=dev && npm run reload_testnet' + + diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml deleted file mode 100644 index b6d106b..0000000 --- a/.github/workflows/cd.yaml +++ /dev/null @@ -1,63 +0,0 @@ -name: deploy -run-name: Deploy artifacts - -on: - # Only run this workflow automatically after ci workflow on main branch. - workflow_run: - workflows: [ci] - types: [completed] - branches: [main, develop] - workflow_dispatch: - -jobs: - deploy-to-mainnet: - runs-on: sg - if: github.event.workflow_run.conclusion == 'success' && github.ref_name == 'main' - environment: mainnet - strategy: - matrix: - target: [SERVER_1, SERVER_2] - steps: - - name: Download Artifact - uses: dawidd6/action-download-artifact@v2 - with: - workflow: ci - workflow_conclusion: success - run_id: ${{ github.event.workflow_run.id }} - run_number: ${{ github.event.workflow_run.run_number }} - name: thq-${{ github.event.workflow_run.head_commit.id }}.zip - - - name: Unzip artifact - run: rm -rf ./dist && unzip -q thq-${{ github.event.workflow_run.head_commit.id }}.zip -d ./dist - - - name: Deploy to server contract - run: ls -la ./dist && rsync -a ./dist/ ${{ vars[matrix.target] }}:/mnt/ckb/ckb-time-generator - - - name: Restart pm2 on server contract - run: ssh ${{ vars[matrix.target] }} 'source ~/.zshrc && cd /mnt/ckb/ckb-time-generator && npm install --omit=dev && npm run reload_mainnet' - - deploy-to-testnet: - runs-on: sg - if: github.event.workflow_run.conclusion == 'success' && github.ref_name == 'develop' - environment: testnet - strategy: - matrix: - target: [SERVER_1, SERVER_2] - steps: - - name: Download Artifact - uses: dawidd6/action-download-artifact@v2 - with: - workflow: ci - workflow_conclusion: success - run_id: ${{ github.event.workflow_run.id }} - run_number: ${{ github.event.workflow_run.run_number }} - name: thq-${{ github.event.workflow_run.head_commit.id }}.zip - - - name: Unzip artifact - run: rm -rf ./dist && unzip -q thq-${{ github.event.workflow_run.head_commit.id }}.zip -d ./dist - - - name: Deploy to server contract - run: ls -la ./dist && rsync -a ./dist/ ${{ vars[matrix.target] }}:/mnt/ckb/ckb-time-generator - - - name: Restart pm2 on server contract - run: ssh ${{ vars[matrix.target] }} 'source ~/.zshrc && cd /mnt/ckb/ckb-time-generator && npm install --omit=dev && npm run reload_mainnet' diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 69a7efe..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,49 +0,0 @@ -name: ci - -on: - push: - branches: [main, develop] - workflow_dispatch: - -jobs: - ci: - runs-on: sg - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup Node.js environment - uses: actions/setup-node@v3 - with: - node-version: 18.x - - - name: Restore Cache - id: cache-node_modules - uses: actions/cache@v3 - with: - path: node_modules - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.yaml') }} - - - name: Install dependency - run: npm install - - - name: List the state of node modules - if: ${{ steps.cache-node_modules.outputs.cache-hit != 'true' }} - continue-on-error: true - run: npm list - - - name: Build - run: npm run build - - - name: Archive file - uses: TheDoctor0/zip-release@0.7.1 - with: - filename: thq-${{ github.sha }}.zip - exclusions: '/*node_modules/*' - - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - with: - name: thq-${{ github.sha }}.zip - path: ./thq-${{ github.sha }}.zip - if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'