Require PRs to have "π Ready to deploy" label to be deployed #2
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: Listen for labels added to PRs | |
on: | |
pull_request: | |
types: [labeled] | |
jobs: | |
dispatch-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check for "π Ready to deploy" label | |
id: label_check | |
run: | | |
labels=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") | |
if [[ "$labels" != *"π Ready to deploy"* ]]; then | |
echo "Label not found, skipping dispatch." | |
exit 0 | |
fi | |
echo "Label found, dispatching deploy workflow." | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Trigger Deploy Workflow | |
if: steps.label_check.outcome == 'success' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const prNumber = context.payload.pull_request.number; | |
const result = await github.rest.repos.createDispatchEvent({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'deploy-to-feature-environment.yml', | |
ref: 'main', | |
inputs: { | |
pr_number: prNumber.toString(), | |
} | |
}); | |
console.log(result); |