Install gemini-cli in GitHub Actions workflow, set GEMINI_API_KEY secret, run gemini commands in job steps. Example: steps: [{uses: 'actions/checkout@v4'}, {run: 'npm install -g @google/generative-ai-cli'}, {run: 'gemini analyze src/', env: {GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'}}]. Supports automated code review, documentation generation, test creation.
Gemini CLI Github Actions FAQ & Answers
10 expert Gemini CLI Github Actions answers researched from official documentation. Every answer cites authoritative sources you can verify.
unknown
10 questionsTrigger on pull_request event, checkout code, run gemini review with --json output, parse results, post as PR comment. Example: gemini review --diff=${{ github.event.pull_request.diff_url }} --json > review.json. Use GitHub CLI (gh pr comment) to post results. Filter noise with confidence threshold (--min-confidence=0.8).
Use actions/cache with hash of source files as key. Example: key: gemini-${{ hashFiles('src/**/*.js') }}. Cache gemini output (review.json, test_gen/) to skip unchanged files. Reduces API costs 60-80% for incremental changes. Set cache restore-keys for fallback to previous runs.
Run only on changed files (git diff), use --max-tokens limit, cache results, conditional execution (only on main/PR), parallel jobs for independent tasks, fail-fast on quota exceeded. Monitor with workflow run logs. Typical cost: $0.10-$2.00 per PR review (varies by repo size).
Use GitHub CLI (gh pr comment) or actions/github-script. Example: gh pr comment ${{ github.event.pull_request.number }} --body-file review.md. For structured output: parse JSON, format as markdown table, post with workflow name header. Update existing comment instead of creating new (use comment ID caching).
Store API key in GitHub Secrets (not environment variables in repo), use least-privilege token (read-only access where possible), sanitize output before posting (no API keys, credentials in comments), audit log access, rotate keys quarterly, use OIDC token for authentication where supported.
Implement exponential backoff with retries (max 3 attempts). Use workflow concurrency limits (concurrency: {group: 'gemini-${{ github.ref }}', cancel-in-progress: true}). Monitor rate limit headers, queue jobs if limit reached. Distribute load across multiple API keys for high-volume repos. Typical limit: 60 requests/minute.
Trigger on push to main, run gemini doc-gen src/ --output docs/, commit generated docs, push to gh-pages branch. Example: git config user.name 'github-actions[bot]' && git add docs/ && git commit -m 'docs: auto-generate from ${GITHUB_SHA}' && git push. Use pull_request_target for fork PRs (security: read-only).
Use strategy.matrix to split work. Example: matrix: {dir: ['src/api', 'src/web', 'src/utils']}, run: 'gemini test-gen ${{ matrix.dir }}'. Parallelizes across 3 jobs. Combine results in final job (needs: [test-gen]). Upload artifacts (actions/upload-artifact) for downstream jobs.
Track: API calls per run (log gemini --version && gemini stats), token usage, success/failure rates, cost per PR, execution time. Use workflow_run event to aggregate metrics. Export to CloudWatch/Datadog via webhook. Alert on: quota exceeded, repeated failures, cost spike (>$10/day).