This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Regenerate all packages after merging to main | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| regenerate: | |
| runs-on: ubuntu-latest | |
| env: | |
| PANDOC_VERSION: 3.8.2 | |
| CACHE_VERSION: v2 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Install Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.26.x' | |
| - name: Install protoc | |
| uses: arduino/setup-protoc@v3 | |
| with: | |
| version: "33.2" | |
| - name: Install pandoc | |
| run: | | |
| mkdir /tmp/pandoc | |
| curl -fsSL --retry 5 --retry-delay 15 -o /tmp/pandoc.tar.gz \ | |
| https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-linux-amd64.tar.gz | |
| tar -xvf /tmp/pandoc.tar.gz -C /tmp/pandoc --strip-components=1 | |
| - name: Install Python packages for Librarian | |
| run: | | |
| version=$(sed -n 's/^version: *//p' librarian.yaml) | |
| go run "github.com/googleapis/librarian/cmd/librarian@v0.13.0" install | |
| - name: Debug Git State | |
| run: | | |
| echo "Current directory: $(pwd)" | |
| echo "Git status:" | |
| git status | |
| echo "Git branch output:" | |
| git branch | |
| echo "HEAD reference:" | |
| git rev-parse HEAD | |
| echo "Current branch:" | |
| git branch --show-current | |
| echo "Is this a shallow clone?" | |
| [ -f .git/shallow ] && echo "Yes, it is shallow" || echo "No, it is not shallow" | |
| - name: Force Git Environment | |
| run: | | |
| # The runner image likely updated and is now stricter about git state. | |
| # We force a valid git state so that synthtool doesn't panic. | |
| git config --global user.email "ci@example.com" | |
| git config --global user.name "CI Bot" | |
| git config --global init.defaultBranch main | |
| # Ensure current directory is a safe directory for git | |
| git config --global --add safe.directory /home/runner/work/google-cloud-python/google-cloud-python | |
| # Ensure a local branch exists | |
| git checkout -B main | |
| - name: Regenerate | |
| run: | | |
| # 1. Clean the cache that synthtool uses | |
| rm -rf $HOME/.cache/synthtool | |
| version=$(sed -n 's/^version: *//p' librarian.yaml) | |
| PATH=$PATH:/tmp/pandoc/bin | |
| go run "github.com/googleapis/librarian/cmd/librarian@v0.13.0" generate -all -v | |
| - name: Create issue on diff | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| TITLE="Regeneration check found diff" | |
| RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| DIFF_STAT=$(git diff --stat) | |
| BODY="The post-submit [regeneration check]($RUN_URL) found a diff. | |
| Diff summary: | |
| \`\`\` | |
| $DIFF_STAT | |
| \`\`\`" | |
| EXISTING_ISSUE=$(gh issue list --state open --search "in:title \"$TITLE\"" --json number --jq '.[0].number') | |
| if [ -z "$EXISTING_ISSUE" ]; then | |
| gh issue create --title "$TITLE" --body "$BODY" | |
| else | |
| echo "Issue #$EXISTING_ISSUE already exists, adding a comment." | |
| gh issue comment "$EXISTING_ISSUE" --body "Another failure with diff occurred: $RUN_URL" | |
| fi | |
| fi | |
| - name: Create issue on generation failure | |
| if: failure() | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TITLE="Regeneration failed" | |
| RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| BODY="The post-submit [regeneration check]($RUN_URL) failed." | |
| EXISTING_ISSUE=$(gh issue list --state open --search "in:title \"$TITLE\"" --json number --jq '.[0].number') | |
| if [ -z "$EXISTING_ISSUE" ]; then | |
| gh issue create --title "$TITLE" --body "$BODY" | |
| else | |
| echo "Issue #$EXISTING_ISSUE already exists, adding a comment." | |
| gh issue comment "$EXISTING_ISSUE" --body "Another regeneration failure occurred: $RUN_URL" | |
| fi |