Documentation Explanation of YAML file
Pipeline setup:
This consists of a name and on attributes followed by env attributes.
-> name: Gives a name to our automatic checks for the Online Voting Application. Besides, recognize what these checks are for in our GitHub Actions.
->on: This basically decides when these checks should happen. And ensures the checks run whenever there's a change in the master code branch.
->env: These stores special details needed for our checks, like database information. we used three environment variables. 1)PG_Database 2)PG_User 3) PG_PASSWORD
1) PG_Database: Specifies the database name used for the Online Voting Application. And tells our checks which database to connect to for testing.
2)PG_User: Defines the username used to access the database. Provides the credentials necessary for accessing the database during the checks.
3)PG_PASSWORD : Holds the password needed to authenticate the database user. Besides it will Ensures secure access to the database by storing the password in a protected manner.
Jobs: In GitHub Actions, a "job" means a bunch of tasks that are done together on a machine called a "runner." A runner is like a workspace where these tasks are carried out. Each job does its work separately, and they can run at the same time unless they need to wait for another job to finish first.
1)Code Validation: This job is named "Validation code" and runs on the latest version of Ubuntu. It checks out the repository code. Sets up Node.js version 14. And installs project dependencies using npm. at last Runs ESLint using the lint-staged package.
lint:
name: Validation code
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Install Dependencies
run: npm ci
- name: Run ESLint
run: npx lint-staged
2) Run Tests:
This job is responsible for running tests on the application. Same as validation it runs on Ubuntu. Utilizes a PostgreSQL service container with version 11.7, which includes providing environment variables for PostgreSQL configuration.
-> services: Defines additional services that need to be run alongside the job. Next to the main task, there's a PostgreSQL service running with specific settings like username and password. It's set up to check if PostgreSQL is ready before starting the tests, and it's connected to the host machine through port 5432.
->Check out the repository code followed by Installing dependencies using npm.
-> Run unit tests using npm test. Setting up the application by dropping the existing database, creating a new one, running migrations, and starting the server on port 7000. And Runs integration tests using Cypress.
run-tests:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:11.7
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${{secrets.password_DB }}
POSTGRES_DB: online_voting_DB
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Check out repository code
uses: actions/checkout@v3
# Performs a clean installation of all dependencies in the `package.json` file
# For more information, see https://docs.npmjs.com/cli/ci.html
- name: Install dependencies
run: npm ci
- name: Run unit 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=7000 npm start &
sleep 5
- name: Run integration tests
run: |
npm install cypress cypress-json-results
npx cypress run
3)Deploy: This job is named as "Automatic Deployment," this job is triggered after the "Run Tests" job is successfully completed.
->This runs on Ubuntu and Deploys the backend application to Render using the johnbeynon/render-deploy-action GitHub Action.
->And requires secrets for Render service ID and API token for authentication.
deploy:
name: Automaic Deployment
needs: [run-tests] #before deployment run tests
runs-on: ubuntu-latest
steps:
- name: Backend application deployment in Render
uses: johnbeynon/render-deploy-action@v0.0.8
with:
service-id: ${{ secrets.RENDER_SERVICEID}}
api-key: ${{ secrets.API_TOKEN }}
4) Notification:
1)Test notification: This script sets up a GitHub Actions workflow named "Test Notifications" that runs on an Ubuntu environment. It sends Discord notifications based on the outcome of the "run-tests" job. If the tests succeed, it sends a success message with log links. If they fail, it sends a failure message with log links. This workflow always executes independently of previous jobs' status.
notifications-tests:
name: Test Notifications
needs: [run-tests] ## should run tests
runs-on: ubuntu-latest
if: ${{ always() }} ## runs or independent on previous jobs. i.e always show notifications
steps:
- name: Discord Notifications for Test Results
env:
DISCORD_WEBHOOKURL: ${{ secrets.DISCORD_WEBHOOKURL }}
run: |
if [[ ${{ needs.run-tests.result }} == 'success' ]]; then
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Test
cases* 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":" *Test
cases* failed. \nCheck the logs for details: https://github.com/${{ github.repository
}}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL
fi
2)Code validation notification: This script sets up a GitHub Actions workflow named "Code validation Notifications" that runs on an Ubuntu environment. It sends Discord notifications based on the outcome of the "lint" job. If the linting succeeds, it sends a success message indicating no staged files found, with log links. If it fails, it sends a failure message with log links. This workflow always executes independently of previous jobs' status.
notifications-codevalidation:
name: Code validation Notifications
needs: [lint] ## should run deployment
runs-on: ubuntu-latest
if: ${{ always() }} ## runs or independent on previous jobs. i.e always show notifications
steps:
- name: Discord Code validation for Results
env:
DISCORD_WEBHOOKURL: ${{ secrets.DISCORD_WEBHOOKURL }}
run: |
if [[ ${{ needs.lint.result }} == 'success' ]]; then
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Code
validation* completed successfully , No staged files found. \nCheck the logs for deta
ils: 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.reposi
tory }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL
fi
3)Deployment Notification: This script sets up a GitHub Actions workflow named "Deployment Notifications". It runs on an Ubuntu environment and sends Discord notifications based on the outcome of the "deploy" job. If the deployment succeeds, it sends a success message indicating completion, along with log links. If it fails, it sends a failure message with log links. This workflow always executes independently of the status of previous jobs.
name: Deployment Notifications
needs: [deploy] ## should run deployment
runs-on: ubuntu-latest
if: ${{ always() }} ## runs or independent on previous jobs. i.e always show notifications
steps:
- name: Discord Notifications for Deployment Results
env:
DISCORD_WEBHOOKURL: ${{ secrets.DISCORD_WEBHOOKURL }}
run: |
if [[ ${{ needs.deploy.result }} == 'success' ]]; then
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Dep
loyment of application* completed successfully. \nCheck the logs for details: https://
github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBH
OOKURL
else
curl -X POST -H 'Content-type: application/json' --data '{"content":" *Dep
loyment of the application* failed. \nCheck the logs for details: https://github.com/$
{{ github.repository }}/actions/runs/${{ github.run_id }}"}' $DISCORD_WEBHOOKURL
fi
4)Push Notification: This workflow sends a push notification to a Discord channel when a push event occurs on the master branch of the repository. It uses a secret named DISCORD_WEBHOOKURL to authenticate with the Discord webhook.
It runs on an Ubuntu environment and triggers only when a push event occurs on the master branch of the repository. Upon a push event, it sends a Discord notification with a message indicating the event and providing a link to the commit on the master branch.
push-notification:
name: Push Notification
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Discord Notifications for Push Event
env:
DISCORD_WEBHOOKURL: ${{ secrets.DISCORD_WEBHOOKURL }}
run: |
curl -X POST -H 'Content-type: application/json' --data '{"content":"A new
push event has been triggered on the master branch of the repository. Check it out at:
https://github.com/${{ github.repository }}/commit/${{ github.sha }}"}' $DISCORD_WEBH
OOKURL
Comments
Post a Comment