Skip to content

Instantly share code, notes, and snippets.

@cremerfc
Created July 29, 2025 17:42
Show Gist options
  • Select an option

  • Save cremerfc/be7751d51663ee992205eb895451e389 to your computer and use it in GitHub Desktop.

Select an option

Save cremerfc/be7751d51663ee992205eb895451e389 to your computer and use it in GitHub Desktop.
name: Build and Deploy with Status Updates
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
env:
CORTEX_API_URL: "https://api.getcortexapp.com/api/v1/catalog"
PROJECT_NAME: "my-application"
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate Cortex token
run: |
if [ -z "${{ secrets.CORTEX_TOKEN }}" ]; then
echo "ERROR: CORTEX_TOKEN secret not configured"
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build application
run: npm run build
- name: Deploy to staging
run: |
echo "Deploying to staging environment..."
# Your deployment commands here
# This might fail intentionally for demonstration
# Guaranteed notification job that runs regardless of build-and-deploy outcome
notify-result:
runs-on: ubuntu-latest
needs: build-and-deploy
if: always() # This ensures the job runs regardless of build-and-deploy outcome
steps:
- name: Send deployment notification to Cortex
run: |
echo "Previous job result: ${{ needs.build-and-deploy.result }}"
REPO_NAME=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
echo "Using repo name: $REPO_NAME"
# Check the status of the previous job
if [ "${{ needs.build-and-deploy.result }}" == "success" ]; then
TYPE="DEPLOY"
STATUS="success"
MESSAGE="All jobs completed successfully"
elif [ "${{ needs.build-and-deploy.result }}" == "failure" ]; then
TYPE="ROLLBACK"
STATUS="failed"
MESSAGE="Build and deploy job failed"
elif [ "${{ needs.build-and-deploy.result }}" == "cancelled" ]; then
TYPE="ROLLBACK"
STATUS="cancelled"
MESSAGE="Build and deploy job was cancelled"
else
TYPE="ROLLBACK"
STATUS="skipped"
MESSAGE="Build and deploy job was skipped"
fi
curl -L \
--request POST \
--max-time 30 \
--retry 2 \
--url "${{ env.CORTEX_API_URL }}/$REPO_NAME/deploys" \
--header "Authorization: Bearer ${{ secrets.CORTEX_TOKEN }}" \
--header "Content-Type: application/json" \
--data "{
\"customData\": {
\"workflow\": \"${{ github.workflow }}\",
\"run_id\": \"${{ github.run_id }}\",
\"branch\": \"${{ github.ref_name }}\",
\"final_status\": \"$STATUS\",
\"message\": \"$MESSAGE\",
\"actor\": \"${{ github.actor }}\",
\"repository\": \"${{ github.repository }}\"
},
\"deployer\": {
\"email\": \"${{ github.actor }}@users.noreply.github.com\",
\"name\": \"${{ github.actor }}\"
},
\"environment\": \"staging\",
\"sha\": \"${{ github.sha }}\",
\"timestamp\": \"$(date -u +"%Y-%m-%dT%H:%M:%SZ")\",
\"title\": \"Final deployment $STATUS - ${{ github.workflow }}\",
\"type\": \"$TYPE\",
\"url\": \"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"
}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment