From 6369c6dfbe356ccb3b366644318cc54fe7befb60 Mon Sep 17 00:00:00 2001 From: Thibault YOU Date: Mon, 30 Sep 2024 14:29:18 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20feat(ci):=20Add=20force=20regene?= =?UTF-8?q?ration=20for=20system=20prompt=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/scripts/generate_metadata.py | 10 ++++++++-- .github/workflows/update_views.yml | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/scripts/generate_metadata.py b/.github/scripts/generate_metadata.py index 94ae7c8..342588d 100644 --- a/.github/scripts/generate_metadata.py +++ b/.github/scripts/generate_metadata.py @@ -76,7 +76,13 @@ def generate_metadata(prompt_content): return metadata def should_update_metadata(prompt_file, metadata_file): - """Check if metadata should be updated based on content hash.""" + """Check if metadata should be updated based on content hash or force flag.""" + force_regenerate = os.environ.get('FORCE_REGENERATE', 'false').lower() == 'true' + + if force_regenerate: + logger.info("Forcing metadata regeneration due to system prompt changes.") + return True, None + # Generate hash of the prompt file content with open(prompt_file, 'rb') as f: prompt_content = f.read() @@ -200,7 +206,7 @@ def update_prompt_metadata(): shutil.rmtree(item_path) else: os.rename(item_path, new_dir_path) - item_path = new_dir_path # Update item_path for the new location + item_path = new_dir_path # Save updated metadata metadata_path = os.path.join(item_path, 'metadata.yml') diff --git a/.github/workflows/update_views.yml b/.github/workflows/update_views.yml index 924d170..c666c70 100644 --- a/.github/workflows/update_views.yml +++ b/.github/workflows/update_views.yml @@ -14,22 +14,39 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.12.6" cache: "pip" cache-dependency-path: ".github/scripts/requirements.txt" + - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r .github/scripts/requirements.txt + + - name: Check for system prompt changes + id: check_changes + run: | + if git diff --name-only HEAD^ HEAD | grep -q ".github/prompts/ai_prompt_analyzer_and_output_generator/"; then + echo "FORCE_REGENERATE=true" >> $GITHUB_ENV + else + echo "FORCE_REGENERATE=false" >> $GITHUB_ENV + fi + - name: Generate metadata env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + FORCE_REGENERATE: ${{ env.FORCE_REGENERATE }} run: python .github/scripts/generate_metadata.py + - name: Update views run: python .github/scripts/update_views.py + - name: Commit changes run: | git config --local user.name "github-actions[bot]"