...

Text file src/cloud.google.com/go/.github/workflows/apidiff.yml

Documentation: cloud.google.com/go/.github/workflows

     1---
     2name: apidiff
     3on:
     4  pull_request:
     5
     6permissions:
     7  contents: read
     8
     9jobs:
    10  scan_changes:
    11    runs-on: ubuntu-latest
    12    steps:
    13    - uses: actions/checkout@v4
    14      with:
    15        ref: main
    16    - name: Get main commit
    17      id: main
    18      run: echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
    19    - uses: actions/checkout@v4
    20    - uses: actions/setup-go@v5
    21      with:
    22        go-version: '1.22.x'
    23    - name: Get changed directories
    24      id: changed_dirs
    25      # Ignore changes to the internal and root directories.
    26      # Ignore added files with --diff-filter=a.
    27      run: |
    28        dirs=$(go run ./internal/actions/cmd/changefinder -q --diff-filter=a)
    29        if [ -z "$dirs" ]
    30        then
    31          echo "skip=1" >> $GITHUB_OUTPUT
    32          echo "No changes worth diffing!"
    33        else
    34          for d in $dirs; do list=${list},\"${d}\"; done
    35          echo "changed={\"changed\":[${list#,}]}" >> $GITHUB_OUTPUT
    36          echo "skip=" >> $GITHUB_OUTPUT
    37        fi
    38    outputs:
    39      changed_dirs: ${{ steps.changed_dirs.outputs.changed }}
    40      skip: ${{ steps.changed_dirs.outputs.skip }}
    41  apidiff:
    42    needs: scan_changes
    43    runs-on: ubuntu-latest
    44    if: ${{ !needs.scan_changes.outputs.skip && !contains(github.event.pull_request.labels.*.name, 'breaking change allowed') }}
    45    continue-on-error: true
    46    permissions:
    47      pull-requests: write
    48    strategy:
    49      matrix: ${{ fromJson(needs.scan_changes.outputs.changed_dirs) }}
    50    steps:
    51    - uses: actions/setup-go@v5
    52      with:
    53        go-version: '1.22.x'
    54    - name: Install latest apidiff
    55      run: go install golang.org/x/exp/cmd/apidiff@latest
    56    - uses: actions/checkout@v4
    57      with:
    58        ref: main
    59    - name: Create baseline
    60      id: baseline
    61      run: |
    62        export CHANGED=${{ matrix.changed }}
    63        echo pkg="${CHANGED//\//_}_pkg.main" >> $GITHUB_OUTPUT
    64    - name: Create Go package baseline
    65      run: cd ${{ matrix.changed }} && apidiff -m -w ${{ steps.baseline.outputs.pkg }} .
    66    - name: Upload baseline package data
    67      uses: actions/upload-artifact@v4
    68      with:
    69        name: ${{ steps.baseline.outputs.pkg }}
    70        path: ${{ matrix.changed }}/${{ steps.baseline.outputs.pkg }}
    71        retention-days: 1
    72    - uses: actions/checkout@v4
    73    - name: Download baseline package data
    74      uses: actions/download-artifact@v4
    75      with:
    76        name: ${{ steps.baseline.outputs.pkg }}
    77        path: ${{ matrix.changed }}
    78    - name: Compare regenerated code to baseline
    79      # Only ignore Go interface additions when the PR is from OwlBot as it is
    80      # likely a new method added to the gRPC client stub interface, which is
    81      # non-breaking.
    82      env:
    83        PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
    84      run: |
    85        cd ${{ matrix.changed }} && apidiff -m -incompatible ${{ steps.baseline.outputs.pkg }} . > diff.txt
    86        if [[ "$PR_HEAD_REF" == owl-bot-copy ]]; then
    87          sed -i '/: added/d' ./diff.txt
    88        fi
    89        cat diff.txt && ! [ -s diff.txt ]
    90    - name: Add breaking change label
    91      if: ${{ failure() && !github.event.pull_request.head.repo.fork }}
    92      uses: actions/github-script@v7
    93      with:
    94        script: |
    95          github.rest.issues.addLabels({
    96            issue_number: ${{ github.event.number }},
    97            owner: context.repo.owner,
    98            repo: context.repo.repo,
    99            labels: ['breaking change']
   100          })

View as plain text