Performance checks on ubuntu.com #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Performance checks on ubuntu.com | |
| on: | |
| schedule: | |
| - cron: "20 7 * * 1" | |
| workflow_dispatch: | |
| env: | |
| THRESHOLD: 70 | |
| jobs: | |
| read-config: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix_data: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| cache: "yarn" | |
| - name: Install dependencies | |
| run: yarn --frozen-lockfile | |
| - name: Read links from test-links.yaml | |
| id: set-matrix | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const yaml = require('js-yaml'); | |
| const fs = require('fs'); | |
| try { | |
| // Read the 'links' array from the file | |
| const doc = yaml.load(fs.readFileSync('test-links.yaml', 'utf8')); | |
| const matrix = JSON.stringify(doc.links); | |
| core.setOutput('matrix', matrix); | |
| } catch (e) { | |
| console.error(e); | |
| core.setFailed('Failed to read or parse YAML config.'); | |
| } | |
| perf-checks: | |
| if: github.repository == 'canonical/ubuntu.com' | |
| runs-on: ubuntu-latest | |
| needs: read-config | |
| strategy: | |
| matrix: | |
| include: ${{ fromJson(needs.read-config.outputs.matrix_data) }} | |
| steps: | |
| - name: Running performance checks on ${{ matrix.name }} | |
| id: perf-check | |
| continue-on-error: true | |
| uses: jakepartusch/psi-action@v1.3 | |
| with: | |
| key: ${{ secrets.PSI_API_KEY }} | |
| url: ${{ matrix.url }} | |
| threshold: $THRESHOLD | |
| strategy: desktop | |
| - name: Save result | |
| id: save-result | |
| run: | | |
| sanitized_name=$(echo "${{ matrix.name }}" | tr ' ' '-' | tr '[:upper:]' '[:lower:]') | |
| obj=$(jq -cn --arg name "$sanitized_name" --arg value "${{ steps.perf-check.outcome }}" '{name: $name, value: $value}') | |
| echo "$obj" > "result-${sanitized_name}.json" | |
| echo "sanitized_name=$sanitized_name" >> $GITHUB_OUTPUT | |
| - name: Upload result | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: perf-results-${{ steps.save-result.outputs.sanitized_name }} | |
| path: result-${{ steps.save-result.outputs.sanitized_name }}.json | |
| collect-results: | |
| if: github.repository == 'canonical/ubuntu.com' && always() | |
| runs-on: ubuntu-latest | |
| needs: [read-config, perf-checks] | |
| steps: | |
| - name: Download all results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: perf-results-* | |
| path: results/ | |
| merge-multiple: true | |
| - name: Check overall results | |
| run: | | |
| failed_checks="" | |
| # Collect results from matrix outputs | |
| results=$(jq -s '.' results/*.json) | |
| step_outcomes=() | |
| # Parse matrix results and build step_outcomes array | |
| for result in $(echo "$results" | jq -r '.[] | @base64'); do | |
| decoded=$(echo "$result" | base64 --decode) | |
| name=$(echo "$decoded" | jq -r '.name') | |
| value=$(echo "$decoded" | jq -r '.value') | |
| step_outcomes+=("$name:$value") | |
| done | |
| for step_outcome in "${step_outcomes[@]}"; do | |
| step_name="${step_outcome%:*}" | |
| outcome="${step_outcome#*:}" | |
| [[ "$outcome" == "failure" ]] && failed_checks="$failed_checks $step_name" | |
| done | |
| if [ -n "$failed_checks" ]; then | |
| echo "Performance checks failed for:$failed_checks" | |
| echo "FAILED_CHECKS=$failed_checks" >> $GITHUB_ENV | |
| exit 1 | |
| else | |
| echo "All performance checks passed!" | |
| fi | |
| - name: Send message on failure | |
| if: failure() | |
| run: curl -X POST -F "workflow=${GITHUB_WORKFLOW}" -F "repo_name=${GITHUB_REPOSITORY}" -F "action_id=${GITHUB_RUN_ID}" ${{ secrets.BOT_URL }}?room=web-alerts |