Guides
Advanced
GitHub Actions

Using GitHub Actions Deployment Events

GitHub Actions are a great way to wire together Flightcontrol deployments with other services. For example, to set Vercel environment variables or start an end-to-end integration test.

Example of getting service domain URL on deploy success

This action runs on GitHub's deployment_status event. It uses the if: to filter a few things:

  • Only run on deploy success: github.event.deployment_status.state == 'success'
  • Only run for a specific Flightcontrol project: github.event.deployment.payload.deployment.projectId == 'cluagwibz000ka6p9uzas7p26'
  • Only run for preview environment: github.event.deployment.payload.deployment.isPreviewEnvironment == true

You can adjust those filters as needed. For example, you can also filter by github.event.deployment.payload.deployment.environmentId or github.event.deployment.payload.deployment.environmentGivenId. But note that environmentId for preview environments will be different for each PR.

Additionally, it gets domain url of the FC_SERVICE_GIVEN_ID: "my-web-app" service. It does this by using the jq utility to search github.event.deployment.payload.deployment.serviceDeployments[] for the service with this given id and then selects the serviceDomain field.

name: Deployment
 
on:
  deployment_status:
jobs:
  run-deployment:
    if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.event.deployment.payload.deployment.projectId == 'cluagwibz000ka6p9uzas7p26' && github.event.deployment.payload.deployment.isPreviewEnvironment == true
    env:
      FC_SERVICE_GIVEN_ID: "my-web-app"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set DOMAIN env varaible
        run: |
          RESULT=$(echo '${{ toJson(github.event.deployment.payload.deployment) }}' | jq -r --arg serviceGivenId "$FC_SERVICE_GIVEN_ID" '.serviceDeployments[] | select(.serviceGivenId == $serviceGivenId) | .serviceDomain')
          echo "Domain $RESULT"
          echo "DOMAIN=$RESULT" >> $GITHUB_ENV
      - name: Do some action with $DOMAIN like set Vercel env variable or start e2e test
        run: echo true

Example of fetching deployment information

This action runs on GitHub's deployment_status event.

It sets the FC_DEPLOYMENT_ID environment variable by reading github.event.deployment.payload.deployment.deploymentId. Then it uses the FC_API_KEY GitHub secret (opens in a new tab) set on the repo to fetch our Get Deployment API endpoint

name: Deployment
 
on:
  deployment_status:
jobs:
  fetch-deployment:
    env:
      FC_DEPLOYMENT_ID: ${{ github.event.deployment.payload.deployment.deploymentId }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
       - name:  deployment
       - name: Fetch deployment
         run: |
           curl -H "Authorization: Bearer ${{ secrets.FC_API_KEY }}" https://api.flightcontrol.dev/v1/deployments/$FC_DEPLOYMENT_ID