diff --git a/.github/workflows/codegen.yaml b/.github/workflows/codegen.yaml index dceaf457dbc..334b48ca010 100644 --- a/.github/workflows/codegen.yaml +++ b/.github/workflows/codegen.yaml @@ -61,7 +61,7 @@ jobs: secrets: inherit # The size of the batch is implicitly decided by the hour of the day. # For example, a job starting at "1:30" uses the chunk at the index 1 in the array. - if: github.event_name != 'workflow_dispatch' && ${{!!fromJson(needs.batch.outputs.services).batches[fromJson(needs.batch.outputs.services).hour]}} + if: ${{ github.event_name != 'workflow_dispatch' && !!fromJson(needs.batch.outputs.services).batches[fromJson(needs.batch.outputs.services).hour] }} with: services: ${{toJson(fromJson(needs.batch.outputs.services).batches[fromJson(needs.batch.outputs.services).hour])}} generate_dispatch: diff --git a/.github/workflows/generate.yaml b/.github/workflows/generate.yaml index 3961c0bddb8..75071bbaf11 100644 --- a/.github/workflows/generate.yaml +++ b/.github/workflows/generate.yaml @@ -27,6 +27,7 @@ jobs: with: fetch-depth: 1 path: google-api-java-client-services + token: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }} - uses: actions/checkout@v2 with: repository: googleapis/discovery-artifact-manager @@ -41,18 +42,43 @@ jobs: pip install pip==21.3.1 pip --version - run: ./google-api-java-client-services/.github/workflows/generate.sh ${{ matrix.service }} - - uses: googleapis/code-suggester@v2 # takes the changes from git directory + - name: Create PR via Local Checkout (Large Commit Support) + shell: bash + working-directory: google-api-java-client-services env: - ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} - with: - command: pr - upstream_owner: ${{ github.repository_owner }} - upstream_repo: google-api-java-client-services - description: 'Generated in GitHub action: https://github.com/${{ github.repository_owner }}/${{ github.repository }}/actions/workflows/codegen.yaml' - title: 'chore: regenerate ${{ matrix.service }} client' - message: 'chore: regenerate ${{ matrix.service }} client' - branch: regenerate-${{ matrix.service }} - git_dir: 'google-api-java-client-services/clients/google-api-services-${{ matrix.service }}' - primary: main - force: true - fork: true + GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }} + SERVICE: ${{ matrix.service }} + AUTHOR: "Cloud Java Bot " + BASE_REPO: "${{ github.repository }}" + run: | + set -ex + + # 1. Setup Identity + git config user.name "Cloud Java Bot" + git config user.email "cloud-java-bot@google.com" + + # 3. Create Branch + BRANCH="regenerate-${SERVICE}" + git checkout -b "$BRANCH" + + # 4. Stage specific files (Large commit handling) + TARGET_PATH="clients/google-api-services-${SERVICE}" + git add "$TARGET_PATH" + + # 5. Commit & Push + MESSAGE="chore: regenerate ${SERVICE} client" + if git diff-index --quiet HEAD --; then + echo "No changes to commit for ${SERVICE}." + exit 0 + fi + + git commit -m "$MESSAGE" + git push origin "$BRANCH" --force + + gh pr create \ + --repo "$BASE_REPO" \ + --head "${BRANCH}" \ + --base "main" \ + --title "$MESSAGE" \ + --body "Generated in GitHub action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ + || echo "PR already exists or failed to create, but changes are pushed."