add a comment Endpoint tested with postman #9
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: CI Workflow | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
lint-and-test: | |
name: Lint and Test | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:15 | |
ports: | |
- 5432:5432 | |
env: | |
POSTGRES_USER: ${{ secrets.POSTGRES_USER || 'news_admin' }} | |
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD || 'news_admin' }} | |
POSTGRES_DB: ${{ secrets.POSTGRES_DB || 'news_app_test' }} | |
options: >- | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
--health-cmd="pg_isready -U $POSTGRES_USER -d $POSTGRES_DB" | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set Up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- name: Set Default Environment Variables | |
run: | | |
export POSTGRES_USER=${{ secrets.POSTGRES_USER || 'news_admin' }} | |
export POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD || 'news_admin' }} | |
export POSTGRES_DB=${{ secrets.POSTGRES_DB || 'news_app_test' }} | |
export POSTGRES_HOST=${{ secrets.POSTGRES_HOST || 'localhost' }} | |
export POSTGRES_PORT=${{ secrets.POSTGRES_PORT || '5432' }} | |
export JWT_SECRET=${{ secrets.JWT_SECRET || 'Y1h8G7vCd2hAtQ2MMteBLXCdLVvAmLUe' }} | |
shell: bash | |
- name: Install Dependencies | |
run: npm install | |
- name: Run ESLint | |
run: npm run lint | |
- name: Wait for PostgreSQL to be Ready | |
run: | | |
for i in {1..10}; do | |
if pg_isready -h localhost -p 5432 -U ${{ secrets.POSTGRES_USER || 'news_admin' }}; then | |
echo "PostgreSQL is ready" | |
exit 0 | |
fi | |
echo "Waiting for PostgreSQL..." | |
sleep 2 | |
done | |
echo "PostgreSQL failed to start" | |
exit 1 | |
- name: Run Jest Tests | |
env: | |
POSTGRES_HOST: localhost | |
POSTGRES_PORT: 5432 | |
POSTGRES_USER: ${{ secrets.POSTGRES_USER || 'news_admin' }} | |
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD || 'news_admin' }} | |
POSTGRES_DB: ${{ secrets.POSTGRES_DB || 'news_app_test' }} | |
JWT_SECRET: ${{ secrets.JWT_SECRET || 'Y1h8G7vCd2hAtQ2MMteBLXCdLVvAmLUe' }} | |
NODE_ENV: test | |
run: npm test |