fgo-ta-com-website/.forgejo/workflows/ci.yml

84 lines
2.7 KiB
YAML
Raw Normal View History

2023-12-19 20:04:51 +00:00
on:
push:
branches:
- main
2023-12-19 20:03:28 +00:00
jobs:
checking:
runs-on: docker
2023-12-19 20:35:16 +00:00
container: node:lts
2023-12-19 20:03:28 +00:00
steps:
2023-12-19 22:27:43 +00:00
- name: Checkout source code
uses: https://code.forgejo.org/actions/checkout@v3
- name: Install packages
2023-12-19 20:03:28 +00:00
run: npm install
2023-12-19 22:27:43 +00:00
- name: Run astro check (linting + static analysis)
2023-12-19 20:03:28 +00:00
run: npm run astro check
build-site:
needs: [checking]
runs-on: docker
2023-12-19 20:35:16 +00:00
container: node:lts
2023-12-19 20:03:28 +00:00
steps:
2023-12-19 22:27:43 +00:00
- name: Checkout checked source code
uses: https://code.forgejo.org/actions/checkout@v3
- name: Install required packages
run: npm install
2023-12-19 20:03:28 +00:00
- name: Build static site
run: npm run build
- name: Delete unnecessary data files
run: rm -r public/assets/data/
2023-12-19 22:27:43 +00:00
- name: Copy missing config for binserve
2023-12-19 20:03:28 +00:00
run: cp serve.json public
2023-12-19 22:27:43 +00:00
- name: Save site artifact as static-site
uses: https://code.forgejo.org/actions/upload-artifact@v3
2023-12-19 20:03:28 +00:00
with:
name: static-site
path: public/
deploy-site:
2023-12-19 22:27:43 +00:00
needs: [ build-site ]
2023-12-19 20:03:28 +00:00
runs-on: docker
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
steps:
2023-12-19 21:50:25 +00:00
- name: Install and update ssh + rsync
run: |
2023-12-19 21:54:08 +00:00
which rsync || ( apt update -y && apt install rsync -y)
which ssh-agent || ( apt update -y && apt install openssh-client -y)
2023-12-19 22:27:43 +00:00
- name: Downloading static site artifacts
uses: actions/download-artifact@v3
2023-12-19 20:03:28 +00:00
with:
name: static-site
2023-12-19 22:05:27 +00:00
path: public
2023-12-19 21:50:25 +00:00
- 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
2023-12-19 21:56:23 +00:00
run: ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
2023-12-19 22:27:43 +00:00
- name: Stop screen session, delete old files
2023-12-19 21:50:25 +00:00
uses: https://github.com/appleboy/ssh-action@master
2023-12-19 20:03:28 +00:00
with:
2023-12-19 22:01:53 +00:00
host: ${{ env.DEPLOY_HOST }}
username: ${{ env.DEPLOY_USER }}
2023-12-19 21:50:25 +00:00
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
screen -X -S fgo-ta_com-public kill
rm -r -f fgo-ta_com/public/*
2023-12-19 22:27:43 +00:00
- name: Copy files using rsync
2023-12-19 22:05:27 +00:00
run: rsync -az --stats public/* ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }}:~/fgo-ta_com/public
2023-12-19 22:27:43 +00:00
- name: Start new screen session
2023-12-19 21:50:25 +00:00
uses: https://github.com/appleboy/ssh-action@master
with:
2023-12-19 22:01:53 +00:00
host: ${{ env.DEPLOY_HOST }}
username: ${{ env.DEPLOY_USER }}
2023-12-19 21:50:25 +00:00
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
PATH="$HOME/.local/bin:$PATH"
cd fgo-ta_com
find public -maxdepth 1 -printf "%p\n"
2023-12-19 22:27:43 +00:00
screen -S fgo-ta_com-public -dm serve public/ -p ${{ secrets.DEPLOY_TARGET_PORT }}