pr.yaml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. name: Develop PR - build test
  2. on:
  3. pull_request:
  4. branches:
  5. - develop
  6. push:
  7. branches:
  8. - develop
  9. jobs:
  10. backend:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - uses: actions/checkout@v2
  14. with:
  15. path: ./
  16. -
  17. name: Install just
  18. uses: extractions/setup-just@v1
  19. -
  20. name: Install Go
  21. uses: actions/setup-go@v4
  22. with:
  23. go-version: 'stable'
  24. # Saves us from having to redownload all modules
  25. - name: Go Mod cache
  26. uses: actions/cache@v3
  27. with:
  28. path: |
  29. ~/.cache/go-build
  30. ~/go/pkg/mod
  31. key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
  32. -
  33. name: Test
  34. run: |
  35. just test
  36. - name: Get branch name
  37. shell: bash
  38. run: echo "BRANCH_NAME=$(echo ${GITHUB_REF} | tr / -)" >> $GITHUB_ENV
  39. - name: save coverage file
  40. uses: actions/upload-artifact@v3
  41. with:
  42. path: ./opencost/opencost/coverage.out
  43. name: coverage-${{ env.BRANCH_NAME }}-${{ github.sha }}
  44. -
  45. name: Build
  46. run: |
  47. just build-local
  48. - name: Submit Code Coverage
  49. uses: sonarsource/sonarqube-scan-action@master
  50. env:
  51. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  52. SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
  53. submit-to-sonarqube:
  54. needs: backend
  55. name: Submit to sonar
  56. runs-on: ubuntu-latest
  57. steps:
  58. - uses: actions/checkout@v2
  59. with:
  60. fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
  61. - name: Get branch name
  62. shell: bash
  63. run: echo "BRANCH_NAME=$(echo ${GITHUB_REF} | tr / -)" >> $GITHUB_ENV
  64. - name: Restore coverage file
  65. uses: actions/download-artifact@v3
  66. with:
  67. path: /tmp/coverage.out
  68. name: coverage-${{ env.BRANCH_NAME }}-${{ github.sha }}
  69. - name: copy output file
  70. shell: bash
  71. run: mv /tmp/coverage.out/coverage.out coverage.out
  72. - uses: sonarsource/sonarqube-scan-action@master
  73. env:
  74. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  75. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  76. - uses: geekyeggo/delete-artifact@v2
  77. with:
  78. name: coverage-${{ env.BRANCH_NAME }}-${{ github.sha }}
  79. - name: save report file
  80. uses: actions/upload-artifact@v3
  81. with:
  82. path: .scannerwork
  83. name: report-${{ env.BRANCH_NAME }}-${{ github.sha }}
  84. code-quality-gate:
  85. needs: submit-to-sonarqube
  86. name: Code Quality Gate
  87. if: github.ref != 'refs/heads/develop'
  88. runs-on: ubuntu-latest
  89. steps:
  90. - name: Get branch name
  91. shell: bash
  92. run: echo "BRANCH_NAME=$(echo ${GITHUB_REF} | tr / -)" >> $GITHUB_ENV
  93. - name: Restore report file
  94. uses: actions/download-artifact@v3
  95. with:
  96. path: /tmp/.scannerwork
  97. name: report-${{ env.BRANCH_NAME }}-${{ github.sha }}
  98. - name: copy output file
  99. shell: bash
  100. run: mv /tmp/.scannerwork .scannerwork
  101. - uses: sonarsource/sonarqube-quality-gate-action@master
  102. timeout-minutes: 5
  103. env:
  104. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  105. - uses: geekyeggo/delete-artifact@v2
  106. with:
  107. name: report-${{ env.BRANCH_NAME }}-${{ github.sha }}
  108. frontend:
  109. runs-on: ubuntu-latest
  110. steps:
  111. - uses: actions/checkout@v2
  112. with:
  113. path: ./
  114. -
  115. name: Install just
  116. uses: extractions/setup-just@v1
  117. -
  118. name: Install node
  119. uses: actions/setup-node@v3
  120. with:
  121. node-version: '18.3.0'
  122. - name: Get npm cache directory
  123. id: npm-cache-dir
  124. shell: bash
  125. run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
  126. - uses: actions/cache@v3
  127. id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
  128. with:
  129. path: ${{ steps.npm-cache-dir.outputs.dir }}
  130. key: ${{ runner.os }}-node-${{ hashFiles('./ui/**/package-lock.json') }}
  131. restore-keys: |
  132. ${{ runner.os }}-node-
  133. -
  134. name: Build
  135. working-directory: ./ui
  136. run: |
  137. just build-local