portulan/.forgejo/workflows/deploy.yaml

145 lines
4 KiB
YAML
Raw Normal View History

2026-03-30 22:14:27 +02:00
x-site_matrix: &site_matrix
- site: "test"
dest: "/var/www/crashtest"
config_file: "test.json"
2026-03-30 19:04:34 +02:00
2026-03-30 18:27:50 +02:00
# - 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"
2026-03-30 19:43:48 +02:00
name: Build and deploy all
on:
push:
branches:
- main
jobs:
build:
runs-on: docker
strategy:
2026-03-30 22:14:27 +02:00
matrix:
include: *site_matrix
steps:
2026-03-30 19:40:18 +02:00
- name: Debug Matrix
run: |
echo "Full Matrix Site: '${{ matrix.site }}'"
echo "Full Matrix Config: '${{ matrix.config_file }}'"
echo "Dump Matrix Context: "
echo '${{ toJSON(matrix) }}'
- name: Checkout git repository
uses: actions/checkout@v4
2026-03-30 17:36:47 +02:00
with:
path: "source"
2026-03-30 19:00:37 +02:00
- name: Retrieve configs
uses: actions/checkout@v4
with:
repository: ${{ secrets.CONFIG_REPO }}
2026-03-30 19:28:36 +02:00
token: ${{ secrets.CONFIG_REPO_TOKEN }}
2026-03-30 19:00:37 +02:00
path: "configs"
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Nodejs
uses: actions/setup-node@v4
2026-03-30 17:50:40 +02:00
with:
node-version: 22
2026-03-30 19:00:37 +02:00
- name: Install dependencies and config
run: |
cp ./configs/${{ matrix.config_file }} ./source/src/data/content.json
cd ./source
pnpm install
- name: Build the project
2026-03-30 22:19:33 +02:00
run: |
cd ./source
pnpm run build
- name: Save the result for deployment
2026-03-30 22:36:05 +02:00
uses: actions/upload-artifact@v3
with:
name: build-${{ matrix.site }}
2026-03-30 22:17:10 +02:00
path: "source/dist/"
deploy:
needs: build
runs-on: docker
strategy:
2026-03-30 22:41:21 +02:00
matrix:
include: *site_matrix
2026-03-30 22:36:05 +02:00
steps:
2026-03-30 22:47:47 +02:00
- name: Install Deployment Tools
run: |
if command -v apk >/dev/null; then
apk add --no-cache rsync openssh-client
else
apt-get update && apt-get install -y rsync openssh-client
fi
- name: Setup SSH
env:
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
2026-03-30 23:13:28 +02:00
TEST_VAL: ${{ secrets.TEST_VALUE }}
run: |
2026-03-30 23:13:28 +02:00
echo "Debugging YAML vars: ${{ secrets.TEST_VALUE }}"
echo "Debugging ENV vars: $TEST_VAL"
mkdir -p ~/.ssh
2026-03-30 23:13:28 +02:00
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p ${{ secrets.SERVER_PORT }} -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
2026-03-30 22:36:05 +02:00
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: build-${{ matrix.site }}
path: ./dist
- name: Push
run: |
2026-03-30 23:13:28 +02:00
rsync -avz -e "ssh -p ${{ secrets.SERVER_PORT }} -o StrictHostKeyChecking=no" \
--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
2026-03-30 22:41:21 +02:00
run: |
STATUS="${{ needs.deploy.result }}"
COLOR=$([ "$STATUS" == "success" ] && echo "48867" || echo "16711680")
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"embeds": [{
"title": "Deployment Report",
"color": '$COLOR',
"description": "Status: **'$STATUS'**\nRepo: ${{ github.repository }}\nCommit: ${{ github.sha }}"
}]
}' \
"${{ secrets.DISCORD_WEBHOOK_URL }}"
# 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 }}"