diff --git a/.github/workflows/cicd_scheduled_notify-seated-prs.yml b/.github/workflows/cicd_scheduled_notify-seated-prs.yml index 8b4c2a539e31..bdce909755ef 100644 --- a/.github/workflows/cicd_scheduled_notify-seated-prs.yml +++ b/.github/workflows/cicd_scheduled_notify-seated-prs.yml @@ -25,6 +25,7 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} - name: Filter execution + id: filter-execution uses: actions/github-script@v7 with: result-encoding: string @@ -33,11 +34,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 @@ -152,24 +155,23 @@ jobs: result-encoding: string script: | 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 memberIds = ${{ needs.resolve-seated-prs.outputs.members_json }} - const missingGithubUsers = ${{ needs.slack-channel-resolver.outputs.missing_github_users }} - const members = memberIds.filter(id => !missingGithubUsers.includes(id)); + const mappings = ${{ fromJSON(needs.slack-channel-resolver.outputs.mappings_json) }}; + + const foundMapping = mappings.find(mapping => mapping.slack_id === member) + if (!found) { + 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); @@ -190,7 +192,7 @@ jobs: core.setOutput('message', message); - name: Notify member - if: success() + if: success() && steps.build-message.outputs.message != '' shell: bash run: | channel=${{ matrix.member }} diff --git a/.github/workflows/utility_slack-channel-resolver.yml b/.github/workflows/utility_slack-channel-resolver.yml index 1938b9d7d647..e7365f7564fd 100644 --- a/.github/workflows/utility_slack-channel-resolver.yml +++ b/.github/workflows/utility_slack-channel-resolver.yml @@ -29,8 +29,8 @@ on: outputs: channel_ids: value: ${{ jobs.slack-channel-resolver.outputs.channel_ids }} - missing_github_users: - value: ${{ jobs.slack-channel-resolver.outputs.missing_github_users }} + mappings_json: + value: ${{ jobs.slack-channel-resolver.outputs.mappings_json }} secrets: CI_MACHINE_USER: description: 'CI machine user' @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-20.04 outputs: channel_ids: ${{ steps.resolve-channels.outputs.channel_ids }} - missing_github_users: ${{ steps.resolve-channels.outputs.missing_github_users }} + mappings_json: ${{ steps.resolve-channels.outputs.mappings_json }} steps: - name: Resolve Users id: resolve-users @@ -77,7 +77,6 @@ jobs: echo "Looking for [${github_user}]" channel_ids= - missing_github_users= for github_user in "${github_users_array[@]}"; do channel_id=$( \ jq ".[] | select(.github_user == \"${github_user}\")" <<< "${json}" | \ @@ -121,8 +120,6 @@ jobs: if [[ -n "${channel_id}" && "${channel_id}" != 'null' ]]; then channel_ids="${channel_ids} ${channel_id}" - else - missing_github_users="${missing_github_users} ${github_user}" fi done @@ -143,18 +140,6 @@ jobs: channel_ids=$(printf '%s\n' "${deduped_channel_ids[@]}" | jq -R . | jq -s . | tr -d '\n' | tr -d ' ') fi - if [[ -n "${missing_github_users}" ]]; then - missing_github_users_array=(${missing_github_users}) - declare -A github_user_deduped_array - for element in "${missing_github_users_array[@]}"; do - github_user_deduped_array["$element"]=1 - done - - deduped_github_users=("${!github_user_deduped_array[@]}") - missing_github_users=$(printf '%s\n' "${deduped_github_users[@]}" | jq -R . | jq -s . | tr -d '\n' | tr -d ' ') - fi - echo "channel_ids: [${channel_ids}]" echo "channel_ids=${channel_ids}" >> $GITHUB_OUTPUT - echo "missing_github_users: [${missing_github_users}]" - echo "missing_github_users=${missing_github_users}" >> $GITHUB_OUTPUT + echo "mappings_json=${json}" >> $GITHUB_OUTPUT