- How to fork the repository
- Creating a workflow file
- Triggering a workflow
- Verifying changes before merging codes
- Creating pull request
- Setting branch protection
- Deploying to heroku
- Let's change some codes
- How could we fix when some test failed?
- More Learning Hubs
- More Agoda
- Click on
Forkbutton (on the top-right) - Select your Github account
- Go to
Codetab in Github repository - Create a folder named
.github/workflowsinside the repository by clickingCreate new file, paste.github/workflowsinto text box - Create a workflow file inside
.github/workflows, filename can be anything but extension must be.ymle.g..github/workflows/cicd-workflow.yml
# workflow name name: Nodejs # event of the workflow on: push jobs: build: name: Nodejs # specify a host machine for the job e.g. ubuntu-latest, windows-latest runs-on: ubuntu-latest # define environment variables using in the job env: IMAGE_NAME: nodejs-example IMAGE_TAG: latest steps: # checkout codes to a build server - uses: actions/checkout@v1 # build docker image - name: Docker build run: docker build -t $IMAGE_NAME:$IMAGE_TAG . # run tests - name: Test run: docker run --rm -i $IMAGE_NAME:$IMAGE_TAG yarn test
- Click
Commit new filebutton
NOTE: You can create more than one workflow in the repository.
Workflow will be triggered by the event defined above.
For example,
pushevent will be triggered when someone push some codes into the repositorypull_requestevent will be triggered when someone open a pull request
After pushing your changes, go to Actions tab in your Github repository. The changes will be verified and you should see the green check in front of the workflow name when it is finished.
- Go back to
Codetab - Go to
.github/workflows/cicd-workflow.yml, edit the file by clicking at pencil icon - Change the event of the workflow from
on: pushto beon: pull_request
name: Nodejs
on: pull_request
- Select
Start commitdropdown (top-right) and clickCommit changesbutton - Go back to
Actionstab and you should not see a new build running
- Go to
README.mdfile in root path, edit the file by clicking at pencil icon - Change the repository name in the first line from

to be

Commit changesby selectingCreate a new branch for this commit and start a pull request.- Click
Propose file changebutton - You will see the difference of your changes and
Create pull request - Go to
Actionstab and wait forpull_requestworkflow to be triggered - Go to
Pull requeststab, you will see the check namedNodejs (pull_request)is running
Protect the master branch from having commits not tested merged by requiring status checks to pass before merging a pull request
- Select
Settingsof your github repository - Go to
Branchesin the left menu and click onAdd rulebutton
- Branch name pattern:
master - Check on
Require status checks to pass before merging - Select
Nodejsworkflow
- Go back to
Pull requests, you will seeRequiredbadge inside the check - Wait for all checks to pass and click on
Merge pull requestbutton
- Sign up in Heroku: https://signup.heroku.com/login
- Verify your account in registered e-mail
- Log in to your account
- Select
New(on the top-right) and thenCreate new app - Fill
App Namee.g.<your_name>-cicd
- Click on your avatar on the top-right corner
- Select
Account settings - Scroll down to
API KeyandGenerate API Key... - Copy
API Key
- Select
Settingsof your github repository - Go to
SecretsandAdd a new secret- Name: HEROKU_API_KEY
- Value:
<your_heroku_api_key>
- Go back to
Codetab and go inside.github/workflowsdirectory - Select
Create new file, filename can be anything but extension must be.ymle.g..github/workflows/master-cicd.yml
name: Nodejs
on:
push:
# the job will be triggered when there are changes in master
branches:
- master
jobs:
build:
name: Nodejs
runs-on: ubuntu-latest
# environment variables for Heroku
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP: <your_name>-cicd
steps:
- uses: actions/checkout@v1
# login to Heroku with Heroku API key
- name: Heroku login
uses: "actions/heroku@master"
with:
args: "container:login"
secrets: |
$HEROKU_API_KEY
# push codes to Heroku
- name: Heroku push
uses: "actions/heroku@master"
with:
args: "container:push -a $HEROKU_APP web"
secrets: |
$HEROKU_API_KEY
# release
- name: Heroku release
uses: "actions/heroku@master"
with:
args: "container:release -a $HEROKU_APP web"
secrets: |
$HEROKU_API_KEY
- Commit new file by selecting
Create a new branch for this commit and start a pull request. - Name your branch to be understandable e.g.
add-master-workflow - Click
Propose new filebutton - You will see the difference of your changes and
Create pull request - Wait for
pull_requestworkflow to be triggered and run test - When everything is green, you can merge this pull request to
master masterworkflow and deployment to Heroku will be triggered following steps defined above- Your deployment result can be seen at http://<your_app_name>.herokuapp.com/
NOTE: This will be triggered only when code is pushed to master branch.
- Go back to
Codetab and selectserver.jsfile - Edit the file by clicking at pencil
- Update greeting text from
Hello Everyone!!toHello <your_name>!! Commit changesby selectingCreate a new branch for this commit and start a pull request.- Name your branch to be understandable e.g.
update-greeting - Click
Commit changesbutton andCreate pull request - Wait for
pull_requestworkflow to be triggered and run test
- Go back to
Codetab - Select
update-greetingbranch - Go to
testsdirectory and selecterver.test.jsfile - Edit the file by clicking at pencil
- Update greeting text from
Hello EveryonetoHello <your_name> Commit changesby selectingCommit directly to the update-greeting branch.- Click
Commit changesbutton - The previous pull request is triggered
- If everything is green, you can merge this pull request to
master - Wait for
masterworkflow and deployment to Heroku to be triggered - Your deployment result can be seen at http://<your_app_name>.herokuapp.com/