Install dependencies #14
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: Node.js CI | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] | |
- name: Set environment variables | |
run: | | |
echo "DB_USER=${{ secrets.DB_USER }}" >> $GITHUB_ENV | |
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> $GITHUB_ENV | |
echo "DEV_DATABASE=${{ secrets.DEV_DATABASE }}" >> $GITHUB_ENV | |
- name: Build Docker image | |
run: docker compose build | |
- name: Run Docker Compose file | |
run: docker compose up -d && sleep 10 | |
- name: Install dependencies | |
run: npm install | |
- name: Run unit tests | |
run: npm test | |
- name: Run integration tests | |
run: | | |
npx sequelize-cli db:drop | |
npx sequelize-cli db:create | |
npx sequelize-cli db:migrate | |
npm run start:dev & | |
sleep 10 | |
npm install cypress cypress-json-results | |
npx cypress run | |
- name: Setup SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
- name: Deploy to the server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USER }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
docker pull todo-app:latest | |
docker stop todo-app || true | |
docker rm todo-app || true | |
docker run -d --name todo-app -p 80:80 todo-app:latest | |
- name: Stop and remove Docker containers | |
run: docker compose down |