Skip to content

Generate and Commit Term Update Changelog for FNL-MDB-DEV #68

Generate and Commit Term Update Changelog for FNL-MDB-DEV

Generate and Commit Term Update Changelog for FNL-MDB-DEV #68

name: Generate and Commit Term Update Changelog for FNL-MDB-DEV
permissions:
contents: write
on:
schedule:
- cron: "0 3 * * *" # runs every night at 10:00pm EST
workflow_dispatch:
inputs:
author:
description: "Author name for changes"
required: false
default: "GitHub Actions"
commit_sha:
description: "Commit SHA for reference"
required: false
default: ""
log_level:
description: "Log level"
required: false
type: string
default: "info"
dry_run:
description: "Dry run flag"
required: false
type: boolean
default: false
no_commit:
description: "Don't commit changes to GitHub."
required: false
type: boolean
default: false
jobs:
setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
MATRIX='{
"include": [
{ "name": "fnl-dev", "mdb_id": "fnl-mdb-dev" }
]
}'
MATRIX=$(echo "$MATRIX" | jq -c .)
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
update-mdb-terms:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
fail-fast: false
max-parallel: 1
outputs:
changelog_files: ${{ steps.update-terms.outputs.changelog_files && matrix.name == 'fnl-dev' && steps.update-terms.outputs.changelog_files || '' }}
steps:
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c
with:
python-version-file: ".python-version"
- name: Install uv
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86
with:
version: "0.5.10"
- name: Install dependencies and project
run: |
uv pip install --system -e .
uv sync --all-extras --dev
- name: Update terms
id: update-terms
env:
PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
PREFECT_API_URL: ${{ secrets.PREFECT_API_URL }}
run: |
set -xeuo pipefail
trap 'echo "Error in $BASH_COMMAND at line $LINENO (exit code $?)"' ERR
PARAMS=$(jq -n \
--arg mdb_id "${{ matrix.mdb_id }}" \
--arg author "${{ github.event.inputs.author || 'GitHub Actions Bot' }}" \
--arg commit "${{ github.event.inputs.commit_sha || github.sha }}" \
--argjson no_commit "${{ github.event.inputs.no_commit || false }}" \
'{
"mdb_id": $mdb_id,
"author": $author,
"commit": $commit,
"no_commit": $no_commit
}')
echo "PARAMS=$PARAMS"
watch_out=$(
prefect deployment run update-terms/update-terms \
--params "$PARAMS" \
--watch \
--watch-interval 30 2>&1 | tee watch.log
)
echo "watch_out=$watch_out"
RUN_ID=$(
grep -oP "(?<=UUID:\s)[0-9a-fA-F-]+" watch.log \
| head -n1
)
echo "Scheduled and completed run: $RUN_ID"
LOG_FILE="${RUN_ID}_run.log"
echo "Log file: $LOG_FILE"
prefect flow-run logs "$RUN_ID" > "$LOG_FILE"
echo "First 10 lines of log file:"
head -n 10 "$LOG_FILE" || echo "Failed to read log file"
echo "Checking for RESULT_JSON in logs:"
grep -a "RESULT_JSON" "$LOG_FILE" || echo "No RESULT_JSON found in logs"
RESULT_JSON='[]'
RAW_JSON=$(grep -a -m1 "RESULT_JSON:" "$LOG_FILE" \
| grep -oP 'RESULT_JSON:\s*\[.*\]' \
| sed 's/RESULT_JSON:\s*//' \
|| echo '[]')
echo "Raw JSON array from logs: $RAW_JSON"
FIRST_PATH=$(echo "$RAW_JSON" | jq -r '.[0] // empty')
if [ -n "$FIRST_PATH" ]; then
CLEAN_PATH=$(echo "$FIRST_PATH" \
| sed -E 's|.*/data/|data/|')
RESULT_JSON=$(jq -nc --arg p "$CLEAN_PATH" '[ $p ]')
echo "Normalized RESULT_JSON: $RESULT_JSON"
fi
if [ -z "${RESULT_JSON//\[\]/}" ]; then
echo "Fallback: no direct JSON, grepping for filename…"
FILE_PATH=$(grep -a -o '/[^ ]*/output/term_changelogs/[^ ]*_term_updates\.xml' "$LOG_FILE" \
| tail -n1 \
|| true)
if [ -n "$FILE_PATH" ]; then
STRIPPED=${FILE_PATH#*/data/} # e.g. output/term_changelogs/xxx.xml
RESULT_JSON=$(jq -nc --arg p "data/$STRIPPED" '[ $p ]')
echo "Fallback RESULT_JSON: $RESULT_JSON"
fi
fi
# Set output for GitHub Actions
echo "changelog_files=$RESULT_JSON" >> $GITHUB_OUTPUT
echo "mdb_name=${{ matrix.name }}" >> $GITHUB_OUTPUT
echo "Changelog files for ${{ matrix.name }}: $RESULT_JSON"
update-fnl-mdb-dev:
needs: [setup, update-mdb-terms]
if: ${{ needs.update-mdb-terms.outputs.changelog_files != '' && needs.update-mdb-terms.outputs.changelog_files != '[]' }}
uses: ./.github/workflows/update_mdb.yml
secrets: inherit
with:
mdb_id: fnl-mdb-dev
changelog_files: ${{ needs.update-mdb-terms.outputs.changelog_files }}
dry_run: ${{ fromJson(github.event.inputs.dry_run || 'false') }}
log_level: ${{ github.event.inputs.log_level || 'info' }}