GitHub Actions 1 cheatsheet
GitHub Actions 1: Workflow basics
7 common GitHub Actions 1 tasks.
Minimal workflow
A workflow file in .github/workflows/ that runs tests on every push and pull request.
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
Run only when certain files change
Limit a trigger to changes under given paths.
on:
push:
paths:
- "src/**"
- "package.json"
Run on a schedule
Run at 03:00 UTC every day. Scheduled times use UTC cron syntax.
on:
schedule:
- cron: "0 3 * * *"
Run manually with inputs
Add a Run workflow button with an input.
on:
workflow_dispatch:
inputs:
environment:
description: Where to deploy
required: true
default: staging
Run several commands
Use a block scalar to run a multi-line script in one step.
- run: |
npm ci
npm run build
Set a job timeout
Stop a job that hangs, instead of waiting for the six-hour default.
jobs:
test:
timeout-minutes: 15