Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 22aeec4

Browse files
committed
Add action to filter on base branch.
This will be used to filter pull request events depending on which branch they're targeting.
1 parent 7707c41 commit 22aeec4

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

base-branch-filter/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM alpine:latest
2+
3+
LABEL "com.github.actions.name"="base branch filter"
4+
LABEL "com.github.actions.description"="Filters pull request events based on their base branch."
5+
LABEL "com.github.actions.icon"="filter"
6+
LABEL "com.github.actions.color"="purple"
7+
8+
LABEL "repository"="https://github.com/hashicorp/terraform-github-actions"
9+
LABEL "homepage"="http://github.com/hashicorp/terraform-github-actions"
10+
LABEL "maintainer"="HashiCorp Terraform Team <[email protected]>"
11+
12+
RUN apk --no-cache add jq
13+
14+
COPY entrypoint.sh /entrypoint.sh
15+
ENTRYPOINT ["/entrypoint.sh"]

base-branch-filter/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Base Branch Filter
2+
Filters pull request events depending on the base branch
3+
The base branch is the branch that the pull request will be merged into.
4+
5+
To use, set `args` to a regular expression that
6+
will be matched against the destination branch.
7+
8+
Note: This action only works on pull request events.
9+
10+
## Example
11+
Filter on pull requests that have been merged into `master`:
12+
```hcl
13+
workflow "example" {
14+
resolves = "base-branch-filter"
15+
# Must be used on pull_request events.
16+
on = "pull_request"
17+
}
18+
19+
# First we use another filter to filter to only merged events.
20+
action "merged-prs-filter" {
21+
uses = "actions/bin/filter@master"
22+
args = "merged true"
23+
}
24+
25+
# Then we use this filter to ensure the branch matches "master".
26+
action "base-branch-filter" {
27+
uses = "hashicorp/terraform-github-actions/base-branc-filter@master"
28+
# We set args to our regex.
29+
args = "^master$"
30+
needs = "merged-prs-filter"
31+
}
32+
```

base-branch-filter/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
regex="$*"
6+
base_branch=$(jq -r .pull_request.base.ref "$GITHUB_EVENT_PATH")
7+
8+
if "$actual" | grep -q "$regex"; then
9+
echo "base branch \"$base_branch\" does not match \"$regex\""
10+
exit 78
11+
fi

0 commit comments

Comments
 (0)