Deploy artifacts #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |