|
| 1 | +# Copyright 2026 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 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +name: Librarian - Formatter Version Check |
| 19 | + |
| 20 | +on: |
| 21 | + schedule: |
| 22 | + - cron: '30 3 * * *' # Run daily at 3:30 AM UTC |
| 23 | + workflow_dispatch: # Allow manual trigger |
| 24 | + pull_request: |
| 25 | + |
| 26 | +jobs: |
| 27 | + filter: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + outputs: |
| 30 | + should_run: ${{ steps.filter.outputs.should_run }} |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 33 | + with: |
| 34 | + persist-credentials: false |
| 35 | + - uses: dorny/paths-filter@d1c1ffe0248fe513906c8e24db8ea791d46f8590 # v3 |
| 36 | + id: filter |
| 37 | + with: |
| 38 | + filters: | |
| 39 | + should_run: |
| 40 | + - 'librarian.yaml' |
| 41 | + - 'java-shared-config/java-shared-config/pom.xml' |
| 42 | + - '.github/workflows/formatter-version-check.yaml' |
| 43 | +
|
| 44 | + check-formatter-version: |
| 45 | + needs: filter |
| 46 | + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || needs.filter.outputs.should_run == 'true' }} |
| 47 | + runs-on: ubuntu-latest |
| 48 | + permissions: |
| 49 | + issues: write |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 52 | + with: |
| 53 | + persist-credentials: false |
| 54 | + - uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4 |
| 55 | + with: |
| 56 | + java-version: "17" |
| 57 | + distribution: "temurin" |
| 58 | + - name: Extract formatter version from pom.xml |
| 59 | + id: extract_pom_version |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + version=$(mvn help:evaluate -Dexpression=google-java-format.version -q -DforceStdout -f java-shared-config/java-shared-config/pom.xml | tail -n 1 | tr -d '"') |
| 63 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 64 | + - name: Extract formatter version from librarian.yaml |
| 65 | + id: extract_librarian_version |
| 66 | + shell: bash |
| 67 | + run: | |
| 68 | + version=$(yq '.tools.maven[] | select(.name == "google-java-format") | .version' librarian.yaml | tr -d '"') |
| 69 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 70 | + - name: Verify formatter versions match |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + echo "Formatter version in pom.xml: ${POM_VERSION}" |
| 74 | + echo "Formatter version in librarian.yaml: ${LIBRARIAN_VERSION}" |
| 75 | +
|
| 76 | + if [ -z "${POM_VERSION}" ]; then |
| 77 | + echo "Error: Could not extract google-java-format.version from java-shared-config/java-shared-config/pom.xml" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | +
|
| 81 | + if [ -z "${LIBRARIAN_VERSION}" ]; then |
| 82 | + echo "Error: Could not extract google-java-format version from librarian.yaml" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + if [ "${POM_VERSION}" != "${LIBRARIAN_VERSION}" ]; then |
| 87 | + echo "Mismatch: librarian.yaml has version '${LIBRARIAN_VERSION}', but java-shared-config/java-shared-config/pom.xml has version '${POM_VERSION}'" |
| 88 | + exit 2 |
| 89 | + fi |
| 90 | +
|
| 91 | + echo "Formatter versions are in sync!" |
| 92 | + env: |
| 93 | + POM_VERSION: ${{ steps.extract_pom_version.outputs.version }} |
| 94 | + LIBRARIAN_VERSION: ${{ steps.extract_librarian_version.outputs.version }} |
| 95 | + - name: Create issue on failure |
| 96 | + if: ${{ failure() && github.event_name == 'schedule' }} |
| 97 | + uses: googleapis/librarian/.github/actions/create-issue-on-failure@35997441eafc2b02716804f9baba1e3f04f8a44f # v0.31.1 |
| 98 | + with: |
| 99 | + title: "Formatter Version Mismatch: librarian.yaml and java-shared-config pom.xml out of sync" |
| 100 | + body: | |
| 101 | + The google-java-format version in `java-shared-config/java-shared-config/pom.xml` and `librarian.yaml` do not match. Please update them to match. |
| 102 | +
|
| 103 | + Please check the logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
0 commit comments