diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7d56533..ae4def0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,7 +26,9 @@ jobs: strategy: matrix: java: [ '17', '21' ] - + permissions: + pull-requests: write + steps: - uses: actions/checkout@v4 with: @@ -60,3 +62,66 @@ jobs: REVISON: ${{ github.ref_name}} TEST_ENVIRONMENT: java${{ matrix.java }} run: mvn -Dxray.clientId=${{ env.XRAYCLOUD_CLIENT_ID }} -Dxray.clientSecret=${{ env.XRAYCLOUD_CLIENT_SECRET }} -Dxray.testEnvironment=${{ env.TEST_ENVIRONMENT }} -Dxray.testPlanKey=${{ env.XRAYCLOUD_TEST_PLAN_KEY }} -Dxray.revision=${{ env.REVISON }} xray:import-results + + deploy-staging: + runs-on: ubuntu-latest + needs: build + permissions: + deployments: write + + steps: + - uses: JorgeLNJunior/render-deploy@v1.4.5 + with: + service_id: ${{ secrets.RENDER_SERVICE_ID_STAGING }} + api_key: ${{ secrets.RENDER_API_KEY }} + wait_deploy: true + github_deployment: true + deployment_environment: 'staging' + github_token: ${{ secrets.GITHUB_TOKEN }} + + k6-check: + runs-on: ubuntu-latest + needs: deploy-staging + permissions: + contents: read + steps: + - uses: actions/checkout@v2 + - uses: grafana/setup-k6-action@v1 + - uses: grafana/run-k6-action@v1 + env: + K6_API_URL: ${{ vars.STAGING_URL }} + with: + path: | + ./src/test/k6/*.js + + lighthouse-check: + needs: deploy-staging + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - run: mkdir /tmp/artifacts + - name: Run Lighthouse + uses: foo-software/lighthouse-check-action@master + id: lighthouseCheck + with: + accessToken: ${{ secrets.GITHUB_TOKEN }} + outputDirectory: /tmp/artifacts + urls: '${{ vars.STAGING_URL}}' + prCommentEnabled: true + prCommentSaveOld: true + - name: Upload artifacts + uses: actions/upload-artifact@master + with: + name: Lighthouse reports + path: /tmp/artifacts + - name: Handle Lighthouse Check results + uses: foo-software/lighthouse-check-status-action@master + with: + lighthouseCheckResults: ${{steps.lighthouseCheck.outputs.lighthouseCheckResults }} + minAccessibilityScore: "95" + minBestPracticesScore: "95" + minPerformanceScore: "78" + minProgressiveWebAppScore: "90" + minSeoScore: "90" + \ No newline at end of file diff --git a/src/test/k6/basic_performance_test.js b/src/test/k6/basic_performance_test.js new file mode 100644 index 0000000..0026881 --- /dev/null +++ b/src/test/k6/basic_performance_test.js @@ -0,0 +1,24 @@ +import http from 'k6/http'; +import { check } from 'k6'; + +export const options = { + stages: [ + { duration: '5s', target: 20 }, // ramp up to 20 users over 5 seconds + { duration: '10s', target: 20 }, // stay at 100 users for 20 seconds + { duration: '5s', target: 0 }, // ramp down to 0 users over 5 seconds + ], + thresholds: { + http_req_failed: ['rate<0.01'], // http errors should be less than 1% + http_req_duration: ['p(95)<1000'], // 95% of requests should be below 1s + }, +}; + +export default function () { + // target url should be obtained from environment variable TARGET_URL or else should be https://tutorial-spring-staging.onrender.com + let target_url = __ENV.K6_API_URL || 'https://tutorial-spring-staging.onrender.com'; + const res = http.get(target_url); + + check(res, { + 'status is 200': (r) => r.status === 200, + }); +} \ No newline at end of file