Skip to content

Require PRs to have "πŸš€ Ready to deploy" label to be deployed #2

Require PRs to have "πŸš€ Ready to deploy" label to be deployed

Require PRs to have "πŸš€ Ready to deploy" label to be deployed #2

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);