Skip to content

Commit

Permalink
Update github action exit codes (#17002)
Browse files Browse the repository at this point in the history
* Update github action exit codes

* Remove Filter Opened from github actions
  • Loading branch information
talldan authored Aug 13, 2019
1 parent 30482db commit 18b194a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
19 changes: 14 additions & 5 deletions .github/actions/assign-fixed-issues/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/bash
set -e

# 1. Find the issues that this PR 'fixes'.
# 1. Proceed only when acting on an opened pull request.

action=$(jq -r '.action' $GITHUB_EVENT_PATH)

if [ "$action" != 'closed' ]; then
echo "Action '$action' not a close action. Aborting."
exit 0;
fi

# 2. Find the issues that this PR 'fixes'.

issues=$(
jq -r '.pull_request.body' $GITHUB_EVENT_PATH | perl -nle 'print $1 while /
Expand All @@ -15,18 +24,18 @@ issues=$(

if [ -z "$issues" ]; then
echo "Pull request does not 'fix' any issues. Aborting."
exit 78
exit 0
fi

# 2. Grab the author of the PR.
# 3. Grab the author of the PR.

author=$(jq -r '.pull_request.user.login' $GITHUB_EVENT_PATH)

# 3. Loop through each 'fixed' issue.
# 4. Loop through each 'fixed' issue.

for issue in $issues; do

# 3a. Add the author as an asignee to the issue. This fails if the author is
# 4a. Add the author as an asignee to the issue. This fails if the author is
# already assigned, which is expected and ignored.

curl \
Expand Down
20 changes: 14 additions & 6 deletions .github/actions/first-time-contributor/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#!/bin/bash
set -e

# 1. Get the author and pr number for the pull request.
# 1. Proceed only when acting on an opened pull request.
action=$(jq -r '.action' $GITHUB_EVENT_PATH)

if [ "$action" != 'opened' ]; then
echo "Action '$action' not a close action. Aborting."
exit 0;
fi

# 2. Get the author and pr number for the pull request.
author=$(jq -r '.pull_request.user.login' $GITHUB_EVENT_PATH)
pr_number=$(jq -r '.number' $GITHUB_EVENT_PATH)

if [ "$pr_number" = "null" ] || [ "$author" = "null" ]; then
echo "Could not find PR number or author. $pr_number / $author"
exit 78
exit 0
fi

# 2. Fetch the author's commit count for the repo to determine if they're a first-time contributor.
# 3. Fetch the author's commit count for the repo to determine if they're a first-time contributor.
commit_count=$(
curl \
--silent \
Expand All @@ -19,13 +27,13 @@ commit_count=$(
| jq -r '.total_count'
)

# 3. If the response has a commit count of zero, exit early, the author is not a first time contributor.
# 4. If the response has a commit count of zero, exit early, the author is not a first time contributor.
if [ "$commit_count" != "0" ]; then
echo "Pull request #$pr_number was not created by a first-time contributor ($author)."
exit 78
exit 0
fi

# 4. Assign the 'First Time Contributor' label.
# 5. Assign the 'First Time Contributor' label.
curl \
--silent \
-X POST \
Expand Down
8 changes: 4 additions & 4 deletions .github/actions/milestone-it/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ action=$(jq -r '.action' $GITHUB_EVENT_PATH)

if [ "$action" != 'closed' ]; then
echo "Action '$action' not a close action. Aborting."
exit 78;
exit 0;
fi

merged=$(jq -r '.pull_request.merged' $GITHUB_EVENT_PATH)

if [ "$merged" != 'true' ]; then
echo "Pull request closed without merge. Aborting."
exit 78;
exit 0;
fi

base=$(jq -r '.pull_request.base.ref' $GITHUB_EVENT_PATH)

if [ "$base" != 'master' ]; then
echo 'Milestones apply only to master merge. Aborting.'
exit 78;
exit 0;
fi

# 2. Determine if milestone already exists (don't replace one which has already
Expand All @@ -39,7 +39,7 @@ current_milestone=$(

if [ "$current_milestone" != 'null' ]; then
echo 'Milestone already applied. Aborting.'
exit 78;
exit 0;
fi

# 3. Read current version.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
on: pull_request
name: Add the First-time Contributor label to PRs opened by first-time contributors
name: Add the First-time Contributor label
jobs:
filterOpened:
name: Filter opened
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Filter opened
uses: actions/bin/filter@0dbb077f64d0ec1068a644d25c71b1db66148a24
with:
args: action opened
- name: First Time Contributor
uses: ./.github/actions/first-time-contributor
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Filter opened
uses: actions/bin/filter@0dbb077f64d0ec1068a644d25c71b1db66148a24
with:
args: action opened
- name: Assign Fixed Issues
uses: ./.github/actions/assign-fixed-issues
env:
Expand Down

0 comments on commit 18b194a

Please sign in to comment.