From e272c34c4600c02399fcabf460111d5bf9d45a72 Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Wed, 25 Mar 2026 17:34:38 +0200 Subject: [PATCH] added github action for auto deploy --- .github/workflows/deploy-blog.yml | 65 +++++++++++++++++++++++++++++++ src/components/Header.astro | 9 ++++- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy-blog.yml diff --git a/.github/workflows/deploy-blog.yml b/.github/workflows/deploy-blog.yml new file mode 100644 index 0000000..ed19128 --- /dev/null +++ b/.github/workflows/deploy-blog.yml @@ -0,0 +1,65 @@ +name: Deploy Astro Blog + +on: + push: + branches: + - main + paths: + - 'src/blog/**' + - 'src/friends/**' + - 'package.json' + - 'package-lock.json' + - 'astro.config.mjs' + - 'astro.config.ts' + - 'src/content/**' + - 'public/**' + - '.github/workflows/deploy-blog.yml' + workflow_dispatch: + +concurrency: + group: deploy-blog + cancel-in-progress: true + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + env: + DEPLOY_HOST: ${{ vars.DEPLOY_HOST }} + DEPLOY_PORT: ${{ vars.DEPLOY_PORT }} + DEPLOY_PATH: ${{ vars.DEPLOY_PATH }} + DEPLOY_USER: ${{ vars.DEPLOY_USER }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Build Astro site + run: npm run build + + - name: Install rsync and ssh client + run: sudo apt-get update && sudo apt-get install -y rsync openssh-client + + - name: Setup SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + echo "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts + chmod 644 ~/.ssh/known_hosts + + - name: Deploy to server + run: | + rsync -avz --delete \ + -e "ssh -p ${DEPLOY_PORT}" \ + dist/ \ + ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/ \ No newline at end of file diff --git a/src/components/Header.astro b/src/components/Header.astro index ca8b5a6..ffe096a 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -13,12 +13,19 @@ const t = getTranslations(lang);