Skip to content

Commit

Permalink
chore(05-filters-activity-types): add README
Browse files Browse the repository at this point in the history
  • Loading branch information
lauromueller committed Nov 3, 2023
1 parent 164449f commit 4d6dd8b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/05-1-filters-activity-types.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# See 05-filters-activity-types/README.md for more information
# about filtering and specifying activity types for events.

name: 05 - 1 - Event Filters and Activity Types

on:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/05-2-filters-activity-types.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# See 05-filters-activity-types/README.md for more information
# about filtering and specifying activity types for events.

name: 05 - 2 - Event Filters and Activity Types

on:
Expand Down
90 changes: 90 additions & 0 deletions 05-filters-activity-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Using Event Filters and Activity Types

GitHub Actions workflows are highly customizable and can be triggered by various events and activities. In this guide, we'll explore how to use event filters and activity types to precisely control when your workflows run.

## Introduction

GitHub Actions allows you to automate your workflows based on specific events and activities. By defining event filters and activity types in your workflow configuration, you can precisely control when your actions run.

## Event Filters

### Using `on`

You can specify when a workflow should run by using the `on` keyword in your workflow YAML file. This is the primary way to define the event that triggers your workflow.

```yaml
on:
push:
branches:
- main
```
In this example, the workflow is triggered on a push event to the main branch.
### Filtering by Event Types
GitHub Actions supports a wide range of event types, such as push, pull_request, release, and more. You can filter your workflow by these event types.
```yaml
on:
push:
branches:
- main
```
### Filtering by Branches
You can further narrow down your workflow's trigger by specifying the branches on which the event should occur.
```yaml
on:
push:
branches:
- main
- feature/*
```
Here, the workflow runs on a push event to either the main branch or branches starting with "feature/."
### Filtering by Paths
If you want to trigger your workflow only when specific files or directories are modified, you can filter by paths.
```yaml
on:
push:
paths:
- 'src/**'
- 'docs/'
```
This workflow is triggered on a push event that modifies files under the src/ directory or any file or folder in the docs/ directory.
### Filtering by Tags
You can also use tags to trigger your workflow when specific tags are created.
```yaml
on:
push:
tags:
- v*
```
In this example, the workflow runs when a tag starting with "v" is pushed.
## Activity Types
GitHub Actions provides several activity types per event. The best place to find a comprehensive list of all available activity types is the [GitHub Actions documentation](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows).
### Pull Request Activity Types
Pull requests offer a variety of activity types. The example below filters the activity types down to `opened` and `synchronize`. This means that the workflow will trigger when a pull request is opened, or when a new commit is pushed to the `head` of the PR branch:

```yaml
on:
pull_request:
types:
- opened
- synchronize
```

0 comments on commit 4d6dd8b

Please sign in to comment.