From d70f13f6cde2495a98db3d73180496ce79c3cb94 Mon Sep 17 00:00:00 2001 From: Chandra Keshav Mishra Date: Mon, 28 Oct 2024 16:17:17 +0530 Subject: [PATCH] Revert "[MOSIP-36092] updated resuable flow for slack notification" --- .github/keys/user_map.json.gpg | 1 - .github/workflows/docker-build.yml | 63 ++--------- .github/workflows/slack-notification.yml | 128 ----------------------- .github/workflows/update-gpg.yml | 95 ----------------- 4 files changed, 10 insertions(+), 277 deletions(-) delete mode 100644 .github/keys/user_map.json.gpg delete mode 100644 .github/workflows/slack-notification.yml delete mode 100644 .github/workflows/update-gpg.yml diff --git a/.github/keys/user_map.json.gpg b/.github/keys/user_map.json.gpg deleted file mode 100644 index 1803d153..00000000 --- a/.github/keys/user_map.json.gpg +++ /dev/null @@ -1 +0,0 @@ -  9-5ejM˗VU_@7!aױnEmnbp9ImgU4DFҐ Ʊy"t ;瞐@ϥSzK(3 /dev/null; then - sudo apt-get update && sudo apt-get install -y gnupg - fi - - name: Download and Decrypt Slack Users Map - run: | - curl -L -o user_map.json.gpg https://raw.githubusercontent.com/bn46org/kattu/develop/.github/keys/user_map.json.gpg - gpg --batch --yes --passphrase "${{ secrets.GPG_USER_MAP_PASSPHRASE }}" --output user_map.json --decrypt user_map.json.gpg - - name: Determine Slack Message and Get Slack User ID - id: slack_message_id - run: | - SLACK_USERS_MAP=$(cat user_map.json) - GITHUB_USER="${{ inputs.GITHUB_USER }}" - EVENT_TYPE="${{ github.event_name }}" - - # Fetch Slack user ID from JSON map - SLACK_USER_ID=$(echo "$SLACK_USERS_MAP" | jq -r --arg user "$GITHUB_USER" '.[$user]') - DEFAULT_CHANNEL_ID="${{ secrets.DEFAULT_CHANNEL_ID }}" - - # Determine Slack message and notification channel based on event type and user existence - if [ -n "$SLACK_USER_ID" ] && [ "$SLACK_USER_ID" != "null" ]; then - if [ "$EVENT_TYPE" == "pull_request" ]; then - # PR Event: Notify only specific Slack user - TARGET_CHANNEL_ID="$SLACK_USER_ID" - SLACK_MESSAGE=":no_entry: Failed GitHub Actions for PR by $GITHUB_USER" - - elif [ "$EVENT_TYPE" == "push" ] || ([ "$EVENT_TYPE" == "pull_request" ] && [ "${{ github.event.action }}" == "closed" ] && [ "${{ github.event.pull_request.merged }}" == "true" ]); then - # Push or Merge Event: Notify both specific Slack user and engineering team - TARGET_CHANNEL_ID="$SLACK_USER_ID" - SECONDARY_MESSAGE=":no_entry: Failed GitHub Actions for push/merge by $GITHUB_USER" - - echo "SECONDARY_CHANNEL_ID=${{ secrets.SECONDARY_CHANNEL_ID }}" >> $GITHUB_ENV - echo "SECONDARY_MESSAGE=$SECONDARY_MESSAGE" >> $GITHUB_ENV - fi - - else - # Fallback if user not found in map - TARGET_CHANNEL_ID="$DEFAULT_CHANNEL_ID" - SLACK_MESSAGE=":warning: *GitHub user $GITHUB_USER not mapped in Slack. Using fallback channel.*" - fi - - echo "TARGET_CHANNEL_ID=$TARGET_CHANNEL_ID" >> $GITHUB_ENV - echo "SLACK_MESSAGE=$SLACK_MESSAGE" >> $GITHUB_ENV - - - name: Notify Slack (Primary) - uses: slackapi/slack-github-action@v1.27.0 - with: - channel-id: ${{ env.TARGET_CHANNEL_ID }} - slack-message: | - ${{ env.SLACK_MESSAGE }} - *PR URL*: ${{ inputs.PR_URL }} - *Repository*: ${{ inputs.REPO }} - *Workflow*: ${{ inputs.WORKFLOW }} - *Commit ID*: ${{ inputs.COMMIT }} - *Action*: ${{ inputs.ACTION }} - *Job URL*: ${{ inputs.JOB_URL }} - *Message*: ${{ inputs.MESSAGE }} - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - - - name: Notify Slack (Secondary - Engineering Team) # Only for push and merge events - if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true) }} - uses: slackapi/slack-github-action@v1.27.0 - with: - channel-id: ${{ env.SECONDARY_CHANNEL_ID }} - slack-message: | - ${{ env.SECONDARY_MESSAGE }} - *PR URL*: ${{ inputs.PR_URL }} - *Repository*: ${{ inputs.REPO }} - *Workflow*: ${{ inputs.WORKFLOW }} - *Commit ID*: ${{ inputs.COMMIT }} - *Action*: ${{ inputs.ACTION }} - *Job URL*: ${{ inputs.JOB_URL }} - *Message*: ${{ inputs.MESSAGE }} - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/.github/workflows/update-gpg.yml b/.github/workflows/update-gpg.yml deleted file mode 100644 index 7f3787f2..00000000 --- a/.github/workflows/update-gpg.yml +++ /dev/null @@ -1,95 +0,0 @@ -name: Update Slack User Map Workflow - -on: - workflow_dispatch: - inputs: - NEW_USERS: - description: "Comma-separated list of new GitHub users and Slack user IDs to add in the format github_user:slack_user_id" - required: false - type: string - REVOKE_GITHUB_USERS: - description: "Comma-separated list of GitHub usernames to revoke" - required: false - type: string -jobs: - update_user_map: - runs-on: ubuntu-latest - steps: - - name: Checkout the repository - uses: actions/checkout@v3 - - - name: Check and Install GPG - run: | - echo "Checking if GPG is installed..." - if ! command -v gpg > /dev/null; then - echo "GPG not found. Installing..." - sudo apt-get update && sudo apt-get install -y gnupg - else - echo "GPG is already installed." - fi - - - name: Download and Decrypt Slack Users Map - run: | - curl -L -o user_map.json.gpg https://raw.githubusercontent.com/bn46/kattu/develop/.github/keys/user_map.json.gpg - gpg --batch --yes --passphrase "${{ secrets.GPG_USER_MAP_PASSPHRASE }}" --output user_map.json --decrypt .github/keys/user_map.json.gpg - - - name: Parse New Users and Skip Existing - if: ${{ inputs.NEW_USERS != '' }} - run: | - echo "Parsing and adding new users..." - NEW_USERS="${{ inputs.NEW_USERS }}" - EXISTING_USERS=$(jq -r 'keys[]' user_map.json) - - ADD_USER=false - for USER_PAIR in $(echo $NEW_USERS | tr "," "\n"); do - GITHUB_USER=$(echo "$USER_PAIR" | cut -d':' -f1) - SLACK_USER_ID=$(echo "$USER_PAIR" | cut -d':' -f2) - - if echo "$EXISTING_USERS" | grep -q "$GITHUB_USER"; then - echo "User $GITHUB_USER already exists. Skipping..." - else - echo "Adding new user: $GITHUB_USER -> $SLACK_USER_ID" - jq --arg gh_user "$GITHUB_USER" --arg slack_id "$SLACK_USER_ID" '.[$gh_user] = $slack_id' user_map.json > tmp.json && mv tmp.json user_map.json - ADD_USER=true - fi - done - - if [ "$ADD_USER" = false ]; then - echo "No new users added." - else - echo "New users added successfully." - fi - - - name: Revoke Users - if: ${{ inputs.REVOKE_GITHUB_USERS != '' }} - run: | - echo "Revoking specified users..." - REVOKE_USERS="${{ inputs.REVOKE_GITHUB_USERS }}" - - for REVOKE_USER in $(echo $REVOKE_USERS | tr "," "\n"); do - if jq -e --arg user "$REVOKE_USER" '.[$user]' user_map.json > /dev/null; then - echo "Revoking GitHub user: $REVOKE_USER" - jq "del(.\"$REVOKE_USER\")" user_map.json > tmp.json && mv tmp.json user_map.json - else - echo "User $REVOKE_USER does not exist. Skipping..." - fi - done - - - name: Encrypt Updated User Map - if: ${{ inputs.NEW_USERS != '' || inputs.REVOKE_GITHUB_USERS != '' }} - run: | - echo "Encrypting the updated user map..." - gpg --batch --yes --passphrase "${{ secrets.GPG_USER_MAP_PASSPHRASE }}" --symmetric --cipher-algo AES256 --output .github/keys/user_map.json.gpg user_map.json - echo "Encryption completed." - - - name: Push Updated Map to Repository - if: ${{ inputs.NEW_USERS != '' || inputs.REVOKE_GITHUB_USERS != '' }} - run: | - git config --global user.email "github-bot@example.com" - git config --global user.name "GitHub Action Bot" - #git pull origin ${{ github.ref_name }} - git add .github/keys/user_map.json.gpg - git commit -m "Updated user map with new users" - git push origin ${{ github.ref_name }} - env: - GH_TOKEN: ${{ secrets.GH_TOKEN }}