deploy_to_server #242
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy_to_server | |
on: | |
workflow_run: | |
workflows: | |
- Lint | |
- Test (backend) | |
- Test (frontend) | |
types: | |
- completed | |
jobs: | |
check_workflows: | |
runs-on: ubuntu-latest | |
outputs: | |
all_success: ${{ steps.check.outputs.all_success }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check workflow statuses | |
id: check | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
workflows=( | |
"Lint:.github/workflows/lint.yml" | |
"Test (backend):.github/workflows/test-backend.yml" | |
"Test (frontend):.github/workflows/test-frontend.yml" | |
) | |
all_success=true | |
retries=5 | |
delay=60 | |
for workflow in "${workflows[@]}"; do | |
IFS=':' read -r name file <<< "$workflow" | |
for ((i=0; i<retries; i++)); do | |
status=$(gh run list --workflow="$file" --json conclusion --jq '.[0].conclusion') | |
echo "Workflow $name ($file) status: $status" | |
if [ "$status" == "in_progress" ] || [ "$status" == "queued" ]; then | |
echo "$name workflow is still in progress or queued. Waiting for it to complete..." | |
sleep $delay | |
else | |
break | |
fi | |
done | |
case "$status" in | |
success) | |
echo "$name workflow succeeded." | |
;; | |
failure) | |
echo "$name workflow failed." | |
all_success=false | |
;; | |
cancelled) | |
echo "$name workflow was cancelled." | |
all_success=false | |
;; | |
skipped) | |
echo "$name workflow was skipped." | |
;; | |
*) | |
echo "$name workflow returned an unknown status: $status" | |
all_success=false | |
;; | |
esac | |
if [ "$all_success" = false ]; then | |
break | |
fi | |
done | |
echo "all_success=$all_success" >> $GITHUB_OUTPUT | |
deploy_to_server: | |
needs: check_workflows | |
if: needs.check_workflows.outputs.all_success == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_IP }} | |
username: ${{ secrets.SSH_USERNAME }} | |
password: ${{ secrets.SSH_PASSWORD }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
curl -X POST -H "Content-Type: application/json" -d '{"i": "${{ secrets.ACCT_TOKEN }}", "text": "@n1lsqn@papi.n1l.dev ใขใใใใผใใ้ๅงใใพใใใ `${{ github.head_ref }}`", "visibility": "home"}' https://m.n1l.dev/api/notes/create | |
cd /home/misskey/misskey | |
git pull origin | |
git fetch origin | |
git reset --hard origin/${{ github.head_ref }} | |
git checkout ${{ github.head_ref }} | |
git submodule update --init | |
NODE_ENV=production pnpm install --frozen-lockfile | |
NODE_ENV=production pnpm run build | |
pnpm run migrate | |
sudo service misskey restart | |
sleep 60 | |
curl -X POST -H "Content-Type: application/json" -d '{"i": "${{ secrets.ACCT_TOKEN }}", "text": "@n1lsqn@papi.n1l.dev ใขใใใใผใใๅฎไบใใพใใใ `${{ github.head_ref }}`", "visibility": "home"}' https://m.n1l.dev/api/notes/create |