Update-slack-alerts #614
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: fly | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- labeled | |
branches: | |
- main | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
env: | |
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | |
AWS_DEFAULT_REGION: us-west-2 | |
OFFSETS_DB_API_KEY_STAGING: ${{ secrets.OFFSETS_DB_API_KEY_STAGING }} | |
OFFSETS_DB_API_KEY_PRODUCTION: ${{ secrets.OFFSETS_DB_API_KEY_PRODUCTION }} | |
PRODUCTION_URL: 'https://offsets-db.fly.dev/docs' | |
STAGING_URL: 'https://offsets-db-staging.fly.dev/docs' | |
jobs: | |
deploy: | |
name: deploy app | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
environment: | |
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} | |
url: ${{ github.ref == 'refs/heads/main' && env.PRODUCTION_URL || env.STAGING_URL }} | |
if: ${{ (contains(github.event.pull_request.labels.*.name, 'api') && github.event_name == 'pull_request') || (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'}} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: configure aws credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: arn:aws:iam::631969445205:role/github-action-role | |
role-session-name: offsets-db-fly-role-session | |
aws-region: ${{ env.AWS_DEFAULT_REGION }} | |
- name: Get Current time in UTC in format YYYY-MM-DD HH:MM | |
if: always() | |
id: time | |
run: echo "date=$(date -u +'%Y-%m-%d %H:%M')" >> $GITHUB_OUTPUT | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install fsspec requests s3fs pandas | |
- uses: superfly/flyctl-actions/setup-flyctl@master | |
- name: Deploy to Staging | |
run: | | |
flyctl deploy --remote-only --config fly.staging.toml | |
python update_database.py staging https://offsets-db-staging.fly.dev/files | |
- name: Deploy to Production | |
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' | |
run: | | |
flyctl deploy --remote-only --config fly.prod.toml | |
- name: Notify Slack on Failure | |
if: failure() && (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch') | |
uses: slackapi/slack-github-action@v2.0.0 | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
with: | |
method: chat.postMessage | |
payload: | | |
{ | |
"channel": "C06CXEYKMBP", | |
"attachments": [ | |
{ | |
"color": "#ff0000", | |
"blocks": [ | |
{ | |
"type": "header", | |
"text": { | |
"type": "plain_text", | |
"text": "Fly Deployment Failure Alert 🚨" | |
} | |
}, | |
{ | |
"type": "section", | |
"fields": [ | |
{ | |
"type": "mrkdwn", | |
"text": "*GH event:*\n${{ github.event_name }}" | |
}, | |
{ | |
"type": "mrkdwn", | |
"text": "*Time:*\n${{ steps.time.outputs.date }} UTC" | |
} | |
] | |
}, | |
{ | |
"type": "section", | |
"fields": [ | |
{ | |
"type": "mrkdwn", | |
"text": "*Details URL:*\n🔍 <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Workflow Run>" | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
- name: Update Production DB | |
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' | |
run: | | |
python update_database.py production https://offsets-db.fly.dev/files |