|
| 1 | +name: 'Update Analyzer' |
| 2 | +description: 'Updates the version of a specified analyzer in SonarQube or SonarCloud and creates a pull request.' |
| 3 | +author: 'SonarSource' |
| 4 | + |
| 5 | +inputs: |
| 6 | + version: |
| 7 | + description: 'The new version to set for the analyzer (e.g., 1.12.0.12345).' |
| 8 | + required: true |
| 9 | + ticket: |
| 10 | + description: 'The Jira ticket number (e.g., SONAR-12345 or SC-12345). This determines the target product.' |
| 11 | + required: true |
| 12 | + plugin-language: |
| 13 | + description: 'The language key of the plugin to update (e.g., architecture, java, csharp).' |
| 14 | + required: true |
| 15 | + github-token: |
| 16 | + description: 'A GitHub token with permissions to create pull requests in the target repository.' |
| 17 | + required: true |
| 18 | + base_branch: |
| 19 | + description: 'The base branch for the product pull request.' |
| 20 | + required: false |
| 21 | + default: 'master' |
| 22 | + draft: |
| 23 | + description: 'A boolean value to control if the pull request is created as a draft.' |
| 24 | + required: false |
| 25 | + default: 'false' |
| 26 | + reviewers: |
| 27 | + description: 'A comma-separated list of GitHub usernames to request a review from.' |
| 28 | + required: false |
| 29 | + pr_body: |
| 30 | + description: 'The body of the pull request.' |
| 31 | + required: false |
| 32 | + |
| 33 | +outputs: |
| 34 | + pr-url: |
| 35 | + description: 'The URL of the created pull request.' |
| 36 | + value: ${{ steps.create_pr.outputs.pull-request-url }} |
| 37 | + |
| 38 | +runs: |
| 39 | + using: 'composite' |
| 40 | + steps: |
| 41 | + - name: Set up environment |
| 42 | + id: setup_env |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + if [[ "${{ inputs.ticket }}" == SONAR-* ]]; then |
| 46 | + echo "PRODUCT_REPOSITORY=sonar-enterprise" >> $GITHUB_ENV |
| 47 | + echo "BUILD_GRADLE_FILE=build.gradle" >> $GITHUB_ENV |
| 48 | + elif [[ "${{ inputs.ticket }}" == SC-* ]]; then |
| 49 | + echo "PRODUCT_REPOSITORY=sonarcloud-core" >> $GITHUB_ENV |
| 50 | + echo "BUILD_GRADLE_FILE=private/edition-sonarcloud/build.gradle" >> $GITHUB_ENV |
| 51 | + else |
| 52 | + echo "::error::Invalid ticket format. Must start with SONAR- or SC-." |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Checkout target repository |
| 57 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 58 | + with: |
| 59 | + repository: SonarSource/${{ env.PRODUCT_REPOSITORY }} |
| 60 | + ref: ${{ inputs.base_branch }} |
| 61 | + sparse-checkout: ${{ env.BUILD_GRADLE_FILE }} |
| 62 | + sparse-checkout-cone-mode: false |
| 63 | + fetch-depth: 0 |
| 64 | + token: ${{ inputs.github-token }} |
| 65 | + |
| 66 | + - name: Update analyzer version in build file |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + set -euo pipefail |
| 70 | + echo "Updating analyzer version in ${{ env.BUILD_GRADLE_FILE }} for plugin ${{ inputs.plugin-language }}" |
| 71 | + |
| 72 | + sed -i "s/\(:sonar-${{ inputs.plugin-language }}.*-plugin:\)[0-9.]*/\1${{ inputs.version }}/g" ${{ env.BUILD_GRADLE_FILE }} |
| 73 | + |
| 74 | + echo "Showing diff:" |
| 75 | + git --no-pager diff ${{ env.BUILD_GRADLE_FILE }} |
| 76 | +
|
| 77 | + - name: Create Pull Request |
| 78 | + id: create_pr |
| 79 | + uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0 |
| 80 | + with: |
| 81 | + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> |
| 82 | + commit-message: '${{ inputs.ticket }} Update `${{ inputs.plugin-language }}` plugins to version ${{ inputs.version }}' |
| 83 | + title: '${{ inputs.ticket }} Update `${{ inputs.plugin-language }}` to version ${{ inputs.version }}' |
| 84 | + body: ${{ inputs.pr_body }} |
| 85 | + base: ${{ inputs.base_branch }} |
| 86 | + branch: '${{ inputs.plugin-language }}/update-analyzer-${{ inputs.version }}' |
| 87 | + token: ${{ inputs.github-token }} |
| 88 | + draft: ${{ inputs.draft }} |
| 89 | + reviewers: ${{ inputs.reviewers }} |
0 commit comments