Sikau

Project: Laptop to production · Day 2 · about 35 min

CI with a nightly log check

Tests on every push and PR, the log report on a schedule, and an alert on failure.

Robots that never forget

Your script is in the repository now (scripts/logreport.sh). Let GitHub Actions run the tests on every push and pull request — and run the log report every night on a schedule, raising an alert when it finds errors.

One workflow, different events

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  schedule:
    - cron: "0 2 * * *"
  workflow_dispatch:

jobs:
  test:
    if: github.event_name == 'push' || github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm test

  logs:
    if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Log report
        run: bash scripts/logreport.sh logs/app.log
      - name: Alert
        if: failure()
        run: echo "ALERT: errors found in logs/app.log"

The rest of this lesson

  • Choosing jobs by eventexplain
  • Alerts that people noticeexplain
  • Cronpredict
  • Which event runs what?match
  • Write the workflowwrite code
  • Badge quizquiz
  • What you builtrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 4 lessons of Project: Laptop to production