|
| 1 | +name: Auto Review Documentation |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + auto-review-merge: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + environment: MMI-Samples |
| 16 | + env: |
| 17 | + AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }} |
| 18 | + AZURE_OPENAI_DEPLOYMENT: ${{ secrets.GPT_4_1_MINI }} |
| 19 | + AZURE_OPENAI_API_VERSION: "2024-12-01-preview" |
| 20 | + GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }} |
| 21 | + REPO_NAME: "Azure-Samples/azure-ai-content-understanding-python" |
| 22 | + DOC_FILE_FILTER: '\.md$|README|\.ipynb$' |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 # Required to compare two SHAs in full history |
| 29 | + |
| 30 | + - name: Set up Python |
| 31 | + uses: actions/setup-python@v4 |
| 32 | + with: |
| 33 | + python-version: '3.12' |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + python -m pip install --upgrade pip |
| 38 | + pip install -r tools/review_file/requirements.txt |
| 39 | +
|
| 40 | + - name: Get changed files |
| 41 | + id: changed-docs |
| 42 | + run: | |
| 43 | + # Retrieve list of files changed between the previous commit and the current SHA |
| 44 | + git diff --name-only ${{ github.event.before }} ${{ github.sha }} > changed_files.txt |
| 45 | + # filter to include only documentation files (e.g., .md, .rst, README, .ipynb) |
| 46 | + grep -E "${DOC_FILE_FILTER}" changed_files.txt || true > changed_docs.txt |
| 47 | + echo "Files changed with DOC_FILE_FILTER (${DOC_FILE_FILTER}) — could be empty:" |
| 48 | + echo "---------------------------------------------------------------" |
| 49 | + cat changed_docs.txt |
| 50 | + echo "---------------------------------------------------------------" |
| 51 | +
|
| 52 | + - name: Azure Login |
| 53 | + uses: azure/login@v2 |
| 54 | + with: |
| 55 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 56 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 57 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 58 | + |
| 59 | + - name: Run review script on each file |
| 60 | + run: | |
| 61 | + if [ ! -s changed_docs.txt ]; then |
| 62 | + echo "No documentation files changed matching DOC_FILE_FILTER (${DOC_FILE_FILTER}). Skipping review step." |
| 63 | + else |
| 64 | + while read file; do |
| 65 | + if [ -n "$file" ]; then |
| 66 | + echo "Running review script on file: $file" |
| 67 | + INPUT_FILE_PATH="$file" python tools/review_file/review_file.py |
| 68 | + fi |
| 69 | + done < changed_docs.txt |
| 70 | + fi |
0 commit comments