Skip to content

Release Magnetio v1.1.0 #2

Release Magnetio v1.1.0

Release Magnetio v1.1.0 #2

Workflow file for this run

name: Validate And Deploy
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: |
addon/package-lock.json
scraper/package-lock.json
- name: Install addon dependencies
working-directory: addon
run: npm ci
- name: Test addon
working-directory: addon
run: npm test
- name: Install scraper dependencies
working-directory: scraper
run: npm ci
deploy:
needs: validate
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Configure SSH
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
run: |
set -euo pipefail
PORT="${DEPLOY_PORT:-22}"
mkdir -p ~/.ssh
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "$PORT" "$DEPLOY_HOST" >> ~/.ssh/known_hosts
- name: Sync repository to server
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
run: |
set -euo pipefail
PORT="${DEPLOY_PORT:-22}"
rsync -az --delete \
--filter='P .env' \
--filter='P addon/.env' \
--filter='P scraper/.env' \
--exclude '.git/' \
--exclude '.github/' \
--exclude 'addon/node_modules/' \
--exclude 'scraper/node_modules/' \
--exclude '.DS_Store' \
-e "ssh -p $PORT" \
./ "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/"
- name: Deploy with Docker Compose
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
run: |
set -euo pipefail
PORT="${DEPLOY_PORT:-22}"
ssh -p "$PORT" "$DEPLOY_USER@$DEPLOY_HOST" "DEPLOY_PATH='$DEPLOY_PATH' bash -s" <<'EOF'
set -euo pipefail
cd "$DEPLOY_PATH"
if [ ! -f .env ]; then
cp .env.example .env
echo "Created .env from .env.example. Update it on the server before exposing the addon publicly."
fi
docker compose up -d --build --remove-orphans
docker compose ps
EOF
- name: Health check
env:
HEALTHCHECK_URL: ${{ secrets.HEALTHCHECK_URL }}
run: |
set -euo pipefail
if [ -z "${HEALTHCHECK_URL:-}" ]; then
echo "HEALTHCHECK_URL not set; skipping."
exit 0
fi
curl --fail --retry 12 --retry-delay 5 --retry-connrefused "$HEALTHCHECK_URL"