- Basic Buidling blocks of Github Actions:
-
By Default each job run parallely and hence have its own runner.
job: test: #job 1 runs-on: ubuntu-latest #runner 1 .. .. deploy: #job 2 runs-on: ubuntu-latest #runner 2 .. ..
-
To make run jobs sequentially we have to just add "needs"
job: test: #job 1 runs-on: ubuntu-latest #runner 1 .. .. deploy: #job 2 needs: test #"deploy" job needs "test" to execute first and if it fails, "deploy" job will not execute, which makes it sequential.. runs-on: ubuntu-latest #runner 2 .. ..
-
Multiple event triggers, add all the ways of trigger under "on"
name: Deploy Project on: [push, workflow_dispatch] #here "push" means whenever pushing code, "workflow_dispatch" means manually running the work.. jobs:
-
Expression and Context Objects
name: Output information on: workflow_dispatch jobs: info: runs-on: ubuntu-latest steps: - name: Output GitHub context run: echo "${{ toJSON(github) }}" #expression. to make it readbale wrapped with function "toJSON()"
- To know about Github Action Context objects: https://docs.github.com/en/actions/learn-github-actions/contexts
- Just like we used above exmaple "github" which is context object..
- To know about Github Actions Expression/Function: https://docs.github.com/en/actions/learn-github-actions/expressions
- Just like we used above exmaple "${{ toJSON(github) }}" which is Expression..
- To know about Github Action Context objects: https://docs.github.com/en/actions/learn-github-actions/contexts
-
Official Github Actions Doc: https://docs.github.com/en/actions
-
On Github Marketplace we have two options: Apps and Actions:
- Here is Github Action Marketplace : https://github.com/marketplace?type=actions
-
Github Checkout Action:
- Repo: https://github.com/actions/checkout?tab=readme-ov-file
- Marketplace: https://github.com/marketplace/actions/checkout
jobs: test: runs-on: ubuntu-latest steps: - name: Get code uses: actions/checkout@v3 #"actions/checkout" define the name and "v3" is the version of teh action #we can also add more parameters to the checkout action with "with" command refer here: https://github.com/marketplace/actions/checkout#usage
-
Failing and Analysizing Workflows: To understand any worflow or just to undestand if whats happening underthe worflow, always refer to the logfile of the workflow which is visible after your workflow executes under the "Actions" tab.
-
Error to push github actions worflow from local to github:
To have access to push Github Action workflows from local system to Github you need to have "developer token" which have access to not just repository but also to workflow, which you can create it from here: https://github.com/settings/tokens (if there are other tokens as well remove them for you) and tick the workflow aswell, as shown in below image:
Now you have createed new token using which you can push the github workflow to github..
-
Final Deployment Code - https://github.com/BaliDataMan/github-actions-course-resources/blob/main/Code/02%20Basics/03%20Finished%20Project/.github/workflows/deployment.yml
- Another 2 deployments exmaples:
-
Deployment 01: https://github.com/BaliDataMan/github-actions-course-resources/blob/main/Code/02%20Basics/05%20Practice%20Project%20(Finished)/.github/workflows/deployment1.yaml
-
Deployment 02: https://github.com/BaliDataMan/github-actions-course-resources/blob/main/Code/02%20Basics/05%20Practice%20Project%20(Finished)/.github/workflows/deployment2.yaml
-
- Another 2 deployments exmaples: