pack directory ethonline-2023-build-run-id #4 #35
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: Build with Vite | |
working-directory: ${{ github.workspace }}/frontend | |
run: yarn build | |
- name: Put Git tag and time to .env file | |
run: | | |
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: 'pm2-start-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 }}" |