0

I want to trigger my UI tests on every 3rd Saturday of every month so that the application is tested after code is moved.

This is my current trigger:

on: 
  schedule:
    - cron:  '00 00 * * 6'
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Nandan N
  • 23
  • 4

1 Answers1

0

Your question is about the schedule event in the POSIX cron syntax which can only express every weekday:

on: schedule: - cron: '22 2 * * 6' # At 02:22, only on Saturday

As it runs every Saturday, it will run on every third Saturday as well.

If you can live with that, you can consider your question answered.

However, as a Posix cron expression does not support to specify the n-th Weekday in a month, it is common then to not execute the job if it is not the correct day. Within the crontab this could be with the command itself1, an option that is also available with a cron expression for a Microsoft Github Action Trigger, same same but different:

With jobs.<job_id>.if Expressions it is possible to formulate whether or not your job is being run.

As no date expressions exist for it but it can operate on the output of a previous job2, a previous job can take care of the shell expression for the third Saturday (if, and only if, it runs on a Saturday):

  - name: Get number of Saturday on a Saturday
    id: number-of-saturday-on-a-saturday
    run: >-
      printf >> "$GITHUB_OUTPUT"
      "VALUE=%s"
      "$((($(date +%d)-1)/7+1))" # (3)
  - name: Test Foo
    run: foo test
    if: steps.number-of-saturday-on-a-saturday.outputs.VALUE == 3

  1. Answer to How to schedule a cron for the first Thursday of every month?
  2. Answer to Get current date and time in GitHub workflows, the procedure has changed, currently see Example of setting an output parameter
  3. C.f. date(1) — Linux manual page and 2.5.4 Arithmetic Expansion - POSIX Shell Command Language
hakre
  • 193,403
  • 52
  • 435
  • 836