From b961b0852af568ad91b416c4fe7aa3900d3f4f79 Mon Sep 17 00:00:00 2001 From: "Gu://em_" Date: Fri, 27 Mar 2026 23:33:21 +0100 Subject: [PATCH] Brand new CI/CD pipeline (hope this one works out this time) --- .forgejo/workflows/deploy.yaml | 83 +++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/.forgejo/workflows/deploy.yaml b/.forgejo/workflows/deploy.yaml index 3ef3776..c4f93ee 100644 --- a/.forgejo/workflows/deploy.yaml +++ b/.forgejo/workflows/deploy.yaml @@ -1,17 +1,38 @@ +name: Build and deploy all on: push: branches: - main +x-site-config: &site_matrix + include: + - site: "harbor" + dest: /var/www/harbor + secret_key: "CONFIG_HARBOR" + # - site: "atlantis" + # dest: /var/www/atlantis + # secret_key: "CONFIG_ATLANTIS" + # - site: "amiral" + # dest: /var/www/amiral + # secret_key: "CONFIG_AMIRAL" + jobs: build: runs-on: docker + strategy: + matrix: *site_matrix steps: - name: Checkout git repository uses: actions/checkout@v4 - - name: "Install pnpm" + - name: Inject configs + env: + CONF: ${{ secrets[matrix.secret_key] }} + run: | + echo "$CONF" > src/data/content.json + + - name: Install pnpm uses: pnpm/action-setup@v4 with: version: 10 @@ -21,36 +42,64 @@ jobs: with: cache: "pnpm" - - name: "Install dependencies" + - name: Install dependencies run: pnpm install - - name: "Lint code" + - name: Lint code run: pnpm run lint - - name: "Checking code format" + - name: Checking code format run: pnpm run format:check - - name: "Build the project" + - name: Build the project run: pnpm run build + - name: Save the result for deployment + uses: actions/upload-artifact@v4 + with: + name: build-${{ matrix.site }} + path: dist/ + deploy: needs: build runs-on: docker + strategy: + matrix: *site_matrix steps: - - name: Get current date - id: date - run: echo "::set-output name=date::$(date +'%Y%m%d%H%M%S')" - name: Setup SSH + env: + SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }} run: | mkdir -p ~/.ssh - chmod 0700 ~/.ssh - echo "${{ secrets.SSHPRIVKEY }}" > ~/.ssh/id_ed25519 - chmod 0600 ~/.ssh/id_ed25519 - echo "[${{ vars.WEBSERVER_IP }}]:${{ SSHPORT }} ${{ secrets.SSHPUBKEY }}" > ~/.ssh/known_hosts - chmod 0600 ~/.ssh/known_hosts + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan -p ${{ secrets.SERVER_PORT }} -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts - name: Push run: | - scp -P ${{ secrets.SSHPORT }} -r dist ${{ secrets.SSH_USERNAME }}@${{ vars.WEBSERVER_IP }}:~/oblog-parallels/build-${{ steps.date.outputs.date }} - - name: Update symlink - run: | - ssh ${{ secrets.SSH_USERNAME }}@${{ vars.WEBSERVER_IP }} -p ${{ secrets.SSHPORT }} "cp -r ~/oblog-parallels/build-${{ steps.date.outputs.date }} ~/oblog-parallels/dist" + rsync -avz -e "ssh -p ${{ secrets.SERVER_PORT }}" --delete ./dist/ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:${{ matrix.dest }} + + notify: + needs: deploy + runs-on: docker + if: always() # Always run + steps: + - name: Send Discord Notification + uses: appleboy/discord-action@master + with: + webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} + webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} + color: ${{ needs.deploy.result == 'success' && '48867' || '16711680' }} + message: | + **Deployment Report** + **Status:** ${{ needs.deploy.result }} + **Repo:** ${{ gitea.repository }} + **Commit:** ${{ gitea.sha }} + + # For later + # - name: Send Matrix Notification + # uses: s707/matrix-action@master + # with: + # server_url: https://matrix.org + # room_id: ${{ secrets.MATRIX_ROOM_ID }} + # access_token: ${{ secrets.MATRIX_ACCESS_TOKEN }} + # message: "Deployment of ${{ gitea.repository }} finished with status: ${{ needs.deploy.result }}"