Skip to content

Commit 3dc6c0f

Browse files
authored
feat: add best practices guide (#245)
This commit introduces a new guide on best practices that covers key areas such as repository security, workflow configuration, and monitoring. The `README.md` file has been updated to include a new "Best Practices" section that summarizes the key recommendations from the guide and links to the full documentation. Closes #97
1 parent 485ce1a commit 3dc6c0f

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ This action can be used to automatically review pull requests when they are
136136
opened. For a detailed guide on how to set up the pull request review system,
137137
go to the [GitHub PR Review workflow documentation](./examples/workflows/pr-review).
138138

139-
There is a [known issue](https://github.com/google-github-actions/run-gemini-cli/issues/169) that action bot may approve the PR occasionally,
140-
to avoid this situation as org owner you can restrict who can approve the PR following
141-
[Code Review Limits](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-pull-request-reviews-in-your-repository#enabling-code-review-limits).
139+
142140

143141
### Gemini CLI Assistant
144142

@@ -268,6 +266,18 @@ for debugging and optimization.
268266
For detailed instructions on how to set up and configure observability, go to
269267
the [Observability documentation](./docs/observability.md).
270268

269+
## Best Practices
270+
271+
To ensure the security, reliability, and efficiency of your automated workflows, we strongly recommend following our best practices. These guidelines cover key areas such as repository security, workflow configuration, and monitoring.
272+
273+
Key recommendations include:
274+
275+
* **Securing Your Repository:** Implementing branch and tag protection, and restricting pull request approvers.
276+
* **Workflow Configuration:** Using Workload Identity Federation for secure authentication to Google Cloud, managing secrets effectively, and pinning action versions to prevent unexpected changes.
277+
* **Monitoring and Auditing:** Regularly reviewing action logs and enabling OpenTelemetry for deeper insights into performance and behavior.
278+
279+
For a comprehensive guide on securing your repository and workflows, please refer to our [**Best Practices documentation**](./docs/best-practices.md).
280+
271281
## Customization
272282

273283
Create a [GEMINI.md] file in the root of your repository to provide

docs/best-practices.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Best Practices
2+
3+
This guide provides best practices for using the Gemini CLI GitHub Action, with a focus on repository security and operational excellence.
4+
5+
- [Best Practices](#best-practices)
6+
- [Repository Security](#repository-security)
7+
- [Branch and Tag Protection](#branch-and-tag-protection)
8+
- [Restrict PR Approvers](#restrict-pr-approvers)
9+
- [Workflow Configuration](#workflow-configuration)
10+
- [Use Workload Identity Federation](#use-workload-identity-federation)
11+
- [Use Secrets for Sensitive Data](#use-secrets-for-sensitive-data)
12+
- [Pin Action Versions](#pin-action-versions)
13+
- [Creating Custom Workflows](#creating-custom-workflows)
14+
- [Monitoring and Auditing](#monitoring-and-auditing)
15+
16+
## Repository Security
17+
18+
A secure repository is the foundation for any reliable and safe automation. We strongly recommend implementing the following security measures.
19+
20+
### Branch and Tag Protection
21+
22+
Protecting your branches and tags is critical to preventing unauthorized changes. You can use [repository rulesets] to configure protection for your branches and tags.
23+
24+
We recommend the following at a minimum for your `main` branch:
25+
26+
* **Require a pull request before merging**
27+
* **Require a minimum number of approvals**
28+
* **Dismiss stale approvals**
29+
* **Require status checks to pass before merging**
30+
31+
For more information, see the GitHub documentation on [managing branch protections].
32+
33+
### Restrict PR Approvers
34+
35+
To prevent fraudulent or accidental approvals, you can restrict who can approve pull requests.
36+
37+
* **CODEOWNERS**: Use a [`CODEOWNERS` file] to define individuals or teams that are responsible for code in your repository.
38+
* **Code review limits**: [Limit code review approvals] to specific users or teams.
39+
40+
## Workflow Configuration
41+
42+
### Use Workload Identity Federation
43+
44+
For the most secure authentication to Google Cloud, we recommend using [Workload Identity Federation]. This keyless authentication method eliminates the need to manage long-lived service account keys.
45+
46+
For detailed instructions on how to set up Workload Identity Federation, please refer to our [**Authentication documentation**](./authentication.md).
47+
48+
### Use Secrets for Sensitive Data
49+
50+
Never hardcode secrets (e.g., API keys, tokens) in your workflows. Use [GitHub Secrets] to store sensitive information.
51+
52+
### Pin Action Versions
53+
54+
To ensure the stability and security of your workflows, pin the Gemini CLI action to a specific version.
55+
56+
```yaml
57+
uses: google-github-actions/run-gemini-cli@v0
58+
```
59+
60+
## Creating Custom Workflows
61+
62+
When creating your own workflows, we recommend starting with the [examples provided in this repository](../examples/workflows/). These examples demonstrate how to use the `run-gemini-cli` action for various use cases, such as pull request reviews, issue triage, and more.
63+
64+
Ensure the new workflows you create follow the principle of least privilege. Only grant the permissions necessary to perform the required tasks.
65+
66+
## Monitoring and Auditing
67+
68+
To gain deeper insights into the performance and behavior of Gemini CLI, you can enable OpenTelemetry to send traces, metrics, and logs to your Google Cloud project. This is highly recommended for production environments to monitor for unexpected behavior and performance issues.
69+
70+
For detailed instructions on how to set up and configure observability, please refer to our [**Observability documentation**](./observability.md).
71+
72+
[repository rulesets]: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets
73+
[managing branch protections]: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches
74+
[`codeowners` file]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
75+
[limit code review approvals]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-pull-request-reviews-in-your-repository#enabling-code-review-limits
76+
[github secrets]: https://docs.github.com/en/actions/security-guides/encrypted-secrets
77+
[Workload Identity Federation]: https://cloud.google.com/iam/docs/workload-identity-federation

0 commit comments

Comments
 (0)