Abstract PR scrub action so it can be used in two places (#39329)

* Abstract PR scrub action so it can be used in two places

* Rename composite action; add newline
This commit is contained in:
jonathansadowski 2023-07-21 02:09:46 +07:00 committed by GitHub
parent 147db933be
commit bfedd049c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 21 deletions

View File

@ -0,0 +1,38 @@
name: Send PRs that require further testing to Slack
permissions: {}
inputs:
TEST_ASSISTANCE_BOT_TOKEN:
default: ''
WOO_PR_TESTING_ANALYSIS_SLACK_CHANNEL:
default: ''
WOO_PR_TESTING_ANALYSIS_TEAM_ID:
default: ''
runs:
using: composite
steps:
- name: Get the PR status
id: get_pr_status
shell: bash
run: |
pr_status=${{ github.event.pull_request.merged == true && 'merged' || 'open' }}
echo "pr_status=$pr_status" >> $GITHUB_OUTPUT
- name: Calculate SLA timestamp
id: calculate_sla
shell: bash
run: |
sla_timestamp=$(date -d "+ 5 hours" -u +%s)
echo "sla_timestamp=$sla_timestamp" >> $GITHUB_OUTPUT
- name: Notify Slack
uses: archive/github-actions-slack@d9dae40827adf93bddf939db6552d1e392259d7d
id: notify
with:
slack-bot-user-oauth-access-token: ${{ inputs.TEST_ASSISTANCE_BOT_TOKEN }}
slack-channel: ${{ inputs.WOO_PR_TESTING_ANALYSIS_SLACK_CHANNEL }}
slack-text: |
<!subteam^${{ inputs.WOO_PR_TESTING_ANALYSIS_TEAM_ID }}>, there is a new *${{ steps.get_pr_status.outputs.pr_status }}* PR to analyze.
<${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}> :thread:
*SLA:* <!date^${{ steps.calculate_sla.outputs.sla_timestamp }}^{date_short_pretty} at {time}|5 hours from now>
slack-optional-unfurl_links: false
slack-optional-unfurl_media: false

View File

@ -51,3 +51,17 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: 'needs: analysis'
- uses: actions/checkout@v3
with:
sparse-checkout: |
.github/actions/pr-scrub-notify-slack
ref: trunk
- name: 'Trigger PR scrub'
if: |
github.event.pull_request.base.ref == 'trunk' &&
! contains(github.event.pull_request.labels.*.name, 'needs: analysis')
uses: ./.github/actions/pr-scrub-notify-slack
with:
TEST_ASSISTANCE_BOT_TOKEN: ${{ secrets.TEST_ASSISTANCE_BOT_TOKEN }}
WOO_PR_TESTING_ANALYSIS_SLACK_CHANNEL: ${{ secrets.WOO_PR_TESTING_ANALYSIS_SLACK_CHANNEL }}
WOO_PR_TESTING_ANALYSIS_TEAM_ID: ${{ secrets.WOO_PR_TESTING_ANALYSIS_TEAM_ID }}

View File

@ -10,25 +10,15 @@ jobs:
if: "${{ github.event.label.name == 'needs: analysis' && (github.event.pull_request.state == 'open' || github.event.pull_request.merged) }}"
runs-on: ubuntu-20.04
steps:
- name: Get the PR status
id: get_pr_status
run: |
pr_status=${{ github.event.pull_request.merged == true && 'merged' || 'open' }}
echo "pr_status=$pr_status" >> $GITHUB_OUTPUT
- name: Calculate SLA timestamp
id: calculate_sla
run: |
sla_timestamp=$(date -d "+ 5 hours" -u +%s)
echo "sla_timestamp=$sla_timestamp" >> $GITHUB_OUTPUT
- name: Notify Slack
uses: archive/github-actions-slack@d9dae40827adf93bddf939db6552d1e392259d7d
id: notify
- uses: actions/checkout@v3
with:
slack-bot-user-oauth-access-token: ${{ secrets.TEST_ASSISTANCE_BOT_TOKEN }}
slack-channel: ${{ secrets.WOO_PR_TESTING_ANALYSIS_SLACK_CHANNEL }}
slack-text: |
<!subteam^${{ secrets.WOO_PR_TESTING_ANALYSIS_TEAM_ID }}>, there is a new *${{ steps.get_pr_status.outputs.pr_status }}* PR to analyze.
<${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}> :thread:
*SLA:* <!date^${{ steps.calculate_sla.outputs.sla_timestamp }}^{date_short_pretty} at {time}|5 hours from now>
slack-optional-unfurl_links: false
slack-optional-unfurl_media: false
sparse-checkout: |
.github/actions/pr-scrub-notify-slack
ref: trunk
- name: 'Trigger PR scrub'
uses: ./.github/actions/pr-scrub-notify-slack
with:
TEST_ASSISTANCE_BOT_TOKEN: ${{ secrets.TEST_ASSISTANCE_BOT_TOKEN }}
WOO_PR_TESTING_ANALYSIS_SLACK_CHANNEL: ${{ secrets.WOO_PR_TESTING_ANALYSIS_SLACK_CHANNEL }}
WOO_PR_TESTING_ANALYSIS_TEAM_ID: ${{ secrets.WOO_PR_TESTING_ANALYSIS_TEAM_ID }}