Skip to content

feat: enhance Slack notifications in CI/CD workflow with detailed pay… #4

feat: enhance Slack notifications in CI/CD workflow with detailed pay…

feat: enhance Slack notifications in CI/CD workflow with detailed pay… #4

Workflow file for this run

name: CI/CD
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [main]
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run tests
run: pnpm test:ci
docker:
name: Docker Publish
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Compute image name
id: image
run: echo "image=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image.outputs.image }}
tags: |
type=raw,value=latest
type=sha,format=long
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
# Added Docker caching for faster builds
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deployment notification
run: |
{
echo "## Deployment"
echo "Image: ${{ steps.image.outputs.image }}"
echo "Tags: latest and sha-${GITHUB_SHA}"
echo "Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
} >> "$GITHUB_STEP_SUMMARY"
- name: Slack notification
if: always()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
STATUS: ${{ job.status }}
IMAGE: ${{ steps.image.outputs.image }}
SHA: ${{ github.sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "SLACK_WEBHOOK_URL secret not set, skipping."
exit 0
fi
payload=$(cat <<EOF
{
"text": ":rocket: CI/CD ${STATUS} — ${{ github.repository }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":rocket: *CI/CD ${STATUS}*\n*Repo:* ${{ github.repository }}\n*Image:* ${IMAGE}\n*Commit:* ${SHA}\n*Run:* <${RUN_URL}|View run>"
}
}
]
}
EOF
)
curl -sS -X POST -H "Content-Type: application/json" \
--data "$payload" \
"$SLACK_WEBHOOK_URL"