1

I'd like to add to the Slack message that notifies that a Github workflow run has finished, the total duration it took to run.

Does anyone know how can it be achieved? I couldn't find "total duration" in any of the contexts...

Itai Ganot
  • 5,873
  • 18
  • 56
  • 99
  • What has been stated in this post could be useful: https://stackoverflow.com/questions/67890631/how-can-i-get-the-total-build-time-of-a-github-action-workflow – GuiFalourd May 09 '22 at 18:37

1 Answers1

2

I don't think it's available from a context, but you could do it with two separate run steps:

  1. Store the current time as a timestamp (first step in workflow):

    - name: Set start timestamp
      id: start
      run: |
        printf 'timestamp=%(%s)T\n' >> "$GITHUB_OUTPUT"
    
  2. Calculate difference (at end of workflow):

    - name: Calculate duration
      run: |
        printf -v now '%(%s)T'
        duration=$((now - ${{ steps.start.outputs.timestamp }}))
        # Do something with duration, set as output to then use in Slack message
        # or similar
    

This puts the duration in seconds into the duration variable.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116