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.

DotNet.tsx 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 { Component } from '../../../../types/types';
  22. import CreateYmlFile from '../../components/CreateYmlFile';
  23. import { GITHUB_ACTIONS_RUNS_ON_WINDOWS } from '../constants';
  24. import { generateGitHubActionsYaml } from '../utils';
  25. import MonorepoDocLinkFallback from './MonorepoDocLinkFallback';
  26. export interface DotNetProps {
  27. branchesEnabled?: boolean;
  28. mainBranchName: string;
  29. monorepo?: boolean;
  30. component: Component;
  31. }
  32. function dotnetYamlSteps(projectKey: string) {
  33. return `
  34. - name: Set up JDK 17
  35. uses: actions/setup-java@v1
  36. with:
  37. java-version: 17
  38. - name: Cache SonarQube packages
  39. uses: actions/cache@v1
  40. with:
  41. path: ~\\.sonar\\cache
  42. key: \${{ runner.os }}-sonar
  43. restore-keys: \${{ runner.os }}-sonar
  44. - name: Cache SonarQube scanner
  45. id: cache-sonar-scanner
  46. uses: actions/cache@v1
  47. with:
  48. path: .\\.sonar\\scanner
  49. key: \${{ runner.os }}-sonar-scanner
  50. restore-keys: \${{ runner.os }}-sonar-scanner
  51. - name: Install SonarQube scanner
  52. if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
  53. shell: powershell
  54. run: |
  55. New-Item -Path .\\.sonar\\scanner -ItemType Directory
  56. dotnet tool update dotnet-sonarscanner --tool-path .\\.sonar\\scanner
  57. - name: Build and analyze
  58. shell: powershell
  59. run: |
  60. .\\.sonar\\scanner\\dotnet-sonarscanner begin /k:"${projectKey}" /d:sonar.token="\${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="\${{ secrets.SONAR_HOST_URL }}"
  61. dotnet build
  62. .\\.sonar\\scanner\\dotnet-sonarscanner end /d:sonar.token="\${{ secrets.SONAR_TOKEN }}"`;
  63. }
  64. export default function DotNet(props: DotNetProps) {
  65. const { component, branchesEnabled, mainBranchName, monorepo } = props;
  66. if (monorepo) {
  67. return <MonorepoDocLinkFallback />;
  68. }
  69. return (
  70. <CreateYmlFile
  71. yamlFileName=".github/workflows/build.yml"
  72. yamlTemplate={generateGitHubActionsYaml(
  73. mainBranchName,
  74. !!branchesEnabled,
  75. GITHUB_ACTIONS_RUNS_ON_WINDOWS,
  76. dotnetYamlSteps(component.key),
  77. )}
  78. />
  79. );
  80. }