Skip to content

Merge branch 'master' of github.com:neurostuff/neurostore into staging #6

Merge branch 'master' of github.com:neurostuff/neurostore into staging

Merge branch 'master' of github.com:neurostuff/neurostore into staging #6

# .github/workflows/deploy-to-staging.yml
name: Deploy to Staging
on:
push:
branches:
- staging
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Set up SSH agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add remote SSH server to known hosts
run: |
ssh-keyscan -H deepdream.psy.utexas.edu >> ~/.ssh/known_hosts
- name: Force sync staging branch to remote server
run: |
ssh [email protected] '
cd /var/www/neurostore &&
git fetch origin --unshallow && # Fetch full history if shallow clone
git fetch --all && # Fetch all branches and their histories
git reset --hard origin/staging &&
git clean -fd
'
- name: Detect changes in specific directories from the previous commit
id: changes
run: |
# Fetch full commit history and compare with the previous commit
ssh [email protected] '
cd /var/www/neurostore &&
git fetch origin && # Ensure we have the latest changes
git log -n 2 && # Log last two commits to ensure previous commit exists
changes_in_store=$(git diff --name-only HEAD~1 -- | grep '^store/' || echo "") &&
changes_in_compose=$(git diff --name-only HEAD~1 -- | grep '^compose/' || echo "") &&
changes_in_frontend=$(git diff --name-only HEAD~1 -- | grep '^compose/neurosynth-frontend/' || echo "")
# Save the outputs for the next steps
echo "store=$changes_in_store" >> $GITHUB_OUTPUT
echo "compose=$changes_in_compose" >> $GITHUB_OUTPUT
echo "frontend=$changes_in_frontend" >> $GITHUB_OUTPUT
'
- name: Run Docker commands in store directory if changes detected
if: ${{ steps.changes.outputs.store }}
run: |
ssh [email protected] '
cd /var/www/neurostore/store &&
docker compose down &&
docker compose build &&
docker compose up -d
# Wait for PostgreSQL to be ready
until docker-compose exec store pg_isready; do sleep 5; done
docker-compose exec store flask db migrate
docker-compose exec store flask db upgrade
'
- name: Run Docker commands in compose directory if changes detected
if: ${{ steps.changes.outputs.compose }}
run: |
ssh [email protected] '
cd /var/www/neurostore/compose &&
docker compose down &&
docker compose build &&
docker compose up -d
# Wait for PostgreSQL to be ready
until docker-compose exec compose pg_isready; do sleep 5; done
docker-compose exec compose flask db migrate
docker-compose exec compose flask db upgrade
'
- name: Skip Docker commands and run frontend build if only frontend changes detected
if: ${{ steps.changes.outputs.frontend }}
run: |
ssh [email protected] '
cd /var/www/neurostore/compose/neurosynth-frontend &&
npm install &&
npm run build:staging
'