fixed #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: CICD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
validation: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Install dependencies | |
run: npm ci | |
- name: Code linting and formatting | |
run: npm run lint | |
notifications-codevalidation: | |
name: Code validation Notification | |
needs: validation | |
runs-on: ubuntu-latest | |
if: ${{ always() }} | |
steps: | |
- name: Code validation results on Discord | |
env: | |
DISCORD_WEBHOOKURL: ${{ secrets.DISCORD_WEBHOOKURL }} | |
run: | | |
if [[ ${{ needs.validation.result }} == 'success' ]]; then | |
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Code validation* completed successfully \nCheck the logs for details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL | |
else | |
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Code validation* failed. \nCheck the logs for details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL | |
fi | |
build_and_run_tests: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:11.7 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: ${{secrets.pg_password }} | |
POSTGRES_DB: voting_db | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- name: Install Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run tests | |
run: npm test | |
- name: Run the app | |
id: run-app | |
run: | | |
npm install | |
npx sequelize-cli db:drop | |
npx sequelize-cli db:create | |
npx sequelize-cli db:migrate | |
PORT=3000 npm start & | |
sleep 5 | |
test-notifications: | |
name: Test Notifications | |
needs: build_and_run_tests | |
runs-on: ubuntu-latest | |
if: ${{ always() }} | |
steps: | |
- name: Test results notifications on Discord | |
env: | |
DISCORD_WEBHOOKURL: ${{ secrets.DISCORD_WEBHOOKURL }} | |
run: | | |
if [[ ${{ needs.build_and_run_tests.result }} == 'success' ]]; then | |
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Test cases* passed successfully. \nCheck the logs for details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL | |
else | |
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Test cases* failed. \nCheck the logs for details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL | |
fi | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build_and_run_tests | |
steps: | |
- name: Deploy to render | |
uses: johnbeynon/render-deploy-action@v0.0.8 | |
with: | |
service-id: ${{ secrets.RENDER_SERVICEID}} | |
api-key: ${{ secrets.API_TOKEN }} | |
deploy-notifications: | |
name: Deployment Notifications | |
needs: deploy | |
runs-on: ubuntu-latest | |
if: ${{ always() }} | |
steps: | |
- name: Deployment results notifications on Discord | |
env: | |
DISCORD_WEBHOOKURL: ${{ secrets.DISCORD_WEBHOOKURL }} | |
run: | | |
if [[ ${{ needs.deploy.result }} == 'success' ]]; then | |
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Deployment of the application* completed successfully. \nCheck the logs for details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL | |
else | |
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Deployment* failed. \nCheck the logs for details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL | |
fi | |