Merge pull request #43 from chainhackers/anastasiabusygina-patch-3 #235
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: Build and Deploy | |
on: | |
push: | |
branches: | |
- "**" | |
tags: | |
- "v*.*.*" | |
pull_request: | |
branches: | |
- "main" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
working-directory: ${{ github.workspace }}/frontend | |
run: yarn install --frozen-lockfile | |
- name: Load environment variables | |
working-directory: ${{ github.workspace }}/frontend | |
run: | | |
echo VITE_REACT_POLYGON_ADDRESS_PP_VAULT_FACTORY=${{ vars.VITE_REACT_POLYGON_ADDRESS_PP_VAULT_FACTORY }} >> .env | |
echo VITE_REACT_APP_GIT_TAG=${{ github.ref_name }} >> .env | |
echo VITE_REACT_APP_GIT_DATE="$(git log -1 --format=%cd)" >> .env | |
- name: Print .env | |
working-directory: ${{ github.workspace }}/frontend | |
run: cat .env | |
- name: ESlint check | |
working-directory: ${{ github.workspace }}/frontend | |
run: yarn lint | |
- name: Build with Vite | |
working-directory: ${{ github.workspace }}/frontend | |
run: yarn build | |
- name: Put Git tag and time to .env file | |
run: | | |
echo VITE_REACT_POLYGON_ADDRESS_PP_VAULT_FACTORY=${{ vars.VITE_REACT_POLYGON_ADDRESS_PP_VAULT_FACTORY }} >> ${{ github.workspace }}/frontend/dist/.env | |
echo VITE_REACT_APP_GIT_TAG=${{ github.ref_name }} >> ${{ github.workspace }}/frontend/dist/.env | |
echo VITE_REACT_APP_GIT_DATE="$(date +'%Y-%m-%d')" >> ${{ github.workspace }}/frontend/dist/.env | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ethonline-2023-build-${{ github.run_id }} | |
path: ${{ github.workspace }}/frontend/dist/ | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') | |
env: | |
SCRIPT_NAME: 'deploy-dev.sh' | |
needs: build | |
steps: | |
- name: Download all workflow run artifacts | |
uses: actions/download-artifact@v3 | |
- name: Compress Build Artifact | |
run: tar -czf ethonline-2023-build-${{ github.run_id }}.tgz ./ethonline-2023-build-${{ github.run_id }}/* | |
- name: Install SSH Key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SSH_KEY }} | |
name: id_rsa | |
known_hosts: ${{ secrets.KNOWN_HOSTS }} | |
- name: Copy artifact to server | |
run: scp ./ethonline-2023-build-${{ github.run_id }}.tgz ${{ secrets.USERNAME }}@${{ secrets.HOST }}:${{ secrets.BUILDS_PATH }} | |
- name: Restart deployed build | |
run: ssh ${{ secrets.USERNAME }}@${{ secrets.HOST }} "/home/${{ secrets.USERNAME }}/${{ env.SCRIPT_NAME }} ${{ github.run_id }}" |