Skip to main content

CI/CD and automation · Beginner · 16 min

Run GitHub Actions workflows on a schedule and by hand with inputs

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · GitHub Actions · actionlint 1.7.12

You will have a site check workflow that runs every morning on a cron schedule, can be started by hand from the Actions tab or gh with typed inputs, and opens an issue through a second workflow whenever it fails.

On this page

Most workflows run because someone pushed. Some jobs have nothing to do with a push: checking every morning that your website still answers, renewing something weekly, or a task you want to start yourself with a couple of options, such as "check staging, and show me the response". GitHub Actions covers both with two triggers, schedule and workflow_dispatch, and a third, workflow_run, lets one workflow react when another finishes.

In this tutorial you build a small site check. A Bash script fetches a page and fails unless it answers with HTTP 200. A workflow runs it at 06:17 Lagos time every day, and also on demand with three typed inputs: which environment, which page, and whether to print the response. A second workflow watches the first and opens an issue when a run fails. The script runs on your machine first, against a local server, and actionlint checks every workflow before it goes near GitHub.

This is different from a crontab on a server, which the cron tutorial covers: here GitHub owns the clock and the machine, and you get logs and history in the Actions tab without running anything yourself.

Step 1 · Write the site check script and try it locally

Create a throwaway repository with a scripts/ folder:

Bash
mkdir -p ~/site-check-demo
cd ~/site-check-demo
git init -b main
mkdir -p scripts .github/workflows

The script reads its settings from environment variables, because that is how the workflow will pass them in. SITE_URL is the address of your site, PAGE the path to fetch, ATTEMPTS how many times to try before giving up, and VERBOSE whether to print the first lines of the response. A retry matters for a scheduled check: one dropped connection at 06:17 should not wake anyone up.

Bash
cat > scripts/check-site.sh <<'SH'
#!/usr/bin/env bash
# Fetches SITE_URL followed by PAGE and fails unless it answers 200 within ATTEMPTS tries.
set -euo pipefail

url="${SITE_URL:?SITE_URL is not set}${PAGE:-/health}"
attempts="${ATTEMPTS:-3}"
delay="${RETRY_DELAY:-10}"
body="$(mktemp)"
trap 'rm -f "$body"' EXIT

code=000
for attempt in $(seq 1 "$attempts"); do
  code="$(curl -sS -o "$body" -w '%{http_code}' --max-time 15 "$url" || true)"
  echo "Attempt $attempt of $attempts: $url answered $code"
  if [ "$code" = 200 ]; then
    break
  fi
  if [ "$attempt" -lt "$attempts" ]; then
    sleep "$delay"
  fi
done

if [ "${VERBOSE:-false}" = true ]; then
  echo "First lines of the response:"
  head -n 5 "$body"
fi

if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
  echo "- \`$url\` answered **$code**" >> "$GITHUB_STEP_SUMMARY"
fi

if [ "$code" != 200 ]; then
  echo "Site check failed: $url answered $code"
  exit 1
fi
echo "Site check passed: $url"
SH

When curl cannot connect at all, it reports the status as 000, so a site that is down and a site that answers 500 both fail the check. GITHUB_STEP_SUMMARY is a file GitHub provides in every job; anything written to it appears on the run's summary page.

Try the script against a small local server. Make a fake site with a health page, start Python's built-in web server on port 8471 in the background, and run the check:

Bash
mkdir -p fake-site
echo "ok" > fake-site/health
python3 -m http.server 8471 --bind 127.0.0.1 --directory fake-site > /dev/null 2>&1 &
SERVER_PID=$!
sleep 1

SITE_URL=http://127.0.0.1:8471 VERBOSE=true bash scripts/check-site.sh

Now ask for a page that does not exist, and a port where nothing listens. RETRY_DELAY=0 skips the wait between attempts so you are not kept waiting:

Bash
SITE_URL=http://127.0.0.1:8471 PAGE=/missing ATTEMPTS=2 RETRY_DELAY=0 bash scripts/check-site.sh || echo "The check failed, as it should (exit code $?)"
SITE_URL=http://127.0.0.1:8472 ATTEMPTS=2 RETRY_DELAY=0 bash scripts/check-site.sh || echo "The check failed, as it should (exit code $?)"
kill "$SERVER_PID"
rm -rf fake-site

Check it worked

The first run prints Attempt 1 of 3: http://127.0.0.1:8471/health answered 200, then ok under "First lines of the response", then Site check passed. The /missing run shows two attempts answering 404 and ends with Site check failed. The run on port 8472 shows a curl error saying it could not connect, and answered 000 twice. Both failures end with the line from echo, and the exit code is 1.

