Automate OpenRouter API Key Distribution for External Recipe Contributors (#3198)
Co-authored-by: w. ian douglas <ian.douglas@iandouglas.com>
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
name: Validate Recipe PR
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
paths:
|
||||
- 'documentation/src/pages/recipes/data/recipes/**'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
validate-recipe:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
PROVIDER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
||||
|
||||
steps:
|
||||
- name: Checkout PR
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Install and Configure Goose
|
||||
run: |
|
||||
mkdir -p /home/runner/.local/bin
|
||||
curl -fsSL https://github.com/block/goose/releases/download/stable/download_cli.sh \
|
||||
| CONFIGURE=false INSTALL_PATH=/home/runner/.local/bin bash
|
||||
echo "/home/runner/.local/bin" >> $GITHUB_PATH
|
||||
|
||||
mkdir -p ~/.config/goose
|
||||
cat <<EOF > ~/.config/goose/config.yaml
|
||||
GOOSE_PROVIDER: openrouter
|
||||
GOOSE_MODEL: "anthropic/claude-3.5-sonnet"
|
||||
keyring: false
|
||||
EOF
|
||||
|
||||
- name: Find and validate recipe files
|
||||
id: validate
|
||||
run: |
|
||||
echo "🔍 Looking for recipe files..."
|
||||
RECIPE_FILES=$(find documentation/src/pages/recipes/data/recipes/ -name "*.yaml" -o -name "*.yml" 2>/dev/null || true)
|
||||
|
||||
if [ -z "$RECIPE_FILES" ]; then
|
||||
echo "❌ No recipe files found in the correct location!"
|
||||
echo "📁 Please add your recipe to: documentation/src/pages/recipes/data/recipes/"
|
||||
echo "validation_status=no_files" >> $GITHUB_OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Found recipe files:"
|
||||
echo "$RECIPE_FILES"
|
||||
|
||||
ALL_VALID=true
|
||||
VALIDATION_OUTPUT=""
|
||||
|
||||
# First pass: Basic YAML validation
|
||||
while IFS= read -r RECIPE_FILE; do
|
||||
if [ -f "$RECIPE_FILE" ]; then
|
||||
echo "🔍 Validating: $RECIPE_FILE"
|
||||
if OUTPUT=$(goose recipe validate "$RECIPE_FILE" 2>&1); then
|
||||
echo "✅ Valid: $RECIPE_FILE"
|
||||
VALIDATION_OUTPUT="${VALIDATION_OUTPUT}✅ $RECIPE_FILE: VALID\n"
|
||||
else
|
||||
echo "❌ Invalid: $RECIPE_FILE"
|
||||
echo "$OUTPUT"
|
||||
VALIDATION_OUTPUT="${VALIDATION_OUTPUT}❌ $RECIPE_FILE: INVALID\n\`\`\`\n$OUTPUT\n\`\`\`\n"
|
||||
ALL_VALID=false
|
||||
fi
|
||||
fi
|
||||
done <<< "$RECIPE_FILES"
|
||||
|
||||
# Second pass: Check for duplicate filenames
|
||||
if [ "$ALL_VALID" = true ]; then
|
||||
echo "🔍 Checking for duplicate filenames..."
|
||||
|
||||
# Check for duplicate filenames first
|
||||
SEEN_FILENAMES=""
|
||||
while IFS= read -r RECIPE_FILE; do
|
||||
if [ -f "$RECIPE_FILE" ]; then
|
||||
FILENAME=$(basename "$RECIPE_FILE" .yaml)
|
||||
FILENAME=$(basename "$FILENAME" .yml)
|
||||
|
||||
echo "📋 Checking filename: '$FILENAME'"
|
||||
|
||||
# Check if we've seen this filename before in this PR
|
||||
if echo "$SEEN_FILENAMES" | grep -q "^$FILENAME$"; then
|
||||
echo "❌ Duplicate filename '$FILENAME' found in this PR"
|
||||
VALIDATION_OUTPUT="${VALIDATION_OUTPUT}❌ Duplicate filename '$FILENAME' found in this PR\n"
|
||||
ALL_VALID=false
|
||||
else
|
||||
SEEN_FILENAMES="$SEEN_FILENAMES\n$FILENAME"
|
||||
fi
|
||||
|
||||
# Check if this is a new file or an update to existing file
|
||||
# Get list of changed files in this PR compared to base branch
|
||||
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD | grep "^$RECIPE_FILE$" || true)
|
||||
EXISTING_FILES=$(find documentation/src/pages/recipes/data/recipes/ -name "$FILENAME.yaml" -o -name "$FILENAME.yml" | grep -v "^$RECIPE_FILE$" || true)
|
||||
|
||||
if [ -n "$EXISTING_FILES" ] && [ -z "$CHANGED_FILES" ]; then
|
||||
# File exists in repo but is not being modified - this is a new duplicate
|
||||
echo "❌ Recipe filename '$FILENAME' already exists:"
|
||||
echo "$EXISTING_FILES"
|
||||
VALIDATION_OUTPUT="${VALIDATION_OUTPUT}❌ $RECIPE_FILE: Filename '$FILENAME' already exists in: $EXISTING_FILES\n"
|
||||
ALL_VALID=false
|
||||
elif [ -n "$EXISTING_FILES" ] && [ -n "$CHANGED_FILES" ]; then
|
||||
# File exists and is being modified - this is an update
|
||||
echo "✅ Updating existing recipe: '$FILENAME'"
|
||||
else
|
||||
# File doesn't exist - this is a new recipe
|
||||
echo "✅ New recipe filename '$FILENAME' is unique"
|
||||
fi
|
||||
|
||||
echo "✅ Filename '$FILENAME' validation complete"
|
||||
fi
|
||||
done <<< "$RECIPE_FILES"
|
||||
fi
|
||||
|
||||
# Save validation output for use in comment
|
||||
echo "$VALIDATION_OUTPUT" > /tmp/validation_output.txt
|
||||
|
||||
if [ "$ALL_VALID" = true ]; then
|
||||
echo "validation_status=valid" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "validation_status=invalid" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Comment validation results
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const status = '${{ steps.validate.outputs.validation_status }}';
|
||||
|
||||
let comment;
|
||||
if (status === 'no_files') {
|
||||
comment = `❌ **Recipe Validation Failed**
|
||||
|
||||
No recipe files found in the correct location!
|
||||
|
||||
📁 **Please add your recipe to**: \`documentation/src/pages/recipes/data/recipes/your-recipe-id.yaml\`
|
||||
|
||||
**Example**: If your recipe ID is \`web-scraper\`, create:
|
||||
\`documentation/src/pages/recipes/data/recipes/web-scraper.yaml\``;
|
||||
} else if (status === 'valid') {
|
||||
comment = `✅ **Recipe Validation Passed**
|
||||
|
||||
Your recipe(s) are valid and ready for review!
|
||||
|
||||
🔍 **Next Steps**:
|
||||
1. Our team will review your recipe
|
||||
2. If approved, we'll run a security scan
|
||||
3. Once merged, you'll receive $10 in OpenRouter credits (if email provided)
|
||||
|
||||
Thanks for contributing to the Goose Recipe Cookbook! 🎉`;
|
||||
} else {
|
||||
// Read validation details from file
|
||||
let validationDetails = '';
|
||||
try {
|
||||
validationDetails = fs.readFileSync('/tmp/validation_output.txt', 'utf8');
|
||||
} catch (e) {
|
||||
validationDetails = 'See workflow logs for details.';
|
||||
}
|
||||
|
||||
comment = `❌ **Recipe Validation Failed**
|
||||
|
||||
Please fix the validation errors and push your changes:
|
||||
|
||||
${validationDetails}
|
||||
|
||||
📚 Check our [Recipe Guide](https://block.github.io/goose/recipes) for help with the correct format.`;
|
||||
}
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.payload.pull_request.number,
|
||||
body: comment
|
||||
});
|
||||
|
||||
- name: Set validation status
|
||||
if: always()
|
||||
env:
|
||||
VALIDATION_STATUS: ${{ steps.validate.outputs.validation_status }}
|
||||
run: |
|
||||
if [ "$VALIDATION_STATUS" = "valid" ]; then
|
||||
echo "✅ All recipes are valid"
|
||||
exit 0
|
||||
else
|
||||
echo "❌ Recipe validation failed"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user