You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { translate } from '../../../../helpers/l10n';
  22. import { CompilationInfo } from '../../components/CompilationInfo';
  23. import CreateYmlFile from '../../components/CreateYmlFile';
  24. import DefaultProjectKey from '../../components/DefaultProjectKey';
  25. import FinishButton from '../../components/FinishButton';
  26. import RenderOptions from '../../components/RenderOptions';
  27. import { OSs } from '../../types';
  28. export interface CFamilyProps {
  29. branchesEnabled?: boolean;
  30. component: T.Component;
  31. onDone: () => void;
  32. }
  33. const STEPS = {
  34. [OSs.Linux]: `steps:
  35. - name: Checkout code
  36. uses: actions/checkout@v2
  37. with:
  38. fetch-depth: 0
  39. - name: Download and install the build wrapper, build the project
  40. run: |
  41. mkdir $HOME/.sonar
  42. curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-linux-x86.zip
  43. unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
  44. $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
  45. env:
  46. SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
  47. - name: SonarQube analysis
  48. uses: SonarSource/sonarqube-scan-action@v1.0.0
  49. with:
  50. args: -Dsonar.cfamily.build-wrapper-output=bw-output
  51. env:
  52. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  53. SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}`,
  54. [OSs.MacOS]: `steps:
  55. - name: Checkout code
  56. uses: actions/checkout@v2
  57. with:
  58. fetch-depth: 0
  59. - name: Download and install the build wrapper
  60. run: |
  61. mkdir $HOME/.sonar
  62. curl -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip \${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-macosx-x86.zip
  63. unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/
  64. env:
  65. SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
  66. - name: Download and install the SonarScanner
  67. run: |
  68. curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-macosx.zip
  69. unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
  70. - name: Build and analyse the project
  71. run: |
  72. # Potential improvement : add these paths to the PATH env var.
  73. $HOME/.sonar/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir bw-output <your clean build command>
  74. $HOME/.sonar/sonar-scanner-4.6.2.2472-macosx/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output
  75. env:
  76. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  77. SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}`,
  78. [OSs.Windows]: `steps:
  79. - name: Checkout code
  80. uses: actions/checkout@v2
  81. with:
  82. fetch-depth: 0
  83. - name: Download and install the build wrapper
  84. shell: powershell
  85. run: |
  86. $path = "$HOME/.sonar/build-wrapper-win-x86.zip"
  87. mkdir $HOME/.sonar
  88. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  89. (New-Object System.Net.WebClient).DownloadFile("\${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-win-x86.zip", $path)
  90. Add-Type -AssemblyName System.IO.Compression.FileSystem
  91. [System.IO.Compression.ZipFile]::ExtractToDirectory($path, "$HOME/.sonar")
  92. env:
  93. SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
  94. - name: Download and install the SonarScanner
  95. shell: powershell
  96. run: |
  97. $path = "$HOME/.sonar/sonar-scanner-cli-4.6.2.2472-windows.zip"
  98. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  99. (New-Object System.Net.WebClient).DownloadFile("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-windows.zip", $path)
  100. Add-Type -AssemblyName System.IO.Compression.FileSystem
  101. [System.IO.Compression.ZipFile]::ExtractToDirectory($path, "$HOME/.sonar")
  102. - name: Build and analyse the project
  103. shell: powershell
  104. run: |
  105. $env:Path += ";$HOME/.sonar/build-wrapper-win-x86;$HOME/.sonar/sonar-scanner-4.6.2.2472-windows/bin"
  106. build-wrapper-win-x86-64 --out-dir bw-output <your clean build command>
  107. sonar-scanner.bat "-Dsonar.cfamily.build-wrapper-output=bw-output"
  108. env:
  109. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  110. SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}`
  111. };
  112. const cfamilyYamlTemplate = (branchesEnabled: boolean, os: OSs) => `name: Build
  113. on:
  114. push:
  115. branches:
  116. - master # or the name of your main branch
  117. ${branchesEnabled ? ' pull_request:\n types: [opened, synchronize, reopened]' : ''}
  118. jobs:
  119. build:
  120. runs-on: <image ready for your build toolchain>
  121. ${STEPS[os]}
  122. `;
  123. export default function CFamily(props: CFamilyProps) {
  124. const { component, branchesEnabled } = props;
  125. const [os, setOs] = React.useState<undefined | OSs>();
  126. return (
  127. <>
  128. <DefaultProjectKey component={component} />
  129. <li>
  130. <span>{translate('onboarding.build.other.os')}</span>
  131. <RenderOptions
  132. checked={os}
  133. name="os"
  134. onCheck={(value: OSs) => setOs(value)}
  135. optionLabelKey="onboarding.build.other.os"
  136. options={Object.values(OSs)}
  137. />
  138. </li>
  139. {os && (
  140. <>
  141. <CreateYmlFile
  142. yamlFileName=".github/workflows/build.yml"
  143. yamlTemplate={cfamilyYamlTemplate(!!branchesEnabled, os)}
  144. />
  145. <CompilationInfo className="abs-width-800" />
  146. <FinishButton onClick={props.onDone} />
  147. </>
  148. )}
  149. </>
  150. );
  151. }