Step 2 · Run the workflow every morning with a cron schedule

A schedule trigger takes one or more cron expressions with five fields: minute, hour, day of the month, month and day of the week. GitHub reads them in UTC unless you say otherwise. Lagos is on West Africa Time, UTC+1 all year with no daylight saving, so 06:17 in Lagos is 05:17 UTC.

Bash
cat > .github/workflows/site-check.yml <<'YAML'
name: Site check

on:
  schedule:
    # 05:17 UTC every day, which is 06:17 in Lagos (UTC+1 all year).
    - cron: '17 5 * * *'

permissions:
  contents: read

jobs:
  check:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v7
      - name: Fetch the health page
        env:
          SITE_URL: ${{ vars.SITE_URL }}
        run: bash scripts/check-site.sh
YAML

Why 17 minutes past and not on the hour: GitHub queues scheduled runs, and the start of every hour is one of its busiest moments, so a 0 5 * * * job is more likely to start late. A run can be delayed at any time of day when load is high, so do not use a schedule for anything that must happen at an exact minute. Cron expressions are also limited to once every five minutes at most.

vars.SITE_URL is a configuration variable you set on GitHub in a later step. It is not a secret: the address of your own site is not sensitive, and variables show their values in the settings page, which makes mistakes easy to spot.

Some useful patterns, all in UTC:

  • '30 4 * * 1-5': 04:30 UTC, Monday to Friday.
  • '0 */6 * * *': every six hours, at 00:00, 06:00, 12:00 and 18:00.
  • '45 22 * * 0': 22:45 UTC every Sunday.

Check it worked

Bash
actionlint
echo "actionlint exit code: $?"

actionlint prints nothing and the exit code is 0. It also checks cron expressions. Change the hour to 25, which does not exist, and run it again:

Bash
sed 's/17 5 \* \* \*/17 25 * * */' .github/workflows/site-check.yml > /tmp/site-check-broken.yml
actionlint /tmp/site-check-broken.yml || echo "actionlint found the bad cron expression (exit code $?)"
rm /tmp/site-check-broken.yml

The broken copy fails with an error on the cron line saying the expression is invalid, and the original file is unchanged.

Step 3 · Know when a schedule will and will not run

A schedule behaves differently from a push trigger in four ways that catch people out:

  • It only runs from the default branch. GitHub reads the schedule from the workflow file on main (or whatever your default branch is) and runs the latest commit there. A schedule you add on a feature branch does nothing until it is merged.
  • It can start late. Minutes late is normal at busy times; treat the time as "around then".
  • It stops in quiet public repositories. In a public repository, GitHub turns scheduled workflows off after 60 days with no repository activity, such as a push. The workflow shows as disabled in the Actions tab. Turn it back on there, or with gh workflow enable "Site check".
  • Few people hear about a failure. GitHub sends notifications for scheduled workflows to the person who last changed the cron line in the workflow file, if their notification settings allow it. The last step in this tutorial opens an issue so the whole team sees it.

If you would rather write the time in Lagos time, GitHub.com accepts a timezone next to each cron entry, using an IANA time zone name. actionlint 1.7.12 checks the name. Try it in a scratch file:

Bash
cat > /tmp/schedule-lagos.yml <<'YAML'
name: Schedule in local time
on:
  schedule:
    - cron: '17 6 * * *'
      timezone: Africa/Lagos
jobs:
  hello:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
      - run: echo "06:17 in Lagos"
YAML
actionlint /tmp/schedule-lagos.yml
echo "actionlint exit code: $?"
rm /tmp/schedule-lagos.yml

A time zone matters most where clocks change. For a team in London, Europe/London keeps a 07:00 job at 07:00 local time through summer and winter, where a plain UTC cron would drift by an hour twice a year. This tutorial keeps plain UTC in the real workflow, because it also works on older GitHub Enterprise Server versions and older linters.

Check it worked

actionlint exits with 0 for the scratch file. Now write down, for your own site, the local time you want the check to run and its UTC equivalent, and confirm the cron line in site-check.yml matches. For Lagos, Accra is UTC+0, Nairobi UTC+3 and Johannesburg UTC+2, all without daylight saving.

Step 4 · Add a Run workflow button with typed inputs

