Skip to content

[NDR-297] Manage GitHub role in Terraform (for Dev env) #887

[NDR-297] Manage GitHub role in Terraform (for Dev env)

[NDR-297] Manage GitHub role in Terraform (for Dev env) #887

name: 'Z-AUTOMATED: SonarQube Cloud Analysis'
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
sonarqube_cloud:
name: SonarQube Cloud Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarQube Cloud Scan
uses: SonarSource/sonarqube-scan-action@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
notify-slack:
name: Notify Slack on Failure
runs-on: ubuntu-latest
environment: development
needs: [sonarqube_cloud]
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
role-skip-session-tagging: true
aws-region: ${{ vars.AWS_REGION }}
mask-aws-account-id: true
- name: Get slack bot token from SSM parameter store
run: |
slack_bot_token=$(aws ssm get-parameter --name "/ndr/alerting/slack/bot_token" --with-decryption --query "Parameter.Value" --output text)
echo "::add-mask::$slack_bot_token"
echo "SLACK_BOT_TOKEN=$slack_bot_token" >> $GITHUB_ENV
- name: Send Slack Notification
uses: slackapi/slack-github-action@v2.1.1
with:
method: chat.postMessage
token: ${{ env.SLACK_BOT_TOKEN }}
payload: |
{
"channel": "${{ vars.ALERTS_SLACK_CHANNEL_ID }}",
"attachments": [
{
"color": "#ff0000",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "❌ Workflow `${{ github.workflow }}` failed"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Triggered by:* `${{ github.actor }}`\n*Branch:* `${{ github.ref_name }}`\n*Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{ "type": "mrkdwn", "text": "*sonarqube_cloud:* ${{ needs.sonarqube_cloud.result == 'success' && ':white_check_mark:' || ':x:' }}" }
]
}
]
}
]
}