deploy-express #42
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-express | |
on: | |
workflow_dispatch: | |
inputs: | |
reason: | |
description: 'Reason for running the workflow' | |
required: true | |
default: 'Manual trigger' | |
jobs: | |
deploy-express: | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "🎉 The job was triggered by a ${{ github.event_name }} on commit ${{ github.SHA }}" | |
- name: Check out repository code | |
uses: actions/checkout@v2 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: SSH to DO | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.DO_SSH_KEY }} | |
name: id_rsa | |
known_hosts: ${{ secrets.KNOWN_HOSTS }} | |
- name: Build | |
run: | | |
npm install -g [email protected] | |
npm install -g [email protected] | |
lerna bootstrap | |
cd ./packages/express | |
yarn remove @types/jest | |
yarn remove @types/pouchdb | |
yarn build | |
- name: Deploy and run | |
run: | | |
ssh ${{ secrets.DO_USERNAME }}@eduquilt.com mkdir /home/skuilder/dist/express/${{github.SHA}} | |
ssh ${{ secrets.DO_USERNAME }}@eduquilt.com mkdir /home/skuilder/dist/express/${{github.SHA}}/assets | |
rsync -rl ./packages/express/dist/ ${{ secrets.DO_USERNAME }}@eduquilt.com:/home/skuilder/dist/express/${{github.SHA}} | |
rsync -rl ./packages/express/assets/ ${{ secrets.DO_USERNAME }}@eduquilt.com:/home/skuilder/dist/express/${{github.SHA}}/assets | |
ssh ${{ secrets.DO_USERNAME }}@eduquilt.com ln -sfn /home/skuilder/dist/express/${{github.SHA}} /home/skuilder/api | |
ssh ${{ secrets.DO_USERNAME }}@eduquilt.com rm /home/skuilder/.env.development.local | |
ssh -t ${{ secrets.DO_USERNAME }}@eduquilt.com 'echo VERSION=${{ github.SHA }} >> /home/skuilder/.env.development.local' | |
ssh -t ${{ secrets.DO_USERNAME }}@eduquilt.com 'echo COUCHDB_ADMIN=${{ secrets.COUCHDB_ADMIN }} >> /home/skuilder/.env.development.local' | |
ssh -t ${{ secrets.DO_USERNAME }}@eduquilt.com 'echo COUCHDB_PASSWORD=${{ secrets.COUCHDB_PASSWORD }} >> /home/skuilder/.env.development.local' | |
ssh -t ${{ secrets.DO_USERNAME }}@eduquilt.com 'echo COUCHDB_PROTOCOL=${{ secrets.COUCHDB_PROTOCOL }} >> /home/skuilder/.env.development.local' | |
ssh -t ${{ secrets.DO_USERNAME }}@eduquilt.com 'echo COUCHDB_SERVER=${{ secrets.COUCHDB_SERVER }} >> /home/skuilder/.env.development.local' | |
ssh -t ${{ secrets.DO_USERNAME }}@eduquilt.com 'echo ${{ secrets.DO_PASSWORD }} | sudo -S systemctl restart eqExpress' | |
sleep 10s | |
- name: Verify deployment | |
run: | | |
response=$(curl -sS https://eduquilt.com/express) | |
if [[ $? -ne 0 ]]; then | |
echo "Error: Failed to fetch https://eduquilt.com/express" | |
exit 1 | |
fi | |
if echo "$response" | grep -q "${{ github.SHA }}"; then | |
echo "Success. Current version found in production" | |
else | |
echo "Error! Current version not reported by production." | |
echo "Response received:" | |
echo "$response" | |
exit 1 | |
fi | |
# todo: toss a buildinfo.md file into the (ecount+1) folder, linking PR, listing time, logging build errors, etc |