Here is my .yml file for a given workflow:
name: Deploy to Fly.io
'on':
push:
branches:
- development # remove this once everything finalized
- production
paths: ["server-v2/**"]
defaults:
run:
working-directory: server-v2
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
send_notification:
needs: deploy
name: Send SMS Notification
runs-on: ubuntu-latest
env:
MESSAGE: "✅ GitHub Action ✅\n\nName: Deploy to Fly.io\nStatus: Complete\n\nAPI is live at:\nhttps://ammarahmedca.fly.dev"
steps:
- uses: twilio-labs/actions-sms@v1
with:
fromPhoneNumber: ${{ secrets.TWILIO_PHONE_NUMBER }}
toPhoneNumber: ${{ secrets.MY_PHONE_NUMBER }}
message: ${{ env.MESSAGE }}
env:
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_API_KEY: ${{ secrets.TWILIO_API_KEY }}
TWILIO_API_SECRET: ${{ secrets.TWILIO_API_SECRET }}
It runs the deploy action and then afterward, it sends me an SMS notifying me its complete. I want to embed values into the MESSAGE
variable such as the workflow name, and date/time the workflow was called or completed. However, adding env variables there throws an error. As in, doing this:
env:
MESSAGE: "✅ GitHub Action ✅\n\nName: ${{ env.GITHUB_WORKFLOW }}\nStatus: Complete\n\nAPI is live at:\nhttps://ammarahmedca.fly.dev"
will throw this error:
Invalid workflow file: .github/workflows/twillio-test.yml#L10
The workflow is not valid. .github/workflows/twillio-test.yml (Line: 10, Col: 16): Unrecognized named-value: 'env'. Located at position 1 within expression: env.GITHUB_WORKFLOW
AFAIK, env.GITHUB_WORKFLOW
should be a default environment variable with all workflows so I'm not sure why it throws the error.
In any case, I'm looking to add values to the message I'm sending with Twilio, more specifically, the name of the workflow and the date/time it was called. I was unable to find any docs on the Twilio GitHub action. I found out how to do this from a short blog post by Twilio.