workflow_dispatch adds a Run workflow button to the Actions tab and lets the GitHub CLI and API start the workflow. Inputs turn it into a small form. Each input has a type: string, number, boolean, choice (a fixed list of options) or environment (a dropdown of the environments set up in your repository).

Replace the workflow with one that has both triggers and three inputs:

Bash
cat > .github/workflows/site-check.yml <<'YAML'
name: Site check

on:
  schedule:
    # 05:17 UTC every day, which is 06:17 in Lagos (UTC+1 all year).
    - cron: '17 5 * * *'
  workflow_dispatch:
    inputs:
      target:
        description: Environment to check
        type: environment
        required: true
        default: production
      page:
        description: Page to fetch
        type: choice
        options:
          - /health
          - /
        default: /health
      verbose:
        description: Print the first lines of the response
        type: boolean
        default: false

permissions:
  contents: read

jobs:
  check:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    environment: ${{ inputs.target || 'production' }}
    steps:
      - uses: actions/checkout@v7
      - name: Fetch the page
        env:
          SITE_URL: ${{ vars.SITE_URL }}
          PAGE: ${{ inputs.page || '/health' }}
          VERBOSE: ${{ inputs.verbose }}
        run: bash scripts/check-site.sh
YAML

How the pieces fit:

  • On a scheduled run there are no inputs, so inputs.target is empty. The || gives the default: production for the environment and /health for the page. inputs.verbose is empty too, which the script treats as false. Keep the defaults in the two places in line with each other.
  • environment: on the job makes vars.SITE_URL come from that environment. You set one SITE_URL for staging and another for production, and the same workflow checks either.
  • If you protect the production environment with required reviewers, every scheduled run waits for approval. Leave this environment unprotected, or use a separate one for checks.
  • Read inputs through the inputs context. github.event.inputs holds the same values, but turns booleans into the strings 'true' and 'false', which is an easy way to write a condition that is always true.
  • Inputs reach the script through env:, not by pasting ${{ inputs.page }} into the run: line. A choice input is safe either way, but the habit protects you when you later add a free-text string input.

A workflow can have up to 25 inputs. If you need more than a handful, the job probably wants splitting.

Check it worked

Bash
actionlint
echo "actionlint exit code: $?"

Exit code 0. Then run the script the way a manual run with page set to / and verbose ticked would, against a local server:

Bash
mkdir -p fake-site
echo "<h1>Home</h1>" > fake-site/index.html
python3 -m http.server 8473 --bind 127.0.0.1 --directory fake-site > /dev/null 2>&1 &
SERVER_PID=$!
sleep 1
SITE_URL=http://127.0.0.1:8473 PAGE=/ VERBOSE=true bash scripts/check-site.sh
kill "$SERVER_PID"
rm -rf fake-site

The output shows answered 200, the <h1>Home</h1> line, and Site check passed: http://127.0.0.1:8473/. If you see answered 000, the server had not started yet; run the check line again.

Step 5 · Push, set the site address and start a run with gh

Commit the work and push it to your GitHub repository. Replace YOUR-USER/YOUR-REPO with your repository:

Bash
git add .
git commit -m "Add a scheduled and manual site check"
Bash
git remote add origin git@github.com:YOUR-USER/YOUR-REPO.git
git push -u origin main

Create two environments, staging and production, under Settings, then Environments, in your repository. Then give each its own SITE_URL. Replace the addresses with your own sites, with no trailing slash:

Bash
gh variable set SITE_URL --env production --body "https://example.com"
gh variable set SITE_URL --env staging --body "https://staging.example.com"

Start a manual run. -f passes one input as name=value; the values are sent as text and GitHub converts them to each input's type:

Bash
gh workflow run site-check.yml -f target=staging -f page=/ -f verbose=true
gh run list --workflow site-check.yml --limit 3

Run gh workflow run site-check.yml with no -f flags and the defaults apply. Run plain gh workflow run and gh asks which workflow and prompts for each input. To start the workflow from a branch other than the default, add --ref your-branch; the workflow file must also exist on the default branch for the trigger to work at all.

Check it worked

gh run list shows a run of Site check with the event workflow_dispatch. Open it with gh run watch or in the Actions tab: the job is called check, it deployed to the staging environment, the log shows your staging address answering 200 followed by the first lines of your home page, and the summary page shows the same address and code. In the Actions tab, the Site check workflow now has a Run workflow button with a dropdown for the environment, a dropdown for the page and a tick box for verbose. The next morning, a run with the event schedule appears a little after 05:17 UTC.

Step 6 · Open an issue when a run fails, with workflow_run

