72 lines
2.6 KiB
YAML
72 lines
2.6 KiB
YAML
name: Send API Key on PR Merge
|
||
|
||
on:
|
||
pull_request_target:
|
||
types: [closed]
|
||
paths:
|
||
- 'documentation/src/pages/recipes/data/recipes/**'
|
||
|
||
jobs:
|
||
send-api-key:
|
||
if: github.event.pull_request.merged == true
|
||
|
||
runs-on: ubuntu-latest
|
||
|
||
steps:
|
||
- name: Checkout repo
|
||
uses: actions/checkout@v3
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Check if recipe files were added or modified in merged PR
|
||
id: recipe_changes
|
||
run: |
|
||
set -e
|
||
echo "🔍 Checking if recipe files were added or modified in merged PR..."
|
||
|
||
# Get the PR merge information
|
||
MERGE_COMMIT=$(git rev-parse HEAD)
|
||
echo "Merge commit: $MERGE_COMMIT"
|
||
|
||
# For merged PRs, compare the PR's changes against the base branch
|
||
# Use the PR information from the event to get the actual changes
|
||
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
||
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
||
|
||
echo "PR base SHA: $BASE_SHA"
|
||
echo "PR head SHA: $HEAD_SHA"
|
||
|
||
# Get the list of files that were added or modified in the PR (not deleted)
|
||
CHANGED_FILES=$(git diff --name-only --diff-filter=AM $BASE_SHA..$HEAD_SHA)
|
||
|
||
echo "Files added/modified in merged PR:"
|
||
echo "$CHANGED_FILES"
|
||
echo ""
|
||
|
||
# Check if any recipe files were added or modified
|
||
if echo "$CHANGED_FILES" | grep -q "^documentation/src/pages/recipes/data/recipes/"; then
|
||
echo "recipe_files_changed=true" >> "$GITHUB_OUTPUT"
|
||
echo "✅ Recipe files were added/modified in merged PR - proceeding with API key sending"
|
||
else
|
||
echo "recipe_files_changed=false" >> "$GITHUB_OUTPUT"
|
||
echo "ℹ️ No recipe files were added/modified in merged PR - skipping API key sending"
|
||
fi
|
||
|
||
- name: Set up Python
|
||
if: steps.recipe_changes.outputs.recipe_files_changed == 'true'
|
||
uses: actions/setup-python@v4
|
||
with:
|
||
python-version: '3.11'
|
||
|
||
- name: Install dependencies and run email script
|
||
if: steps.recipe_changes.outputs.recipe_files_changed == 'true'
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
GITHUB_SHA: ${{ github.sha }}
|
||
GITHUB_REPOSITORY: ${{ github.repository }}
|
||
PROVISIONING_API_KEY: ${{ secrets.PROVISIONING_API_KEY }}
|
||
EMAIL_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
|
||
run: |
|
||
pip install requests sendgrid email-validator
|
||
python .github/scripts/send_key.py
|