Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 2Naam in de cursus: Events that trigger workflows

Start workflows at the right time

The on: block decides when a workflow runs: on pushes to some branches, on pull requests, on a schedule, by hand, or when another workflow finishes. Filters keep pipelines fast and cheap.

  • 5 Lessen
  • 1 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

2.1

Run on push and pull request

The most used events. Filter by branch, tag and path.

.github/workflows/terraform.yml
on:
  push:
    branches: [main]
    tags: ["v*"]
    paths: ["envs/**", "modules/**"]
  pull_request:
    branches: [main]
    paths-ignore: ["docs/**", "**.md"]
FilterMeaning
branches / branches-ignoreOnly these / not these branches
tagsTag pushes, for releases
paths / paths-ignoreOnly when these files changed

Onthoud

pull_request runs the code of the PR in a safe context: secrets are not given to PRs from forks.

2.2

Run on a schedule

schedule uses cron syntax in UTC — for nightly scans, drift checks and reports.

.github/workflows/nightly.yml
on:
  schedule:
    - cron: "30 1 * * *"

Let op

Scheduled runs can start late at busy times, and they stop after 60 days without activity in a public repository.

2.3

Run by hand with inputs

workflow_dispatch adds a Run workflow button, with inputs you choose.

.github/workflows/deploy.yml
on:
  workflow_dispatch:
    inputs:
      environment:
        type: choice
        options: [staging, prod]
        default: staging
      dry_run:
        type: boolean
        default: true
 
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploying to ${{ inputs.environment }} (dry run ${{ inputs.dry_run }})"
gh workflow run deploy.yml -f environment=staging -f dry_run=false

Commando's in deze les

2.4

Chain workflows

workflow_run starts a workflow when another one finishes; workflow_call makes a workflow reusable (see Reuse workflows).

.github/workflows/deploy-after-ci.yml
on:
  workflow_run:
    workflows: [CI]
    types: [completed]
    branches: [main]
jobs:
  deploy:
    if: github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    steps:
      - run: echo "CI passed, deploying"

2.5

Know other useful events

Many GitHub events can start automation.

EventUse
release (types: [published])Build and upload release files
issues, issue_commentLabel or triage issues
merge_groupChecks for the merge queue
repository_dispatchStart from an outside system through the API
pull_request_targetRuns with secrets for PRs from forks — dangerous, see Secure your pipelines

Alle commando's in dit hoofdstuk