Skip to content

ingest

ingest #410

Workflow file for this run

name: Ingest Content via Webhook
on:
repository_dispatch:
types: [ingest]
workflow_dispatch:
inputs:
payload:
description: "JSON payload forwarded to ingest:webhook as MESSAGE"
required: true
type: string
concurrency:
group: ingestion
jobs:
ingestWebhook:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Find and checkout latest updated branch
id: brancher
run: |
LATEST_BRANCH=$(git for-each-ref --sort=-committerdate refs/remotes/origin/ --format='%(refname:short)' | grep '^origin/automated-' | head -n 1)
if [[ -z "$LATEST_BRANCH" ]]; then
BRANCH_NAME="main"
else
BRANCH_NAME=${LATEST_BRANCH#origin/}
fi
echo "Latest updated branch: $BRANCH_NAME"
git checkout $BRANCH_NAME
echo "latest-branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- run: npm ci
- name: Build ingest payload
id: ingest-payload
env:
DISPATCH_PAYLOAD: ${{ toJSON(github.event.client_payload) }}
MANUAL_PAYLOAD: ${{ inputs.payload }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
PAYLOAD="$MANUAL_PAYLOAD"
else
PAYLOAD="$DISPATCH_PAYLOAD"
fi
echo "$PAYLOAD" | jq -e . >/dev/null
{
echo 'message<<EOF'
echo "$PAYLOAD"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- run: npm run ingest:webhook
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
MESSAGE: ${{ steps.ingest-payload.outputs.message }}
- run: npm run data:validate
- name: Check for changes
id: make-changes
run: |-
if [[ -n $(git status --porcelain) ]]; then
echo "There are uncommitted changes"
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "Working directory is clean"
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Target branch
if: steps.make-changes.outputs.has_changes == 'true'
id: target-branch
run: |-
if [[ "${{ steps.brancher.outputs.latest-branch }}" = "main" ]]; then
echo "branch-name=automated-${{ github.run_id }}" >> $GITHUB_OUTPUT
else
echo "branch-name=${{ steps.brancher.outputs.latest-branch }}" >> $GITHUB_OUTPUT
fi
- name: Push changes
if: steps.make-changes.outputs.has_changes == 'true'
run: |-
BRANCH_NAME="${{ steps.target-branch.outputs.branch-name }}"
if [[ "${{ steps.brancher.outputs.latest-branch }}" = "main" ]]; then
git checkout -b $BRANCH_NAME
else
git checkout $BRANCH_NAME
fi
git add -A
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -m "chore(data): automated changes"
git push origin $BRANCH_NAME
- name: Create Pull Request
if: steps.make-changes.outputs.has_changes == 'true' && steps.brancher.outputs.latest-branch == 'main'
uses: actions/github-script@v7
with:
script: |
const branchName = '${{ steps.target-branch.outputs.branch-name }}';
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `[Automated] Update Data`,
body: `
# Automated Data
This PR was automatically created by the scheduled GitHub Action workflow.
`,
head: branchName,
base: 'main'
});
console.log(`Pull Request created: ${pullRequest.html_url}`);