diff --git a/.github/workflows/cicd_scheduled_notify-seated-prs.yml b/.github/workflows/cicd_scheduled_notify-seated-prs.yml index 61b174cde97f..14ae851f3606 100644 --- a/.github/workflows/cicd_scheduled_notify-seated-prs.yml +++ b/.github/workflows/cicd_scheduled_notify-seated-prs.yml @@ -3,6 +3,12 @@ on: schedule: - cron: '0 10 * * *' workflow_dispatch: + inputs: + current_user: + description: 'Limit execution of this workflow to the current user' + type: string + required: false + default: U0125JCDSSE env: PR_DAY_THRESHOLD: 3 DRAFT_PR_DAY_THRESHOLD: 5 @@ -20,6 +26,7 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} - name: Filter execution + id: filter-execution uses: actions/github-script@v7 with: result-encoding: string @@ -28,11 +35,13 @@ jobs: console.log(new Date()); if (day === 0 || day === 6) { console.log('It\'s (happy) weekend, not sending any notifications'); - process.exit(1); + process.exit(0); } + + core.setOutput('continue', 'true'); - id: fetch-seated-prs name: Fetch Seated PRs - if: success() + if: success() && steps.filter-execution.outputs.continue == 'true' uses: actions/github-script@v7 with: result-encoding: string @@ -146,23 +155,25 @@ jobs: with: result-encoding: string script: | + const member = '${{ matrix.member }}'; const urlMapper = (pr) => `- ${pr.url}`; - const prDayThreshold = ${{ env.PR_DAY_THRESHOLD }}; const draftPrDayThreshold = ${{ env.DRAFT_PR_DAY_THRESHOLD }}; const seatedPrs = ${{ needs.resolve-seated-prs.outputs.seated_prs }} + const mappings = ${{ needs.slack-channel-resolver.outputs.mappings_json }}; + + const foundMapping = mappings.find(mapping => mapping.slack_id === member) + if (!foundMapping) { + core.warning(`Slack user Id [${member}] cannot be found, exiting`); + process.exit(0); + } + const members = ${{ needs.resolve-seated-prs.outputs.members_json }} const channels = ${{ needs.slack-channel-resolver.outputs.channel_ids }} console.log(JSON.stringify(members, null, 2)); console.log(JSON.stringify(channels, null, 2)); - const idx = channels.findIndex(channel => channel === '${{ matrix.member }}'); - if (idx === -1) { - console.log('Could not find channel [${{ matrix.member }}], skipping this'); - process.exit(2); - } - - const login = members[idx]; + const login = foundMapping.github_user; const userPrs = seatedPrs.find(pr => pr.login === login); const prs = userPrs.prs.filter(pr => !pr.draft).map(urlMapper); const draftPrs = userPrs.prs.filter(pr => pr.draft).map(urlMapper); @@ -183,14 +194,17 @@ jobs: core.setOutput('message', message); - name: Notify member - if: success() + if: success() && steps.build-message.outputs.message != '' shell: bash run: | channel=${{ matrix.member }} - - curl -X POST \ - -H "Content-type: application/json" \ - -H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" \ - -d "{ \"channel\":\"${channel}\",\"text\":\"${{ steps.build-message.outputs.message }}\"}" \ - -s \ - https://slack.com/api/chat.postMessage + + echo "Sending notification to ${channel}" + if [[ -x '${{ inputs.current_user }}' || "${channel}" == '${{ inputs.current_user }}' ]]; then + curl -X POST \ + -H "Content-type: application/json" \ + -H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" \ + -d "{ \"channel\":\"${channel}\",\"text\":\"${{ steps.build-message.outputs.message }}\" }" \ + -s \ + https://slack.com/api/chat.postMessage + fi diff --git a/.github/workflows/issue_comp_next-release-label.yml b/.github/workflows/issue_comp_next-release-label.yml index bf37125ee964..c7a8fb703765 100644 --- a/.github/workflows/issue_comp_next-release-label.yml +++ b/.github/workflows/issue_comp_next-release-label.yml @@ -28,6 +28,7 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} - name: Validate inputs + id: validate-inputs uses: actions/github-script@v7 with: result-encoding: string @@ -35,15 +36,15 @@ jobs: let issueNumber; const issue = context.payload.issue; if (!issue && '${{ inputs.issue_number }}'.trim() === '') { - console.log('Issue number is not provided'); - process.exit(1); + core.warn('Issue number is not provided'); + process.exit(0); } let label = context.payload.label; if (!label) { if (!'${{ inputs.label }}') { - console.log('Label is missing, exiting'); - process.exit(2); + core.warn('Label is missing, exiting'); + process.exit(0); } label = '${{ inputs.label }}'; } else { @@ -51,14 +52,14 @@ jobs: } if (label !== '${{ env.QA_NOT_NEEDED_LABEL }}') { - console.log('Label is not [${{ env.QA_NOT_NEEDED_LABEL }}], exiting'); - process.exit(3); + core.warn('Label is not [${{ env.QA_NOT_NEEDED_LABEL }}], exiting'); + process.exit(0); } core.setOutput('label', label); - name: Add Next Release label uses: actions/github-script@v7 - if: success() + if: success() && steps.validate-inputs.outputs.label != '' with: result-encoding: string retries: 3 @@ -81,25 +82,25 @@ jobs: } if (!issue) { - console.log('Issue [${{ inputs.issue_number }}] not found'); - process.exit(4); + core.warn('Issue [${{ inputs.issue_number }}] not found'); + process.exit(0); } } console.log(`Issue: ${JSON.stringify(issue, null, 2)}`); const issueNumber = issue.number; - const dropAndLearnText = 'Drop Everything & Learn'; - if (issue.title.includes(dropAndLearnText)) { - console.log(`Issue does have "${dropAndLearnText}" text in title, exiting`); - process.exit(5); + const dropAndLearnText = 'Drop Everything & Learn'.toLowerCase(); + if (issue.title.toLowerCase().includes(dropAndLearnText)) { + core.warn(`Issue does have "${dropAndLearnText}" text in title, exiting`); + process.exit(0); } const typeCicdLabel = 'Type : CI/CD'; const foundLabel = issue.labels.find(label => label.name === typeCicdLabel); if (foundLabel) { - console.log(`Issue does have "${typeCicdLabel}" label , exiting`); - process.exit(6); + core.warn(`Issue does have "${typeCicdLabel}" label , exiting`); + process.exit(0); } await github.rest.issues.addLabels({ @@ -111,9 +112,4 @@ jobs: const updated = await getIssue(issueNumber); console.log(`Labels: ${JSON.stringify(updated.labels, null, 2)}`); - - name: Finalize - if: always() - run: | - echo 'Finalizing Next release labeling' - exit 0 diff --git a/.github/workflows/utility_slack-channel-resolver.yml b/.github/workflows/utility_slack-channel-resolver.yml index 8ad2110a5803..818e12e8a574 100644 --- a/.github/workflows/utility_slack-channel-resolver.yml +++ b/.github/workflows/utility_slack-channel-resolver.yml @@ -29,6 +29,8 @@ on: outputs: channel_ids: value: ${{ jobs.slack-channel-resolver.outputs.channel_ids }} + mappings_json: + value: ${{ jobs.slack-channel-resolver.outputs.mappings_json }} secrets: CI_MACHINE_USER: description: 'CI machine user' @@ -45,6 +47,7 @@ jobs: runs-on: ubuntu-20.04 outputs: channel_ids: ${{ steps.resolve-channels.outputs.channel_ids }} + mappings_json: ${{ steps.resolve-channels.outputs.mappings_json }} steps: - name: Resolve Users id: resolve-users @@ -70,7 +73,8 @@ jobs: githack_core_repo_url=https://${githack_host}/${{ github.repository }} slack_mappings_file=slack-mappings.json slack_mapping_url=${githack_core_repo_url}/${{ inputs.branch }}/.github/data/${slack_mappings_file} - json=$(curl -s ${slack_mapping_url}) + json=$(curl -s ${slack_mapping_url} | jq -c .) + echo "json: ${json}" echo "Looking for [${github_user}]" channel_ids= @@ -115,7 +119,9 @@ jobs: fi fi - [[ -n "${channel_id}" ]] && channel_ids="${channel_ids} ${channel_id}" + if [[ -n "${channel_id}" && "${channel_id}" != 'null' ]]; then + channel_ids="${channel_ids} ${channel_id}" + fi done default_channel_id=${{ inputs.default_channel_id }} @@ -135,5 +141,6 @@ jobs: channel_ids=$(printf '%s\n' "${deduped_channel_ids[@]}" | jq -R . | jq -s . | tr -d '\n' | tr -d ' ') fi + echo "mappings_json=${json}" >> $GITHUB_OUTPUT echo "channel_ids: [${channel_ids}]" echo "channel_ids=${channel_ids}" >> $GITHUB_OUTPUT