Search code examples
ubuntugithubgithub-actionscicdtime-bomb

How to create a time bomb in Github actions that runs Ubuntu?


I have recently encountered an issue that I will need to address in the future. As a result, I am interested to create a time bomb in my CI workflow:

In computer software, a time bomb is part of a computer program that has been written so that it will start or stop functioning after a predetermined date or time is reached.

Here is what I have tried so far:

jobs:
  Test-Runner:
    runs-on: ubuntu-22.04
    steps:
      # Other steps ...
      - name: 'A timebomb to address an issue on the 01/05/2023'
        run: |
          if [[ $(date +%s) -gt 1682895600 ]]; then
            echo "It has been X months since #ISSUE was opened."
            echo "Please check if Y has been fixed."
            echo "  If it has, please update do Z."
            echo "  else, please increase this timebomb by 1 month."
            echo "See: ..."
          fi

I want this step to fail on the given date, is this possible using Github actions?


Solution

  • GitHub actions respect Linux exit codes, and set them to the action's check run status, which can be 'success' or 'failure'.

    From the documentation, Setting exit codes for actions:

    You can use exit codes to set the status of an action. GitHub displays statuses to indicate passing or failing actions.

    Like usual, 0 indicates success, and:

    Any other exit code indicates the action failed. When an action fails, all concurrent actions are canceled and future actions are skipped. The check run and check suite both get a failure status.

    Therefore doing something as simple as checking the current date and returning a non-zero exit code:

    jobs:
      Test-Runner:
        runs-on: ubuntu-22.04
        steps:
          # Other steps ...
          - name: 'A timebomb to address an issue on the 01/05/2023'
            run: |
              if [[ $(date +%s) -gt 1682895600 ]]; then
                echo "It has been X months since #ISSUE was opened."
                echo "Please check if Y has been fixed."
                echo "  If it has, please update do Z."
                echo "  else, please increase this timebomb by 1 month."
                echo "See: ..."
                exit 1 # <--- A non-zero exit code 
              fi
          - name: 'Uploading test artifacts'
            if: success() || failure()
    

    Will fail the CI on a given date. It is important note you will need to place this at the end of your test steps if you want other steps to run before failing the job. (perhaps just before uploading your test artifacts)