A failed scheduled run is easy to miss. You could add a step at the end of the check that opens an issue, but that gives the check job permission to write issues. A separate workflow, triggered by workflow_run when the check finishes, keeps the check read-only and puts the alerting in one place you can reuse for other workflows later.

Write the script that composes the issue text first, so you can test it locally:

Bash
cat > scripts/describe-run.sh <<'SH'
#!/usr/bin/env bash
# Writes issue-title.txt and issue-body.md describing a finished workflow run.
set -euo pipefail
: "${WORKFLOW_NAME:?}" "${CONCLUSION:?}" "${TRIGGER:?}" "${RUN_URL:?}"

printf '%s\n' "$WORKFLOW_NAME: $CONCLUSION on $(date -u +%Y-%m-%d)" > issue-title.txt
cat > issue-body.md <<EOF
The **$WORKFLOW_NAME** workflow ended with **$CONCLUSION**.

- Started by: $TRIGGER
- Run log: $RUN_URL

Close this issue once the site is answering again.
EOF
cat issue-title.txt issue-body.md
SH

WORKFLOW_NAME="Site check" CONCLUSION=failure TRIGGER=schedule \
  RUN_URL=https://github.com/YOUR-USER/YOUR-REPO/actions/runs/123 \
  bash scripts/describe-run.sh
rm issue-title.txt issue-body.md

Now the alert workflow:

Bash
cat > .github/workflows/site-check-alert.yml <<'YAML'
name: Site check alert

on:
  workflow_run:
    workflows: [Site check]
    types: [completed]

permissions:
  contents: read
  issues: write

jobs:
  open-issue:
    if: github.event.workflow_run.conclusion == 'failure'
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v7
      - name: Write the issue text
        env:
          WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
          CONCLUSION: ${{ github.event.workflow_run.conclusion }}
          TRIGGER: ${{ github.event.workflow_run.event }}
          RUN_URL: ${{ github.event.workflow_run.html_url }}
        run: bash scripts/describe-run.sh
      - name: Open the issue
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
        run: gh issue create --title "$(cat issue-title.txt)" --body-file issue-body.md
YAML

What to know about workflow_run:

  • workflows: lists workflows by their name:, not their file name. Rename Site check and the alert silently stops; keep the two in step.
  • types: [completed] fires once the check finishes, whatever the result. The if: on the job keeps only failures, so a passing run shows the alert workflow as skipped. The other types are requested and in_progress.
  • Like schedule, it only works when the alert workflow file is on the default branch, and it runs that branch's version of the file.
  • workflow_run can chain at most three levels of workflows. An alert on an alert on a check is the limit.
  • The alert's token can write issues even when the check was started by something with fewer rights. Here the check only runs from a schedule or a person with write access, so that is fine. Be more careful with workflow_run after pull request workflows from forks, which the hardening tutorial covers.

If your site stays down for a week, this opens one issue per failed run. That is noisy on purpose; close them as you fix the cause, or extend the script to look for an open issue first with gh issue list.

Check it worked

Bash
actionlint
echo "actionlint exit code: $?"
git add .
git commit -m "Open an issue when the site check fails"
git log --oneline

The test run of describe-run.sh printed a title like Site check: failure on 2026-11-18 and a body with the trigger and the run link. actionlint exits with 0, and git log --oneline shows two commits.

Push with git push, then prove the alert on GitHub. Temporarily point staging at an address that will fail, start a check, and put it back. Replace the addresses with your own:

Bash
gh variable set SITE_URL --env staging --body "https://staging.example.com/this-path-does-not-exist"
gh workflow run site-check.yml -f target=staging

Within a few minutes the Site check run fails, a Site check alert run starts with the event workflow_run, and a new issue titled Site check: failure on today's date appears in the Issues tab. Set SITE_URL for staging back to its real address afterwards. If you read GitHub's notification emails on a phone with prepaid data, one short issue per failure is cheaper to load than opening run logs.

When you have finished with the practice copy on your computer, remove it with rm -rf ~/site-check-demo. The workflows on GitHub keep running until you delete the files there or disable the workflow with gh workflow disable "Site check".

Bash
rm -rf ~/site-check-demo

Next steps

  • Go back over the basics of workflow files and actionlint: /tutorials/github-actions-first-workflow
  • Compare a server crontab, where you own the machine and the clock: /tutorials/schedule-jobs-with-cron
  • Move the alert job into a reusable workflow that other checks can call: /tutorials/write-reusable-workflows-and-composite-actions

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.