Skip to content

Commit

Permalink
🔧 feat(ci): Add force regeneration for system prompt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultyou committed Sep 30, 2024
1 parent 85cd3a3 commit 6369c6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .github/scripts/generate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/update_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down

0 comments on commit 6369c6d

Please sign in to comment.