This GitHub Action simplifies the process of creating multiple GitHub Deployments within a single workflow run. It's particularly useful for scenarios where you need to deploy to various environments (e.g., staging, preview, production) or different regions simultaneously and track their statuses directly within GitHub.
Add the multi-deployments action to your workflow. You'll need to provide a JSON object specifying the environments and their corresponding URLs.
This example demonstrates how to use the multi-deployments action to create preview deployments for multiple URLs.
name: multi-deployments example
on:
workflow_dispatch:
permissions:
actions: read
contents: write
deployments: write
id-token: write
issues: write
pull-requests: write
statuses: write
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
cache: "pnpm"
node-version-file: ".nvmrc"
- name: Installing dependencies
run: pnpm install
- name: Build all actions
run: pnpm run build
- name: This is where you create your environments
run: node ./scripts/generate-multi-urls.js
id: generate
- uses: stephansama/actions/multi-deployments@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
invalidate_previous: true
environments: ${{steps.generate.outputs.environments}}
Name | Default | Description | Required |
---|---|---|---|
environments | undefined | Environments to deploy | true |
invalidate_previous | false | Invalidate previous deploys | false |
ref | ${{github.ref}} | Commit ref to reference for deploys (automatically uses Github CI environments) | false |
token | ${{github.token}} | GitHub token used to create octokit client | true |
{
"my-staging-env": "https://staging.example.com",
"my-preview-env": "https://preview.example.com/pr-123",
"production-east": "https://prod-east.example.com"
}
The action leverages the GitHub Deployments API to create and manage deployment records. For each environment provided in the environments input, it performs the following steps:
The invalidate_previous input, when set to true, tells the action to mark any existing deployments for the given environments as inactive before creating the new ones, ensuring only the latest deployments are active.