-
Notifications
You must be signed in to change notification settings - Fork 0
feat: auto-generate llms #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| name: Generate CLIX Flutter LLMS | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| llm_mode: | ||
| description: 'Generation mode' | ||
| type: choice | ||
| options: [changed, all] | ||
| default: changed | ||
| base: | ||
| description: 'Base ref/tag/sha for compare (optional)' | ||
| type: string | ||
| required: false | ||
| head: | ||
| description: 'Head ref/tag/sha for compare (optional)' | ||
| type: string | ||
| required: false | ||
| release: | ||
| types: [published] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| generate: | ||
| name: Generate LLMS | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Ensure tools | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y jq | ||
| chmod +x scripts/generate_llms.sh || true | ||
|
|
||
| - name: Compute compare range and inputs | ||
| id: range | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| # Defaults from inputs | ||
| LLM_MODE="${{ inputs.llm_mode || 'changed' }}" | ||
| echo "LLM_MODE=$LLM_MODE" >> "$GITHUB_ENV" | ||
|
|
||
| # Optionally honor explicit base/head | ||
| if [[ -n "${{ inputs.base }}" && -n "${{ inputs.head }}" ]]; then | ||
| echo "COMPARE=${{ inputs.base }}...${{ inputs.head }}" >> "$GITHUB_ENV" | ||
| fi | ||
|
|
||
| # If release event, try to set COMPARE to previous tag...current tag | ||
| if [[ "${{ github.event_name }}" == "release" ]]; then | ||
| TAG="${{ github.event.release.tag_name }}" | ||
| echo "HEAD_REF=$TAG" >> "$GITHUB_ENV" | ||
| git fetch --tags --force --depth=1 origin "+refs/tags/*:refs/tags/*" || true | ||
| BASE_TAG="$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || true)" | ||
| if [[ -n "$BASE_TAG" ]]; then | ||
| echo "COMPARE=${BASE_TAG}...${TAG}" >> "$GITHUB_ENV" | ||
| fi | ||
| fi | ||
|
|
||
| # Echo for debugging | ||
| echo "LLM_MODE=${LLM_MODE}" | ||
| echo "COMPARE=${COMPARE:-"(none)"}" | ||
|
|
||
| - name: Create update branch | ||
| id: branch | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" | ||
| BRANCH="chore/llms-${{ github.run_id }}-${{ github.run_attempt }}" | ||
| git checkout -B "$BRANCH" "origin/${DEFAULT_BRANCH}" | ||
| echo "BRANCH=$BRANCH" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Run generators | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} # used by scripts for GitHub compare API if needed | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ -z "${OPENAI_API_KEY:-}" ]]; then | ||
| echo "OPENAI_API_KEY is not set. Add it in repository Secrets." >&2 | ||
| exit 1 | ||
| fi | ||
| # Always fetch default branch for raw links | ||
| git fetch origin "${{ github.event.repository.default_branch }}" --depth=1 || true | ||
|
|
||
| # Determine compare range (strict surgical mode) | ||
| if [[ "${LLM_MODE}" == "all" ]]; then | ||
| CMD='./scripts/generate_llms.sh --llm-all --slug "'"${{ github.repository }}"'" --branch "'"${{ github.event.repository.default_branch }}"'"' | ||
| else | ||
| # HEAD ref: inputs.head or default to origin/<default_branch> | ||
| if [[ -n "${{ inputs.head }}" ]]; then | ||
| HEAD_REF="${{ inputs.head }}" | ||
| else | ||
| HEAD_REF="${{ github.event.repository.default_branch }}" | ||
| fi | ||
|
|
||
| if [[ -n "${COMPARE:-}" ]]; then | ||
| COMPARE_RANGE="${COMPARE}" | ||
| else | ||
| # Read base SHA from existing file header | ||
| BASE="$(sed -nE 's/^<!--[[:space:]]*commit:[[:space:]]*([0-9a-f]+).*/\1/p' llms.txt | head -1 || true)" | ||
0xHieu01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [[ -z "${BASE}" ]] && BASE="${HEAD_REF}" | ||
| COMPARE_RANGE="${BASE}...${HEAD_REF}" | ||
| fi | ||
| CMD='./scripts/generate_llms.sh --compare "'"${COMPARE_RANGE}"'" --llm --slug "'"${{ github.repository }}"'" --branch "'"${{ github.event.repository.default_branch }}"'"' | ||
| fi | ||
|
|
||
| eval "${CMD}" | ||
0xHieu01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Commit and push changes | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| # Stage files if present | ||
| git add llms.txt 2>/dev/null || true | ||
| if git diff --cached --quiet; then | ||
| echo "No changes to commit." | ||
| echo "NO_CHANGES=true" >> "$GITHUB_ENV" | ||
| exit 0 | ||
| fi | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git commit -m "chore: update llms index [skip ci]" | ||
| git push origin "HEAD:${BRANCH}" | ||
|
|
||
| - name: Create pull request | ||
| if: env.NO_CHANGES != 'true' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const defaultBranch = context.payload.repository.default_branch; | ||
| const head = process.env.BRANCH; | ||
| const title = 'chore: update CLIX Flutter LLMS index'; | ||
| const body = [ | ||
| 'This PR updates the generated CLIX Flutter SDK LLMS index.', | ||
| '', | ||
| `- Triggered by: ${context.eventName}`, | ||
| `- Range: ${process.env.COMPARE || '(none / full)'}` | ||
| ].join('\n'); | ||
| try { | ||
| const { data: pr } = await github.rest.pulls.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title, | ||
| head, | ||
| base: defaultBranch, | ||
| body | ||
| }); | ||
| core.info(`Created PR #${pr.number}`); | ||
| } catch (e) { | ||
| if (e.status === 422) { | ||
| core.info('PR likely already exists or no changes to propose.'); | ||
| } else { | ||
| throw e; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.