From 2b63453f3880e4201d45de2984ed92cb60f3c288 Mon Sep 17 00:00:00 2001 From: Firq Date: Tue, 19 Dec 2023 21:03:28 +0100 Subject: [PATCH] First try at forgejo actions --- .forgejo/workflows/ci.yml | 55 ++++++++++++++++++++++++++++++++ .forgejo/workflows/ssh-setup.yml | 27 ++++++++++++++++ .vscode/settings.json | 12 +++++++ 3 files changed, 94 insertions(+) create mode 100644 .forgejo/workflows/ci.yml create mode 100644 .forgejo/workflows/ssh-setup.yml create mode 100644 .vscode/settings.json diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..4931468 --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,55 @@ + +jobs: + checking: + runs-on: docker + container: node:lts + steps: + - name: Checking Out Repository Code + uses: https://code.forgejo.org/actions/checkout@v3 + - name: + run: npm install + - name: Astro checks + run: npm run astro check + + build-site: + needs: [checking] + runs-on: docker + container: node:lts + steps: + - 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: Add missing config for binserve + run: cp serve.json public + - uses: https://code.forgejo.org/actions/upload-artifact@v4 + with: + name: static-site + path: public/ + + deploy-site: + needs: [build-site] + runs-on: docker + env: + DEPLOY_USER: ${{ secrets.DEPLOY_USER }} + DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} + SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + steps: + - uses: actions/download-artifact@v4 + with: + name: static-site + - name: Setup ssh + uses: ./.forgejo/workflows/ssh-setup.yml + with: + DEPLOY_HOST: $DEPLOY_HOST + SSH_KNOWN_HOSTS: $SSH_KNOWN_HOSTS + SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY + - name: Stopping screen session, cleaning + run: ssh $DEPLOY_USER@$DEPLOY_HOST "screen -X -S fgo-ta_com-public kill; rm -r -f fgo-ta_com/public/*;" + - name: Copying to proxmox machine + run: rsync -az --stats public/* $DEPLOY_USER@$DEPLOY_HOST:~/fgo-ta_com/public + - name: Restarting screen session + run: ssh $DEPLOY_USER@$DEPLOY_HOST 'PATH="$HOME/.local/bin:$PATH"; cd fgo-ta_com; find public -maxdepth 1 -printf "%p\n"; screen -S fgo-ta_com-public -dm serve public/ -p 9200' diff --git a/.forgejo/workflows/ssh-setup.yml b/.forgejo/workflows/ssh-setup.yml new file mode 100644 index 0000000..55558c0 --- /dev/null +++ b/.forgejo/workflows/ssh-setup.yml @@ -0,0 +1,27 @@ +name: "ssh & rsync setup" +inputs: + SSH_KNOWN_HOSTS: + required: true + description: "Known hosts file to use" + DEPLOY_HOST: + required: true + description: "hostname" + SSH_PRIVATE_KEY: + required: true + description: "SSH private key" + runs: + using: "composite" + steps: + - run: 'which rsync || ( apt update -y && apt install rsync -y )' + - run: 'which ssh-agent || ( apt update -y && apt install openssh-client -y)' + - run: eval $(ssh-agent -s) + - run: mkdir -p ~/.ssh + - run: chmod 700 ~/.ssh + - run: echo "$SSH_PRIVATE_KEY" | tr -d '\r' >> ~/.ssh/key_firq + - run: chmod 600 ~/.ssh/key_firq + - run: echo "Host $DEPLOY_HOST" >> ~/.ssh/config + - run: echo $'\n\tIdentityFile ~/.ssh/key_firq' >> ~/.ssh/config + - run: echo $'\n\tStrictHostKeyChecking no\n\tIdentitiesOnly yes\n' >> ~/.ssh/config + - run: chmod 644 ~/.ssh/config + - run: echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts + - run: chmod 644 ~/.ssh/known_hosts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ff5ea15 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "**/__pycache__": true + }, + "hide-files.files": [] +} \ No newline at end of file