Create GitHub issues on a schedule#

In post Custom GitHub templates for issues, the first step was made to automate the workflow more by defining issue templates on the organizational level and assigning labels when creating a new issue. A human still needs to create the issue manually while some issues must be created on a schedule to deploy new certificates or run an Ansible playbook to patch servers for example.

Like in post Start using GitHub Dependabot where merge requests were automatically created for updated dependencies, issues can also be created on a schedule. Let’s create a workflow that creates an issue every month for recurring maintenance that must be done.

GitHub Actions on a schedule#

GitHub Actions supports different triggers and one of its triggers is called schedule which allows starting a workflow at a specific time. In the example below we start the workflow every first day of the month at 8 AM sharp. The syntax to specify the time follows the implementation of cron in Linux.

Example workflow file .github/workflows/patch-reminder.yml#
 1---
 2name: Create patch issue
 3
 4on:
 5  schedule:
 6    - cron: "0 8 1 * *"
 7
 8permissions:
 9  contents: read
10  issues: write
11
12jobs:
13  create-issue:
14    name: Create an issues
15    runs-on: ubuntu-latest
16    steps:
17      - name: Checkout Code
18        uses: actions/[email protected]
19
20      - name: Create an issue
21        uses: JasonEtco/[email protected]
22        env:
23          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24        with:
25          update_existing: false
26          filename: .github/patch-issue-template.md

The job to create an issue relies on a third-party action called JasonEtco/create-an-issue that needs write permissions to create or update issues. This GitHub Action can update existing issues, but also create new ones. In our example pipeline we create a new issue every month and are using file .github/patch-issue-template.md as a template for this.

Warning

The cron implementation used by GitHub Actions doesn’t support extensions like @daily or @weekly for example.

Template autonomy for create-an-issue#

GitHub Action JasonEtco/create-an-issue takes a template file and supports some basic Jinja2 filters that are applied when an issue is created. This way a unique issue is generated every month and supports similar keys as in post Custom GitHub templates for issues to directly assign the issue and to apply labels.

Example template .github/patch-issue-template.md#
 1---
 2title: Monthly maintenance for {{ date | date('MMMM YYYY') }}
 3assignees: user01
 4labels: infrastructure
 5---
 6Monthly maintenance cycle for {{ date | date('MMMM YYYY') }}
 7
 8Actions:
 9- [ ]  Install all patches
10- [ ]  Reboot all servers
11- [ ]  Deploy Ansible site.yml to validate the state
12- [ ]  Update all certificates that will expire

With this, a new issue will be created on the first day of every month, assigned to user01, and will have label infrastructure. The issue can be used to create new related issues as it has a checklist or to just mark tasks as done.