From d87f4e718311c3033f9dda4808b97ecf6e5c96ed Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Mon, 12 Aug 2019 16:15:41 +0800 Subject: [PATCH 1/2] Update github action exit codes --- .github/actions/assign-fixed-issues/entrypoint.sh | 2 +- .github/actions/first-time-contributor/entrypoint.sh | 4 ++-- .github/actions/milestone-it/entrypoint.sh | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/assign-fixed-issues/entrypoint.sh b/.github/actions/assign-fixed-issues/entrypoint.sh index c8c15d53d88f7..b21197f79250f 100755 --- a/.github/actions/assign-fixed-issues/entrypoint.sh +++ b/.github/actions/assign-fixed-issues/entrypoint.sh @@ -15,7 +15,7 @@ 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. diff --git a/.github/actions/first-time-contributor/entrypoint.sh b/.github/actions/first-time-contributor/entrypoint.sh index c775c4f615098..431786c5c21c2 100755 --- a/.github/actions/first-time-contributor/entrypoint.sh +++ b/.github/actions/first-time-contributor/entrypoint.sh @@ -7,7 +7,7 @@ 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. @@ -22,7 +22,7 @@ commit_count=$( # 3. 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. diff --git a/.github/actions/milestone-it/entrypoint.sh b/.github/actions/milestone-it/entrypoint.sh index 3c65671104e26..8c91df0cb05ff 100755 --- a/.github/actions/milestone-it/entrypoint.sh +++ b/.github/actions/milestone-it/entrypoint.sh @@ -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 @@ -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. From 45890eb7224a6de037c52c9730fab213cbfccb03 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 13 Aug 2019 11:23:13 +0800 Subject: [PATCH 2/2] Remove Filter Opened from github actions --- .../actions/assign-fixed-issues/entrypoint.sh | 17 +++++++++++++---- .../first-time-contributor/entrypoint.sh | 16 ++++++++++++---- ...to-prs-opened-by-first-time-contributors.yml | 6 +----- ...gn-fixed-issues-when-pull-request-opened.yml | 4 ---- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.github/actions/assign-fixed-issues/entrypoint.sh b/.github/actions/assign-fixed-issues/entrypoint.sh index b21197f79250f..83680fcc30877 100755 --- a/.github/actions/assign-fixed-issues/entrypoint.sh +++ b/.github/actions/assign-fixed-issues/entrypoint.sh @@ -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 / @@ -18,15 +27,15 @@ if [ -z "$issues" ]; then 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 \ diff --git a/.github/actions/first-time-contributor/entrypoint.sh b/.github/actions/first-time-contributor/entrypoint.sh index 431786c5c21c2..9360574ebe509 100755 --- a/.github/actions/first-time-contributor/entrypoint.sh +++ b/.github/actions/first-time-contributor/entrypoint.sh @@ -1,7 +1,15 @@ #!/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) @@ -10,7 +18,7 @@ if [ "$pr_number" = "null" ] || [ "$author" = "null" ]; then 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 \ @@ -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 0 fi -# 4. Assign the 'First Time Contributor' label. +# 5. Assign the 'First Time Contributor' label. curl \ --silent \ -X POST \ diff --git a/.github/workflows/pull_request-add-the-first-time-contributor-label-to-prs-opened-by-first-time-contributors.yml b/.github/workflows/pull_request-add-the-first-time-contributor-label-to-prs-opened-by-first-time-contributors.yml index d5b8fbbe2e07b..5c5bf75d0716e 100644 --- a/.github/workflows/pull_request-add-the-first-time-contributor-label-to-prs-opened-by-first-time-contributors.yml +++ b/.github/workflows/pull_request-add-the-first-time-contributor-label-to-prs-opened-by-first-time-contributors.yml @@ -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: diff --git a/.github/workflows/pull_request-assign-fixed-issues-when-pull-request-opened.yml b/.github/workflows/pull_request-assign-fixed-issues-when-pull-request-opened.yml index 2b4f0ac9ec4e7..bc39c69442425 100644 --- a/.github/workflows/pull_request-assign-fixed-issues-when-pull-request-opened.yml +++ b/.github/workflows/pull_request-assign-fixed-issues-when-pull-request-opened.yml @@ -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: