on: push: branches: - main jobs: checking: runs-on: docker container: node:lts steps: - name: Checkout source code uses: https://code.forgejo.org/actions/checkout@v3 - name: Install packages run: npm install - name: Run astro check (linting + static analysis) run: npm run astro check build-site: needs: [checking] runs-on: docker container: node:lts steps: - name: Checkout checked source code uses: https://code.forgejo.org/actions/checkout@v3 - name: Install required packages run: npm install - name: Build static site run: npm run build - name: Delete unnecessary data files run: rm -r public/assets/data/ - name: Copy missing config for binserve run: cp serve.json public - name: Save site artifact as static-site uses: https://code.forgejo.org/actions/upload-artifact@v3 with: name: static-site path: public/ deploy-files: needs: [ build-site ] runs-on: docker env: DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} steps: - name: Install and update ssh + rsync run: | which rsync || ( apt update -y && apt install rsync -y) which ssh-agent || ( apt update -y && apt install openssh-client -y) - name: Downloading static site artifacts uses: actions/download-artifact@v3 with: name: static-site path: public - name: Install SSH Key uses: https://github.com/shimataro/ssh-key-action@v2 with: key: ${{ secrets.SSH_PRIVATE_KEY }} known_hosts: unnecessary - name: Adding Known Hosts run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts - name: Stop screen session, delete old files uses: https://github.com/appleboy/ssh-action@master with: host: ${{ env.DEPLOY_HOST }} username: ${{ env.DEPLOY_USER }} key: ${{ secrets.SSH_PRIVATE_KEY }} script: | screen -X -S fgo-ta_com-public kill rm -r -f fgo-ta_com/public/* - name: Copy files using rsync run: rsync -az --stats public/* ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:~/fgo-ta_com/public - name: Check files on deploy target uses: https://github.com/appleboy/ssh-action@master with: host: ${{ env.DEPLOY_HOST }} username: ${{ env.DEPLOY_USER }} key: ${{ secrets.SSH_PRIVATE_KEY }} script: | cd fgo-ta_com find public -maxdepth 1 -printf "%p\n" deploy-site: needs: [ deploy-files ] runs-on: docker env: DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} steps: - name: Install and update ssh + rsync run: | which rsync || ( apt update -y && apt install rsync -y) which ssh-agent || ( apt update -y && apt install openssh-client -y) - name: Install SSH Key uses: https://github.com/shimataro/ssh-key-action@v2 with: key: ${{ secrets.SSH_PRIVATE_KEY }} known_hosts: unnecessary - name: Adding Known Hosts run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts - name: Start new screen session uses: https://github.com/appleboy/ssh-action@master with: host: ${{ env.DEPLOY_HOST }} username: ${{ env.DEPLOY_USER }} key: ${{ secrets.SSH_PRIVATE_KEY }} script: | PATH="$HOME/.local/bin:$PATH" cd fgo-ta_com screen -S fgo-ta_com-public -dm serve public/ -p ${{ secrets.DEPLOY_TARGET_PORT }}