diff options
author | Antonio Aversa <antonio.aversa@sonarsource.com> | 2024-11-28 14:38:28 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-28 20:02:58 +0000 |
commit | 91a67e7a3e601e7dd5f572e2f59e232f3ec0fd2a (patch) | |
tree | de8fe050b59cfa206a2f7b2e7a8c5513d330067a | |
parent | c771f240e293e0a7d8021cbfc5d2236e95ebe57b (diff) | |
download | sonarqube-91a67e7a3e601e7dd5f572e2f59e232f3ec0fd2a.tar.gz sonarqube-91a67e7a3e601e7dd5f572e2f59e232f3ec0fd2a.zip |
SONAR-22270 Update onboarding tutorials for GitHub Actions to use sonarqube-scan-action v4
6 files changed, 228 insertions, 122 deletions
diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx index e4d1d300cac..28e1230014a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/AnalysisCommand.tsx @@ -25,7 +25,6 @@ import { Feature } from '../../../types/features'; import { Component } from '../../../types/types'; import { BuildTools, TutorialConfig } from '../types'; import CFamily from './commands/CFamily'; -import Dart from './commands/Dart'; import DotNet from './commands/DotNet'; import Gradle from './commands/Gradle'; import JavaMaven from './commands/JavaMaven'; @@ -83,8 +82,12 @@ export function AnalysisCommand(props: Readonly<AnalysisCommandProps>) { ); case BuildTools.Dart: return ( - <Dart + <Others branchesEnabled={branchSupportEnabled} + buildSteps={` + # The analysis requires to retrieve dependencies and build successfully + - name: Build project + run: <commands to build your project>`} mainBranchName={mainBranchName} monorepo={monorepo} component={component} @@ -94,6 +97,7 @@ export function AnalysisCommand(props: Readonly<AnalysisCommandProps>) { return ( <Others branchesEnabled={branchSupportEnabled} + buildSteps="" mainBranchName={mainBranchName} monorepo={monorepo} component={component} diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx index 2e5f29a69cc..84859f187fa 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GithubActionTutorial-it.tsx @@ -154,7 +154,20 @@ it('should follow and complete all steps', async () => { // Dart await user.click(ui.dartBuildButton.get()); expect(getCopyToClipboardValue({ i: 0, name: 'Copy' })).toMatchSnapshot( - 'Dart: .github/workflows/build.yml', + 'Dart: sonar-project.properties', + ); + + await user.click(ui.linuxButton.get()); + expect(getCopyToClipboardValue({ i: 1, name: 'Copy' })).toMatchSnapshot( + 'Dart Linux: .github/workflows/build.yml', + ); + await user.click(ui.windowsButton.get()); + expect(getCopyToClipboardValue({ i: 1, name: 'Copy' })).toMatchSnapshot( + 'Dart Windows: .github/workflows/build.yml', + ); + await user.click(ui.macosButton.get()); + expect(getCopyToClipboardValue({ i: 1, name: 'Copy' })).toMatchSnapshot( + 'Dart MacOS: .github/workflows/build.yml', ); // Other @@ -162,8 +175,18 @@ it('should follow and complete all steps', async () => { expect(getCopyToClipboardValue({ i: 0, name: 'Copy' })).toMatchSnapshot( 'C++ (automatic) and other: sonar-project.properties', ); + + await user.click(ui.linuxButton.get()); expect(getCopyToClipboardValue({ i: 1, name: 'Copy' })).toMatchSnapshot( - 'C++ (automatic) and other: .github/workflows/build.yml', + 'C++ (automatic) and other Linux: .github/workflows/build.yml', + ); + await user.click(ui.windowsButton.get()); + expect(getCopyToClipboardValue({ i: 1, name: 'Copy' })).toMatchSnapshot( + 'C++ (automatic) and other Windows: .github/workflows/build.yml', + ); + await user.click(ui.macosButton.get()); + expect(getCopyToClipboardValue({ i: 1, name: 'Copy' })).toMatchSnapshot( + 'C++ (automatic) and other MacOS: .github/workflows/build.yml', ); expect(ui.allSetSentence.get()).toBeInTheDocument(); diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap index ae97f9249b1..eee03b96041 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/__snapshots__/GithubActionTutorial-it.tsx.snap @@ -51,7 +51,7 @@ jobs: .\\.sonar\\scanner\\dotnet-sonarscanner end /d:sonar.token="\${{ secrets.SONAR_TOKEN }}"" `; -exports[`should follow and complete all steps: C++ (automatic) and other: .github/workflows/build.yml 1`] = ` +exports[`should follow and complete all steps: C++ (automatic) and other Linux: .github/workflows/build.yml 1`] = ` "name: Build on: @@ -70,7 +70,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - uses: sonarsource/sonarqube-scan-action@v3 + - uses: sonarsource/sonarqube-scan-action@v4 env: SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} @@ -78,13 +78,79 @@ jobs: # following lines. This would typically be used to fail a deployment. # We do not recommend to use this in a pull request. Prefer using pull request # decoration instead. - # - uses: sonarsource/sonarqube-quality-gate-action@master + # - uses: sonarsource/sonarqube-quality-gate-action@v1 # timeout-minutes: 5 # env: # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}" `; -exports[`should follow and complete all steps: C++ (automatic) and other: .github/workflows/build.yml 2`] = ` +exports[`should follow and complete all steps: C++ (automatic) and other MacOS: .github/workflows/build.yml 1`] = ` +"name: Build + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build and analyze + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - uses: sonarsource/sonarqube-scan-action@v4 + env: + SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # We do not recommend to use this in a pull request. Prefer using pull request + # decoration instead. + # - uses: sonarsource/sonarqube-quality-gate-action@v1 + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}" +`; + +exports[`should follow and complete all steps: C++ (automatic) and other Windows: .github/workflows/build.yml 1`] = ` +"name: Build + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build and analyze + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - uses: sonarsource/sonarqube-scan-action@v4 + env: + SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # We do not recommend to use this in a pull request. Prefer using pull request + # decoration instead. + # - uses: sonarsource/sonarqube-quality-gate-action@v1 + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}" +`; + +exports[`should follow and complete all steps: C++ (automatic) and other: .github/workflows/build.yml 1`] = ` "name: Build on: @@ -103,7 +169,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - uses: sonarsource/sonarqube-scan-action@v3 + - uses: sonarsource/sonarqube-scan-action@v4 env: SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} @@ -111,7 +177,7 @@ jobs: # following lines. This would typically be used to fail a deployment. # We do not recommend to use this in a pull request. Prefer using pull request # decoration instead. - # - uses: sonarsource/sonarqube-quality-gate-action@master + # - uses: sonarsource/sonarqube-quality-gate-action@v1 # timeout-minutes: 5 # env: # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}" @@ -267,7 +333,7 @@ jobs: exports[`should follow and complete all steps: C++: sonar-project.properties 1`] = `"sonar.projectKey=my-project"`; -exports[`should follow and complete all steps: Dart: .github/workflows/build.yml 1`] = ` +exports[`should follow and complete all steps: Dart Linux: .github/workflows/build.yml 1`] = ` "name: Build on: @@ -281,21 +347,102 @@ jobs: build: name: Build and analyze runs-on: ubuntu-latest + steps: - - <commands to build your project> - - name: Download sonar-scanner - run: | - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.1.0.4477-linux-x64.zip - unzip $HOME/.sonar/sonar-scanner.zip -o -d $HOME/.sonar/ - - name: Run sonar-scanner + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + # The analysis requires to retrieve dependencies and build successfully + - name: Build project + run: <commands to build your project> + - uses: sonarsource/sonarqube-scan-action@v4 env: SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} - run: | - sonar-scanner-6.1.0.4477-linux-x64/bin/sonar-scanner \\ - -Dsonar.projectKey=my-project" + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # We do not recommend to use this in a pull request. Prefer using pull request + # decoration instead. + # - uses: sonarsource/sonarqube-quality-gate-action@v1 + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}" +`; + +exports[`should follow and complete all steps: Dart MacOS: .github/workflows/build.yml 1`] = ` +"name: Build + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build and analyze + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + # The analysis requires to retrieve dependencies and build successfully + - name: Build project + run: <commands to build your project> + - uses: sonarsource/sonarqube-scan-action@v4 + env: + SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # We do not recommend to use this in a pull request. Prefer using pull request + # decoration instead. + # - uses: sonarsource/sonarqube-quality-gate-action@v1 + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}" +`; + +exports[`should follow and complete all steps: Dart Windows: .github/workflows/build.yml 1`] = ` +"name: Build + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build and analyze + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + # The analysis requires to retrieve dependencies and build successfully + - name: Build project + run: <commands to build your project> + - uses: sonarsource/sonarqube-scan-action@v4 + env: + SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + # We do not recommend to use this in a pull request. Prefer using pull request + # decoration instead. + # - uses: sonarsource/sonarqube-quality-gate-action@v1 + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}" `; +exports[`should follow and complete all steps: Dart: sonar-project.properties 1`] = `"sonar.projectKey=my-project"`; + exports[`should follow and complete all steps: Gradle: .github/workflows/build.yml 1`] = ` "name: Build diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx index beb74fefcc9..4f6159eba74 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx @@ -101,7 +101,7 @@ export default function CFamily(props: Readonly<CFamilyProps>) { const [arch, setArch] = React.useState<Arch>(Arch.X86_64); if (config.buildTool === BuildTools.Cpp && config.autoConfig === AutoConfig.Automatic) { - return <Others {...props} />; + return <Others buildSteps="" {...props} />; } const runsOn = { diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Dart.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Dart.tsx deleted file mode 100644 index b5eb0dfeb2d..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Dart.tsx +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import { FormattedMessage } from 'react-intl'; -import { CodeSnippet, Link, NumberedListItem } from '~design-system'; -import { DocLink } from '../../../../helpers/doc-links'; -import { useDocUrl } from '../../../../helpers/docs'; -import { translate } from '../../../../helpers/l10n'; -import { Component } from '../../../../types/types'; -import MonorepoDocLinkFallback from './MonorepoDocLinkFallback'; - -export interface DartProps { - branchesEnabled?: boolean; - component: Component; - mainBranchName: string; - monorepo?: boolean; -} - -export default function Dart(props: Readonly<DartProps>) { - const { component, branchesEnabled, mainBranchName, monorepo } = props; - const docUrl = useDocUrl(DocLink.SonarScanner); - - if (monorepo) { - return <MonorepoDocLinkFallback />; - } - - return ( - <NumberedListItem> - <FormattedMessage - defaultMessage={translate('onboarding.tutorial.with.github_action.dart')} - id="onboarding.tutorial.with.github_action.dart" - /> - <CodeSnippet - className="sw-p-6 sw-overflow-auto" - snippet={` -name: Build - -on: - push: - branches: - - ${mainBranchName} -${branchesEnabled ? ' pull_request:\n types: [opened, synchronize, reopened]' : ''} - -jobs: - build: - name: Build and analyze - runs-on: ubuntu-latest - steps: - - <commands to build your project> - - name: Download sonar-scanner - run: | - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.1.0.4477-linux-x64.zip - unzip $HOME/.sonar/sonar-scanner.zip -o -d $HOME/.sonar/ - - name: Run sonar-scanner - env: - SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} - run: | - sonar-scanner-6.1.0.4477-linux-x64/bin/sonar-scanner \\ - -Dsonar.projectKey=${component.key}`} - language="yml" - /> - - <p className="sw-mt-4"> - <FormattedMessage - defaultMessage={translate('onboarding.analysis.sq_scanner.docs')} - id="onboarding.analysis.sq_scanner.docs" - values={{ - link: <Link to={docUrl}>{translate('onboarding.analysis.sq_scanner.docs_link')}</Link>, - }} - /> - </p> - </NumberedListItem> - ); -} diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Others.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Others.tsx index 73963402ecc..f74a2da0f41 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Others.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Others.tsx @@ -18,23 +18,30 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import * as React from 'react'; +import { NumberedListItem } from '~design-system'; +import { translate } from '../../../../helpers/l10n'; import { Component } from '../../../../types/types'; import CreateYmlFile from '../../components/CreateYmlFile'; import DefaultProjectKey from '../../components/DefaultProjectKey'; -import { GITHUB_ACTIONS_RUNS_ON_LINUX } from '../constants'; +import RenderOptions from '../../components/RenderOptions'; +import { OSs } from '../../types'; import { generateGitHubActionsYaml } from '../utils'; import MonorepoDocLinkFallback from './MonorepoDocLinkFallback'; export interface OthersProps { branchesEnabled?: boolean; + buildSteps: string; component: Component; mainBranchName: string; monorepo?: boolean; } -function otherYamlSteps(branchesEnabled: boolean) { - let output = ` - - uses: sonarsource/sonarqube-scan-action@v3 +function otherYamlSteps(buildSteps: string, branchesEnabled: boolean) { + let output = + buildSteps + + ` + - uses: sonarsource/sonarqube-scan-action@v4 env: SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} @@ -48,7 +55,7 @@ function otherYamlSteps(branchesEnabled: boolean) { } output += ` - # - uses: sonarsource/sonarqube-quality-gate-action@master + # - uses: sonarsource/sonarqube-quality-gate-action@v1 # timeout-minutes: 5 # env: # SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}`; @@ -57,11 +64,28 @@ function otherYamlSteps(branchesEnabled: boolean) { } export default function Others(props: OthersProps) { - const { component, branchesEnabled, mainBranchName, monorepo } = props; + const runsOn = { + [OSs.Linux]: 'ubuntu-latest', + [OSs.MacOS]: 'macos-latest', + [OSs.Windows]: 'windows-latest', + }; + + const { component, branchesEnabled, mainBranchName, monorepo, buildSteps } = props; + const [os, setOs] = React.useState<OSs>(OSs.Linux); + return ( <> <DefaultProjectKey component={component} monorepo={monorepo} /> - + <NumberedListItem> + <span>{translate('onboarding.build.other.os')}</span> + <RenderOptions + label={translate('onboarding.build.other.os')} + checked={os} + onCheck={(value: OSs) => setOs(value)} + optionLabelKey="onboarding.build.other.os" + options={Object.values(OSs)} + /> + </NumberedListItem> {monorepo ? ( <MonorepoDocLinkFallback /> ) : ( @@ -70,8 +94,8 @@ export default function Others(props: OthersProps) { yamlTemplate={generateGitHubActionsYaml( mainBranchName, !!branchesEnabled, - GITHUB_ACTIONS_RUNS_ON_LINUX, - otherYamlSteps(!!branchesEnabled), + runsOn[os], + otherYamlSteps(buildSteps, !!branchesEnabled), )} /> )} |