From dd0162260042b11f4017b555a865ff279c23ee38 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 24 Jan 2024 13:15:53 -0700 Subject: [PATCH] feat(ci): check for major versions and use MAJOR_VERSION_ALLOWED= to release them (#6995) --- .../backwards-compatibility-check.yaml | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backwards-compatibility-check.yaml b/.github/workflows/backwards-compatibility-check.yaml index c153f46ffa0e..33efeab1682d 100644 --- a/.github/workflows/backwards-compatibility-check.yaml +++ b/.github/workflows/backwards-compatibility-check.yaml @@ -46,7 +46,9 @@ jobs: --from=${{ steps.latest-release.outputs.release }} \ --to=origin/main --format=github-actions - # Ensure the release PR does not contain an unexpected (2.0.0) major version release + # Ensure the release PR does not contain an unexpected (e.g. 2.0.0) major version release + # Add "MAJOR_VERSION_ALLOWED=component1,component2" to the PR description to allow major version + # releases for those components unexpected-major-version-check: runs-on: ubuntu-latest if: github.event.pull_request.user.login == 'release-please[bot]' @@ -54,9 +56,33 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Parse allowed major versions + uses: actions-ecosystem/action-regex-match@v2 + id: allowed-major-versions + with: + text: ${{ github.event.pull_request.body }} + regex: '^MAJOR_VERSION_ALLOWED=(.*)$' + flags: gm - name: "Check for unexpected major version" run: | - if [[ "true" == "${{ contains(github.event.pull_request.body, '2.0.0') }}" ]]; then - echo "Unexpected 2.0.0 major version release found" + # parse allowed major versions into an array + IFS=', ' read -r -a ALLOWED_MAJOR_VERSIONS <<< "${{ steps.allowed-major-versions.outputs.group1 }}" + # get all changed components + COMPONENTS=$(git diff origin/main --name-only | grep VERSION | xargs dirname) + FAIL="" + for COMPONENT in ${COMPONENTS}; do { + if [[ "$(cat $COMPONENT/VERSION)" == [123456789].0.0 ]]; then + # A new version is being released - make sure it's allowed + if [[ ${ALLOWED_MAJOR_VERSIONS[@]} =~ $COMPONENT ]]; then + echo "Major version release allowed: $COMPONENT" + else + echo "Unexpected major version release found: $COMPONENT" + FAIL="true" + fi + fi + }; done + if [[ "$FAIL" == "true" ]]; then + echo "Add \"MAJOR_VERSION_ALLOWED=component1,component2\" to the PR description to allow " + echo "major version releases for those components" exit 1 fi