46 lines
1.6 KiB
YAML
46 lines
1.6 KiB
YAML
name: Deploy Frontend
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
shell: sh
|
|
steps:
|
|
- name: Install SSH client
|
|
run: |
|
|
V=$(cut -d'.' -f1-2 /etc/alpine-release)
|
|
echo "https://dl-cdn.alpinelinux.org/alpine/v$V/main" > /etc/apk/repositories
|
|
echo "https://dl-cdn.alpinelinux.org/alpine/v$V/community" >> /etc/apk/repositories
|
|
apk add --no-cache openssh-client
|
|
- name: Setup SSH key
|
|
env:
|
|
SSH_KEY: ${{ secrets.DEPLOY_KEY }}
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "$SSH_KEY" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
ssh-keyscan -p 2234 -H 172.17.0.1 >> ~/.ssh/known_hosts
|
|
- name: Deploy reviewed scoped frontend release
|
|
env:
|
|
RELEASE_SHA: ${{ gitea.sha }}
|
|
run: |
|
|
case "$RELEASE_SHA" in ''|*[!0-9a-f]*) exit 1;; esac
|
|
test "${#RELEASE_SHA}" = 40
|
|
ssh -p 2234 devops@172.17.0.1 "bash -s -- $RELEASE_SHA" <<'REMOTE'
|
|
set -euo pipefail
|
|
expected=$1
|
|
cd /opt/services/parsa/frontend/repo
|
|
test -z "$(git status --porcelain --untracked-files=normal)"
|
|
export GIT_SSH_COMMAND='ssh -i /home/devops/.ssh/deploy_key -o StrictHostKeyChecking=no'
|
|
git fetch origin main
|
|
test "$(git rev-parse origin/main)" = "$expected"
|
|
git merge --ff-only "$expected"
|
|
bash -n ops/deploy-frontend.sh
|
|
sudo install -m 0755 ops/deploy-frontend.sh /opt/services/parsa/frontend/deploy.sh
|
|
bash /opt/services/parsa/frontend/deploy.sh "$expected"
|
|
REMOTE
|