woocommerce/.github/workflows/new-cfe-prr-notifications.yml

232 lines
8.6 KiB
YAML

name: New CFE/PRR workflow notifications
on:
issues:
types: [labeled]
permissions: {}
jobs:
prep:
if: github.event.label.name == 'Approved' || github.event.label.name == 'Rejected'
runs-on: ubuntu-20.04
outputs:
release_number: ${{ steps.extract-release.outputs.RELEASE_NUMBER }}
steps:
- name: Extract Release Number from Issue Body
id: extract-release
uses: actions/github-script@v7
with:
script: |
const body = context.payload.issue.body; // Accessing the issue body directly from the context
// Regular expression to match the release number after the specific question
const releaseRegex = /Which release does this request apply to\?.*?\n([0-9]+\.[0-9]+)/s;
// Match the body against the regex
const match = body.match(releaseRegex);
// Check if a valid release number was found
if (match && match[1]) {
const releaseNumber = match[1];
// Log the release number and set it as a GitHub output
console.log(`Valid release number: ${releaseNumber}`);
core.setOutput('RELEASE_NUMBER', releaseNumber);
} else {
// If no valid release number is found, fail the step
core.setFailed("No valid release number found after the 'Which release does this request apply to?' section. Aborting.");
}
cfe-created:
if: github.event.label.name == 'code freeze exception' || github.event.label.name == 'point release request'
runs-on: ubuntu-20.04
steps:
- name: Set Slack Message
id: set-message
uses: actions/github-script@v7
with:
script: |
const event = context.payload;
const labelName = event.label?.name;
const issueTitle = event.issue.title;
const issueUrl = event.issue.html_url;
let message = '';
// Determine the type of message based on the label name
if (labelName === 'code freeze exception') {
message = `:arrow_right: New CFE request: ${issueTitle} ${issueUrl}`;
} else {
message = `:arrow_right: New PRR request: ${issueTitle} ${issueUrl}`;
}
// Set the message as a core output
core.setOutput('SLACK_MESSAGE', message);
- name: Notify Slack
uses: archive/github-actions-slack@v2.0.0
id: notify
with:
slack-bot-user-oauth-access-token: ${{ secrets.CODE_FREEZE_BOT_TOKEN }}
slack-channel: ${{ secrets.WOO_RELEASE_SLACK_CHANNEL }}
slack-text: ${{ steps.set-message.outputs.SLACK_MESSAGE }}
slack-optional-unfurl_links: false
slack-optional-unfurl_media: false
continue-on-error: true
request-approved:
if: ${{ github.event.label.name == 'Approved' }}
runs-on: ubuntu-20.04
needs:
- prep
permissions:
pull-requests: write
issues: write
steps:
- name: Extract PR number from issue body
id: extract-pr
uses: actions/github-script@v7
with:
script: |
const body = context.payload.issue.body;
// Regular expression to match the PR link that follows the specific question
const prRegex = /Which PR needs to be included\?.*?\n(https:\/\/github\.com\/[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+\/pull\/([0-9]+))/s;
// Match the body against the regex
const match = body.match(prRegex);
// Check if a valid PR number was found
if (match && match[2]) {
const prNumber = match[2];
// Log the PR number and set it as a GitHub output
console.log(`Valid PR number: ${prNumber}`);
core.setOutput('PR_NUMBER', prNumber);
} else {
// If no valid PR number is found, fail the step
core.setFailed("No valid PR found after the 'Which PR' section. Aborting.");
}
- name: Add label 'cherry pick to trunk' to PR
env:
OWNER: ${{ github.event.repository.owner.login }}
REPO: ${{ github.event.repository.name }}
PR_NUMBER: ${{ steps.extract-pr.outputs.PR_NUMBER }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr edit $PR_NUMBER --add-label "cherry pick to trunk" --repo "$OWNER/$REPO"
- name: Add label 'cherry pick to frozen release' to PR
if: contains(github.event.issue.labels.*.name, 'point release request')
env:
OWNER: ${{ github.event.repository.owner.login }}
REPO: ${{ github.event.repository.name }}
PR_NUMBER: ${{ steps.extract-pr.outputs.PR_NUMBER }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr edit $PR_NUMBER --add-label "cherry pick to frozen release" --repo "$OWNER/$REPO"
- name: Apply Milestone to the Issue
env:
MILESTONE: ${{ needs.prep.outputs.release_number }}.0
ISSUE_URL: ${{ github.event.issue.html_url }}
GH_TOKEN: ${{ github.token }}
run: |
echo "Applying milestone: $MILESTONE"
gh issue edit "$ISSUE_URL" --milestone "$MILESTONE"
- name: Comment issue has been approved
env:
ISSUE_URL: ${{ github.event.issue.html_url }}
GH_TOKEN: ${{ github.token }}
run: |
gh issue comment "$ISSUE_URL" --body "This request has been approved. Please merge the PR to release branch."
- name: Set Slack Message
id: set-message
uses: actions/github-script@v7
with:
script: |
const event = context.payload; // Accessing the event directly from the context
const labelName = event.label?.name;
const issueTitle = event.issue.title;
const issueUrl = event.issue.html_url;
let message = '';
if (labelName === 'code freeze exception') {
message = `:white_check_mark: CFE request approved: ${issueTitle} ${issueUrl}`;
} else {
message = `:white_check_mark: PRR request approved: ${issueTitle} ${issueUrl}`;
}
core.setOutput('SLACK_MESSAGE', message);
- name: Notify Slack
uses: archive/github-actions-slack@v2.0.0
id: notify
with:
slack-bot-user-oauth-access-token: ${{ secrets.CODE_FREEZE_BOT_TOKEN }}
slack-channel: ${{ secrets.WOO_CORE_RELESES_DAILY_SLACK_CHANNEL }}
slack-text: ${{ steps.set-message.outputs.SLACK_MESSAGE }}
slack-optional-unfurl_links: false
slack-optional-unfurl_media: false
continue-on-error: true
request-rejected:
if: ${{ github.event.label.name == 'Rejected' }}
runs-on: ubuntu-20.04
needs:
- prep
permissions:
issues: write
steps:
- name: Apply Milestone to the Issue
env:
MILESTONE: ${{ needs.prep.outputs.release_number }}.0
ISSUE_URL: ${{ github.event.issue.html_url }}
GH_TOKEN: ${{ github.token }}
run: |
echo "Applying milestone: $MILESTONE"
gh issue edit "$ISSUE_URL" --milestone "$MILESTONE"
- name: Close the request
env:
ISSUE_URL: ${{ github.event.issue.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh issue close "$ISSUE_URL" --comment "Closing issue the request is rejected - $ISSUE_URL. Please switch the base to trunk and merge."
- name: Set Slack Message
id: set-message
uses: actions/github-script@v7
with:
script: |
const event = context.payload;
const labelName = event.label?.name;
const issueTitle = event.issue.title;
const issueUrl = event.issue.html_url;
let message = '';
if (labelName === 'code freeze exception') {
message = `:x: CFE request rejected: ${issueTitle} ${issueUrl}`;
} else {
message = `:x: PRR request rejected: ${issueTitle} ${issueUrl}`;
}
core.setOutput('SLACK_MESSAGE', message);
- name: Notify Slack
uses: archive/github-actions-slack@v2.0.0
id: notify
with:
slack-bot-user-oauth-access-token: ${{ secrets.CODE_FREEZE_BOT_TOKEN }}
slack-channel: ${{ secrets.WOO_CORE_RELESES_DAILY_SLACK_CHANNEL }}
slack-text: ${{ steps.set-message.outputs.SLACK_MESSAGE }}
slack-optional-unfurl_links: false
slack-optional-unfurl_media: false
continue-on-error: true