|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -name: Librarian - Generate diff check on main |
| 14 | + |
| 15 | +# This workflow runs a check to ensure that all generated libraries are up-to-date with |
| 16 | +# the latest configuration. |
| 17 | +# |
| 18 | +# Triggers: |
| 19 | +# 1. Push to main: Generates the libraries, checks for git diffs, and fails (creating |
| 20 | +# a Buganizer/GitHub issue) if any changes are detected. |
| 21 | +# 2. Manual trigger (workflow_dispatch) on a branch (except main): Generates the |
| 22 | +# libraries and commits the resulting diff directly back to the triggering branch. |
| 23 | +name: Librarian - Generate libraries check / update |
15 | 24 | on: |
16 | 25 | push: |
17 | 26 | branches: |
|
22 | 31 | library_generation: |
23 | 32 | runs-on: ubuntu-24.04 |
24 | 33 | permissions: |
25 | | - contents: read |
| 34 | + contents: write |
26 | 35 | issues: write |
27 | 36 | steps: |
| 37 | + - name: Prevent running manually on main branch |
| 38 | + if: ${{ github.event_name == 'workflow_dispatch' && github.ref_name == 'main' }} |
| 39 | + run: | |
| 40 | + echo "Error: Running this workflow manually on the main branch is not allowed." |
| 41 | + exit 1 |
28 | 42 | - uses: actions/checkout@v4 |
29 | 43 | with: |
30 | 44 | fetch-depth: 0 |
|
70 | 84 | run: | |
71 | 85 | librarian generate --all |
72 | 86 | - name: Check for generated code changes |
| 87 | + if: ${{ github.event_name != 'workflow_dispatch' }} |
73 | 88 | run: | |
74 | 89 | if [ -n "$(git status --porcelain)" ]; then |
75 | 90 | git status |
|
79 | 94 | echo "Regeneration produced code changes! Please run 'librarian generate --all' to update the generated files." |
80 | 95 | exit 1 |
81 | 96 | fi |
| 97 | + - name: Commit and push changes (manual run only) |
| 98 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 99 | + run: | |
| 100 | + if [ -n "$(git status --porcelain)" ]; then |
| 101 | + git config --global user.name 'github-actions[bot]' |
| 102 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 103 | + git add -A |
| 104 | + git commit -m "chore: regenerate libraries" |
| 105 | + git push |
| 106 | + else |
| 107 | + echo "No changes to commit" |
| 108 | + fi |
82 | 109 | - name: Create issue if previous step fails |
83 | | - if: ${{ failure() && github.ref == 'refs/heads/main' }} |
| 110 | + if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
84 | 111 | uses: googleapis/librarian/.github/actions/create-issue-on-failure@main |
85 | 112 | with: |
86 | 113 | title: "Librarian generate diff check failed on main branch" |
|
0 commit comments