Skip to content

Update repo map README #241

Update repo map README

Update repo map README #241

name: Update repo map README
on:
# pull_request:
# branches:
# - main
## Manual trigger
workflow_dispatch:
## Scheduled trigger
schedule:
- cron: "0 0 * * *"
permissions:
contents: write
pull-requests: write
jobs:
update-repo-map:
name: Update repo map and create PR if needed
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.create_pr.outputs.pull-request-number }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# ## Checkout the incoming PR branch
# ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: true
## Fetch all history for diffing
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
# - name: Set up Python
# run: uv python install
- name: Install the project
run: uv sync --all-extras --dev
- name: Run update_repo_map.py
run: |
uv run scripts/update_repo_map.py --save-json --log-level debug
- name: Check for changes
id: changes
run: |
if [[ -n "$(git status --porcelain ./map/README.md ./metadata/categories.json ./metadata/templates.json)" ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Commit and create PR if there are changes
id: create_pr
if: steps.changes.outputs.changes == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update repo map README and metadata"
title: "Update repo map README and categories"
body: |
Automated updates to repo map:
- `./map/README.md`
- `./metadata/categories.json`
- `./metadata/templates.json`
Triggered by: ${{ github.event_name }}
branch: update-repo-map-${{ github.run_number }}-${{ github.run_id }}
base: main
add-paths: |
./map/README.md
./metadata/categories.json
./metadata/templates.json
labels: automated,documentation
assignees: redjax
auto-merge-pr:
name: Auto-merge PR with repo map updates
runs-on: ubuntu-latest
needs: update-repo-map
if: needs.update-repo-map.outputs.pr_number != ''
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install GitHub CLI
run: sudo apt-get update && sudo apt-get install -y gh
- name: Auto-merge PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr merge ${{ needs.update-repo-map.outputs.pr_number }} --auto --squash
- name: Check if PR merged
id: pr-status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
state=$(gh pr view ${{ needs.update-repo-map.outputs.pr_number }} --json state -q '.state')
if [ "$state" = "MERGED" ]; then
echo "merged=true" >> $GITHUB_OUTPUT
else
echo "merged=false" >> $GITHUB_OUTPUT
fi
- name: Delete branch if PR merged successfully
if: steps.pr-status.outputs.merged == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Deleting branch update-repo-map-${{ github.run_number }}-${{ github.run_id }} because PR was merged"
gh api -X DELETE repos/$GITHUB_REPOSITORY/git/refs/heads/update-repo-map-${{ github.run_number }}-${{ github.run_id }} || true