5 May 2022

Github Actions tips

Evaluate Expressions

I have an action that takes a URL input, like

https://docs.github.com/en/enterprise-cloud@latest/actions/learn-github-actions/expressions

on:
  workflow_call:
    inputs:
      url_endpoint: # http://my-endpoint.com/something
        required: false
        type: string
jobs:
    defaults:
      run:
        shell: bash
    steps:
      - name: Checkout sources
        uses: actions/checkout@v2
        with:
          path: some-path
          repository: ${{ env.TEST_PLAN_REPO }}
          ref: ${{ env.TEST_PLAN_BRANCH }}
      - name: call external action
        uses: some/action@v1.0
        with:
          backend_addr: ${{ ??? }} # my-endpoint.com/something
          backend_proto: ${{ ??? }} # http

How to tell if an expression is empty?

Say I have a job that sets an ouput, how to run a step if and only if, the output is set?

name: Test libp2p Compatibility

on:
  workflow_call:
    inputs:
      testsuite:
        required: true
        type: string
jobs:
  run_test:
    name: Test
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: Checkout sources
        uses: actions/checkout@v2
      - name: prepare env variable
        run: |
		  echo "::set-output name=my_var::helloworld"
        shell: bash
      - name: collect result
        if: ${{ failure() && steps.run.outputs.my_var == null }}
        run: |
                    testground collect ${{ steps.run.outputs.output_id }} --extended

Example of github actions expressions

https://www.actionsbyexample.com/context-expressions.html

https://sanderknape.com/2021/01/go-crazy-github-actions/


Laurent Senta

I wrote software for large distributed systems, web applications, and even robots. Now I focus on decentralization, overly-engineered software, and frugal innovation. I help companies around the world build products through SingularGarden.