70 lines
2.4 KiB
YAML
70 lines
2.4 KiB
YAML
name: Veyra CI/CD
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
env:
|
|
REMOTE_DIR: /home/workspace/sundynix-veyra
|
|
DEPLOY_HOST: 192.168.100.132
|
|
DEPLOY_USER: root
|
|
jobs:
|
|
verify:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout exact commit from Gitea
|
|
env:
|
|
GITEA_TOKEN: ${{ github.token }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
curl -fLsS -H "Authorization: token ${GITEA_TOKEN}" \
|
|
"https://git.sundynix.cn/${REPOSITORY}/archive/${COMMIT_SHA}.tar.gz" \
|
|
| tar -xz --strip-components=1
|
|
- name: Install SSH tools
|
|
run: |
|
|
set -eu
|
|
if command -v sshpass >/dev/null && command -v ssh >/dev/null; then exit 0; fi
|
|
if command -v apk >/dev/null; then
|
|
apk add --no-cache sshpass openssh-client
|
|
else
|
|
apt-get update -qq
|
|
apt-get install -y -qq --no-install-recommends sshpass openssh-client
|
|
fi
|
|
- name: Verify and build on cached deployment host
|
|
env:
|
|
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
|
|
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: bash deploy/ci-ssh.sh verify
|
|
deploy:
|
|
needs: verify
|
|
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout exact commit from Gitea
|
|
env:
|
|
GITEA_TOKEN: ${{ github.token }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
curl -fLsS -H "Authorization: token ${GITEA_TOKEN}" \
|
|
"https://git.sundynix.cn/${REPOSITORY}/archive/${COMMIT_SHA}.tar.gz" \
|
|
| tar -xz --strip-components=1
|
|
- name: Install SSH tools
|
|
run: |
|
|
set -eu
|
|
if command -v sshpass >/dev/null && command -v ssh >/dev/null; then exit 0; fi
|
|
if command -v apk >/dev/null; then
|
|
apk add --no-cache sshpass openssh-client
|
|
else
|
|
apt-get update -qq
|
|
apt-get install -y -qq --no-install-recommends sshpass openssh-client
|
|
fi
|
|
- name: Deploy verified image
|
|
env:
|
|
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
|
|
DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
|
|
COMMIT_SHA: ${{ github.sha }}
|
|
run: bash deploy/ci-ssh.sh deploy
|