Github Actions πŸ™

Hero image for Github Actions πŸ™

Formatting

  • Add a line break between each root-level block.

    # Bad
    name: Build
    on: push
    env:
      DOCKER_IMAGE: $
      
    # Good
    name: Build
      
    on: push
      
    env:
      DOCKER_IMAGE: $
    
  • Add a line break between each job step.

    # Bad
    steps:
      - uses: actions/[email protected]
      - name: Login to DockerHub
        uses: docker/[email protected]
      
    # Good
    steps:
      - uses: actions/[email protected]
      
      - name: Login to DockerHub
        uses: docker/[email protected]
    

Naming

  • Name workflow files following the pattern verb_environment.yml. environment can be omitted if the workflow does not vary per environment.

    # Bad 
    β”œβ”€β”€ ci.yml
    β”œβ”€β”€ run_all_tests.yml
    β”œβ”€β”€ prod_deploy.yml
    β”œβ”€β”€ docker_test.yml
      
    # Good
    β”œβ”€β”€ test.yml
    β”œβ”€β”€ deploy.yml
    β”œβ”€β”€ deploy_production.yml
    β”œβ”€β”€ deploy_staging.yml
    β”œβ”€β”€ test_docker_build.yml
    
  • The name attribute for job must be provided as this is the value which will be used in the web UI.

    # Bad
    jobs:
      publish:
        runs-on: ubuntu-latest
      
    # Good
    jobs:
      publish:
        name: Publish Docker Image
        runs-on: ubuntu-latest
    
  • The name attribute jobs set must be provided and follow the pattern β€œVerb description”. Start with a verb so there is a clear expectation of what the step is for.

    # Bad 
    - run: echo "SEGMENT_JS_KEY=$SEGMENT_JS_KEY" >> .env
      
    - uses: docker/[email protected]
      
    # Good
    - name: Add environments variables to .env file
      run: echo "SEGMENT_JS_KEY=$SEGMENT_JS_KEY" >> .env
      
    - name: Login to DockerHub
      uses: docker/[email protected]
    

Syntax

  • In the step block with run, prefer using a command with single line format.

    # Bad 
    - name: All using commands
      run: |
        echo "command no.1" >> .env
      
    # Good
    - name: All using commands
      run: echo "command no.1" >> .env
    

    And for multi-line commands, prefer using the literal block scalar | which preserves new lines and trailing spaces.

    - name: All using commands
      run: |
        echo "command no.1" >> .env
        echo "command no.2" >> .env
        echo "command no.3" >> .env