#
# Copyright 2021 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http: //www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
{
  # semantic-release cuts a prerelease only from a prerelease branch, so the rc
  # needs a branch of its own. next is where work integrates and every push
  # cuts an rc; merging next into main cuts the GA. main has to stay a release
  # branch — it is the only one, since the maintenance glob matches nothing yet.
  branches: [
    "+([0-9])?(.{+([0-9]),x}).x",
    "main",
    { name: "next", prerelease: "rc"
    },
  ],
  plugins: [
    # The default angular preset does not parse the "!" breaking-change
    # marker at all, so "refactor!:" and "feat!:" were read as no release.
    [
      "@semantic-release/commit-analyzer",
      { preset: "conventionalcommits"
      },
    ],
    [
      "@google/semantic-release-replace-plugin",
      {
        "replacements": [
          {
            "files": [
              "pysmi/__init__.py"
            ],
            "from": "__version__ ?=.*",
            "to": "__version__ = \"${nextRelease.version}\"",
            "results": [
              {
                "file": "pysmi/__init__.py",
                "hasChanged": true,
                "numMatches": 1,
                "numReplacements": 1
              }
            ],
            "countMatches": true
          }
        ]
      }
    ],
    [
      "@semantic-release/release-notes-generator",
      { preset: "conventionalcommits"
      },
    ],
    [
      "@semantic-release/exec",
      {
        # Building is all semantic-release does here. The upload is a separate
        # workflow step, so that PyPI is reached over OIDC and no token exists.
        "prepareCmd": "./.github/workflows/sr-prepare.sh ${nextRelease.version}",
        "shell": "bash"
      },
    ],
    [
      "@semantic-release/git",
      {
        "assets": [
          "NOTICE",
          "pyproject.toml",
          "pysmi/__init__.py"
        ],
        "message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}",
      },
    ],
    [
      "@semantic-release/github",
      {
        "assets": [
          "NOTICE",
          "pyproject.toml"
        ]
      }
    ],
  ],
}