|
| 1 | +name: Repo-mind Index |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + actions: write |
| 13 | + packages: read |
| 14 | + |
| 15 | +defaults: |
| 16 | + run: |
| 17 | + shell: bash |
| 18 | + |
| 19 | +jobs: |
| 20 | + update-index: |
| 21 | + if: github.actor != 'github-actions[bot]' |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Check out repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Verify repo-mind access secrets |
| 30 | + run: | |
| 31 | + set -euo pipefail |
| 32 | + if [ -z "${{ secrets.REPO_MIND_GHCR_USERNAME }}" ]; then |
| 33 | + echo "Missing required secret REPO_MIND_GHCR_USERNAME" >&2 |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + if [ -z "${{ secrets.REPO_MIND_GHCR_TOKEN }}" ]; then |
| 37 | + echo "Missing required secret REPO_MIND_GHCR_TOKEN" >&2 |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: Seed cache from committed index |
| 42 | + run: | |
| 43 | + set -euo pipefail |
| 44 | + mkdir -p .cache/blobs |
| 45 | + if [ -d repo-mind-index ] && [ "$(ls -A repo-mind-index)" ]; then |
| 46 | + rsync -a repo-mind-index/ .cache/blobs/ |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Log in to GHCR |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ghcr.io |
| 53 | + username: ${{ secrets.REPO_MIND_GHCR_USERNAME }} |
| 54 | + password: ${{ secrets.REPO_MIND_GHCR_TOKEN }} |
| 55 | + |
| 56 | + - name: Pull repo-mind image |
| 57 | + run: docker pull ghcr.io/githubnext/repo-mind:latest |
| 58 | + |
| 59 | + - name: Run repo-mind indexer |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ secrets.REPO_MIND_GHCR_TOKEN }} |
| 62 | + GITHUBNEXT_MODEL_8_UKSOUTH_API_KEY: ${{ secrets.GITHUBNEXT_MODEL_8_UKSOUTH_API_KEY }} |
| 63 | + GITHUBNEXT_EASTUS2_API_KEY: ${{ secrets.GITHUBNEXT_EASTUS2_API_KEY }} |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | + repo_mind_output_file="${PWD}/.repo_mind_output.json" |
| 67 | + : > "${repo_mind_output_file}" |
| 68 | + chmod 666 "${repo_mind_output_file}" |
| 69 | + docker run --rm \ |
| 70 | + -v "${PWD}":/github/workspace \ |
| 71 | + -v "${PWD}/repo-mind-config/common.yaml":/opt/repo-mind-action/configs/common.yaml:ro \ |
| 72 | + -v "${repo_mind_output_file}":/github/workspace/.repo_mind_output.json \ |
| 73 | + -e REPO_MIND_OP=index \ |
| 74 | + -e GITHUB_REPOSITORY="${{ github.repository }}" \ |
| 75 | + -e GITHUB_SHA="${{ github.sha }}" \ |
| 76 | + -e REPO_MIND_MAX_INDEX_AGE_IN_DAYS=0 \ |
| 77 | + -e GITHUB_TOKEN \ |
| 78 | + -e GITHUBNEXT_MODEL_8_UKSOUTH_API_KEY \ |
| 79 | + -e GITHUBNEXT_EASTUS2_API_KEY \ |
| 80 | + -e REPO_MIND_OUTPUT_FILE=/github/workspace/.repo_mind_output.json \ |
| 81 | + ghcr.io/githubnext/repo-mind:latest |
| 82 | +
|
| 83 | + rm -f "${repo_mind_output_file}" |
| 84 | +
|
| 85 | + - name: Fix blob permissions |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + if [ -d .cache/blobs ]; then |
| 89 | + sudo chown -R $USER:$USER .cache/blobs || true |
| 90 | + chmod -R 755 .cache/blobs || true |
| 91 | + fi |
| 92 | +
|
| 93 | + - name: Sync generated index into repo |
| 94 | + run: | |
| 95 | + set -euo pipefail |
| 96 | +
|
| 97 | + if [ ! -d ".cache/blobs" ]; then |
| 98 | + echo "repo-mind did not produce .cache/blobs" >&2 |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | +
|
| 102 | + rm -rf repo-mind-index |
| 103 | + mkdir -p repo-mind-index |
| 104 | + rsync -a --delete .cache/blobs/ repo-mind-index/ |
| 105 | +
|
| 106 | + - name: Check out repo-mind sources |
| 107 | + uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + repository: githubnext/repo-mind |
| 110 | + ref: copilot/refactor-rate-limit-handling |
| 111 | + path: repo-mind-src |
| 112 | + token: ${{ secrets.REPO_MIND_GHCR_TOKEN }} |
| 113 | + persist-credentials: false |
| 114 | + |
| 115 | + - name: Install uv |
| 116 | + uses: astral-sh/setup-uv@v4 |
| 117 | + |
| 118 | + - name: Prepare repo-mind configuration for wiki |
| 119 | + run: | |
| 120 | + set -euo pipefail |
| 121 | + cp repo-mind-config/wiki-common.yaml repo-mind-src/configs/wiki-common.yaml |
| 122 | + cp repo-mind-config/wiki.yaml repo-mind-src/configs/w3k-ci.yaml |
| 123 | +
|
| 124 | + - name: Generate repo wiki content |
| 125 | + env: |
| 126 | + PYTHONPATH: ${{ github.workspace }}/repo-mind-src |
| 127 | + REPO_MIND_WORKDIR: ${{ github.workspace }} |
| 128 | + GITHUB_TOKEN: ${{ secrets.REPO_MIND_GHCR_TOKEN }} |
| 129 | + GITHUBNEXT_MODEL_8_UKSOUTH_API_KEY: ${{ secrets.GITHUBNEXT_MODEL_8_UKSOUTH_API_KEY }} |
| 130 | + GITHUBNEXT_EASTUS2_API_KEY: ${{ secrets.GITHUBNEXT_EASTUS2_API_KEY }} |
| 131 | + REPO_MIND_LOCAL_CACHE_DIR: ${{ github.workspace }}/.cache/blobs |
| 132 | + run: | |
| 133 | + set -euo pipefail |
| 134 | + uv run --directory repo-mind-src python repo-mind/generate_wiki.py --config-name=w3k-ci |
| 135 | +
|
| 136 | + - name: Sync generated wiki into repo |
| 137 | + run: | |
| 138 | + set -euo pipefail |
| 139 | + org=${GITHUB_REPOSITORY%%/*} |
| 140 | + repo=${GITHUB_REPOSITORY#*/} |
| 141 | + wiki_source="repo-mind-src/.cache/wiki/${org}/${repo}/_edited" |
| 142 | + if [ ! -d "${wiki_source}" ]; then |
| 143 | + echo "repo-mind wiki output not found at ${wiki_source}" >&2 |
| 144 | + exit 1 |
| 145 | + fi |
| 146 | +
|
| 147 | + rm -rf repo-wiki |
| 148 | + mkdir -p repo-wiki |
| 149 | + rsync -a --delete "${wiki_source}/" repo-wiki/ |
| 150 | +
|
| 151 | + - name: Setup Bun |
| 152 | + uses: oven-sh/setup-bun@v2 |
| 153 | + |
| 154 | + - name: Generate templated documentation |
| 155 | + env: |
| 156 | + REPO_MIND_SRC: ${{ github.workspace }}/repo-mind-src |
| 157 | + REPO_MIND_WORKDIR: ${{ github.workspace }} |
| 158 | + PYTHONPATH: ${{ github.workspace }}/repo-mind-src |
| 159 | + GITHUB_TOKEN: ${{ secrets.REPO_MIND_GHCR_TOKEN }} |
| 160 | + GITHUBNEXT_MODEL_8_UKSOUTH_API_KEY: ${{ secrets.GITHUBNEXT_MODEL_8_UKSOUTH_API_KEY }} |
| 161 | + GITHUBNEXT_EASTUS2_API_KEY: ${{ secrets.GITHUBNEXT_EASTUS2_API_KEY }} |
| 162 | + REPO_MIND_LOCAL_CACHE_DIR: ${{ github.workspace }}/.cache/blobs |
| 163 | + run: | |
| 164 | + set -euo pipefail |
| 165 | + if [ -f "scripts/generate-docs.ts" ]; then |
| 166 | + echo "Generating documentation from templates..." |
| 167 | + bun run scripts/generate-docs.ts |
| 168 | + else |
| 169 | + echo "No generate-docs.ts script found, skipping template generation" |
| 170 | + fi |
| 171 | +
|
| 172 | + - name: Prepare git state |
| 173 | + run: | |
| 174 | + set -euo pipefail |
| 175 | + git config user.name "github-actions[bot]" |
| 176 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 177 | +
|
| 178 | + - name: Publish wiki |
| 179 | + env: |
| 180 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 181 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 182 | + GITHUB_ACTOR: github-actions[bot] |
| 183 | + run: | |
| 184 | + set -euo pipefail |
| 185 | + if [ -f "scripts/publish-wiki.ts" ]; then |
| 186 | + echo "Publishing wiki content..." |
| 187 | + bun run scripts/publish-wiki.ts |
| 188 | + else |
| 189 | + echo "No publish-wiki.ts script found, skipping wiki publish" |
| 190 | + fi |
| 191 | +
|
| 192 | + - name: Create pull request with refreshed index |
| 193 | + uses: peter-evans/create-pull-request@v6 |
| 194 | + with: |
| 195 | + branch: chore/repo-mind-index-${{ github.run_id }} |
| 196 | + title: 'chore: refresh repo-mind index' |
| 197 | + commit-message: 'chore: refresh repo-mind index' |
| 198 | + body: | |
| 199 | + Automated Repo-mind indexing run triggered by `${{ github.sha }}`. |
| 200 | +
|
| 201 | + - Workflow: `${{ github.workflow }}` |
| 202 | + - Run: `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}` |
| 203 | +
|
| 204 | + Please review the generated shards and merge if they look good. |
| 205 | + add-paths: | |
| 206 | + repo-mind-index/** |
| 207 | + repo-wiki/** |
| 208 | + docs/repo-wiki/** |
| 209 | + delete-branch: true |
0 commit comments