Skip to content

Latest commit

 

History

History
102 lines (79 loc) · 4.8 KB

01- Github Actions Basic Building blocks and Components.md

File metadata and controls

102 lines (79 loc) · 4.8 KB

Github Actions Basic Building blocks and Components

  • Basic Buidling blocks of Github Actions:
image
  • 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()"
    
  • Official Github Actions Doc: https://docs.github.com/en/actions

  • On Github Marketplace we have two options: Apps and Actions:

  • Github Checkout Action:

    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.

Errors

  1. 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:

image

Now you have createed new token using which you can push the github workflow to github..

Summary: Github Actions Basic Building blocks and Components

image