refactor: recipe structure #44
Workflow file for this run
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: PR Preview | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
paths: | |
- apps/mobile/** | |
- apps/server/** | |
jobs: | |
server-deploy: | |
runs-on: ubuntu-latest | |
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'development' }} | |
outputs: | |
port: ${{ steps.deploy.outputs.port }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Deploy to Server | |
id: deploy | |
run: | | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
# Stop existing containers and remove directory | |
ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_HOST <<EOF | |
docker ps -q --filter "name=${{ github.repository }}-pr-${PR_NUMBER}" | xargs -r docker stop | |
docker ps -aq --filter "name=${{ github.repository }}-pr-${PR_NUMBER}" | xargs -r docker rm | |
docker images "${{ github.repository }}-pr-${PR_NUMBER}*" -q | xargs -r docker rmi -f | |
rm -rf $DEPLOY_DIR/${{ github.repository }}-pr-$PR_NUMBER | |
mkdir -p $DEPLOY_DIR/${{ github.repository }}-pr-$PR_NUMBER | |
cd $DEPLOY_DIR/${{ github.repository }}-pr-$PR_NUMBER | |
# Clone the latest code | |
git clone -b ${{ github.event.pull_request.head.ref }} https://github.com/${{ github.repository }}.git . | |
cd apps/server | |
cat > .env <<EOL | |
DB_URL=${{ secrets.DB_URL }} | |
nodemailer_host=smtp.163.com | |
[email protected] | |
nodemailer_auth_pass=${{ secrets.NODEMAILER_AUTH_PASS }} | |
jwt_secret=agshddgfsd | |
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} | |
REDIS_URL=redis-13502.c261.us-east-1-4.ec2.redns.redis-cloud.com | |
EOL | |
cd ../.. | |
# Start container with dynamic port | |
SERVER_PORT=$PORT NODE_ENV=dev docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --force-recreate --build | |
EOF | |
env: | |
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }} | |
DEPLOY_USER: ${{ secrets.DEPLOY_USER }} | |
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} | |
# https://github.com/expo/expo-github-action/tree/main/preview#create-previews-on-pull-requests | |
eas-preview: | |
runs-on: ubuntu-latest | |
needs: server-deploy | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20.10.0 | |
cache: yarn | |
- name: Setup Expo and EAS | |
uses: expo/expo-github-action@v8 | |
with: | |
eas-version: latest | |
token: ${{ secrets.EXPO_TOKEN }} | |
- name: Install dependencies | |
run: yarn install | |
- name: Change env | |
working-directory: ./apps/mobile | |
run: | | |
EXPO_PUBLIC_BASE_URL=http://${{ secrets.DEPLOY_HOST }}:${{ needs.server-deploy.outputs.port }} | |
echo $EXPO_PUBLIC_BASE_URL | |
echo "EXPO_PUBLIC_BASE_URL=$EXPO_PUBLIC_BASE_URL" >> .env | |
- name: Trigger EAS Preview | |
uses: expo/expo-github-action/preview@v8 | |
id: preview | |
with: | |
working-directory: ./apps/mobile | |
command: eas update --auto --branch ${{ github.event.pull_request.head.ref }} |