|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# This workflow generates or modifies Java template files based on changes |
| 16 | +# to YAML files in a pull request. |
| 17 | + |
| 18 | +name: YAML to Java Template Generation or Modification |
| 19 | + |
| 20 | +on: |
| 21 | + pull_request: |
| 22 | + paths: |
| 23 | + - 'yaml/src/main/yaml/*.yaml' |
| 24 | + |
| 25 | +permissions: write-all |
| 26 | + |
| 27 | +jobs: |
| 28 | + job-generate-templates: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout code |
| 33 | + |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@v6 |
| 39 | + with: |
| 40 | + python-version: '3.11' |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: pip install pyyaml |
| 44 | + |
| 45 | + - name: Find changed YAML files |
| 46 | + id: yaml-files |
| 47 | + run: | |
| 48 | + echo "Finding changed YAML files at 'yaml/src/main/yaml/'" |
| 49 | + FILES=$(find yaml/src/main/yaml -name '*.yaml' | tr '\n' ' ') |
| 50 | + echo "files found: $FILES" |
| 51 | + echo "files=$FILES" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Generate Java Templates |
| 54 | + if: steps.yaml-files.outputs.files |
| 55 | + run: | |
| 56 | + echo "Processing YAML files: ${{ steps.yaml-files.outputs.files }}" |
| 57 | + for file in ${{ steps.yaml-files.outputs.files }}; do |
| 58 | + python yaml/scripts/generate_yaml_java_templates.py "$file" |
| 59 | + done |
| 60 | +
|
| 61 | + - name: Fetch and Checkout PR Branch |
| 62 | + run: | |
| 63 | + git fetch origin refs/pull/${{ github.event.number }}/head:${{ github.head_ref }} |
| 64 | + git checkout ${{ github.head_ref }} |
| 65 | + |
| 66 | + - name: Commit and push changes |
| 67 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 68 | + with: |
| 69 | + commit_message: "chore(templates): Autogenerate/modify Java templates from YAML" |
| 70 | + branch: ${{ github.head_ref }} |
| 71 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
0 commit comments