Skip to content

Lighthouse CI

Lighthouse CI #48

Workflow file for this run

name: Lighthouse CI
on:
deployment_status:
permissions:
contents: write
jobs:
lighthouse:
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Wait for deployment
run: sleep 10
- name: Run Lighthouse CI
id: lighthouse
uses: treosh/lighthouse-ci-action@v11
with:
urls: |
${{ github.event.deployment_status.target_url }}
${{ github.event.deployment_status.target_url }}/posts
${{ github.event.deployment_status.target_url }}/retrospections
uploadArtifacts: true
temporaryPublicStorage: true
runs: 3
- name: Parse Lighthouse Results
id: parse
run: |
MANIFEST=".lighthouseci/manifest.json"
if [ -f "$MANIFEST" ]; then
PERF=$(jq -r '.[0].summary.performance' "$MANIFEST" 2>/dev/null)
ACCESS=$(jq -r '.[0].summary.accessibility' "$MANIFEST" 2>/dev/null)
BEST=$(jq -r '.[0].summary["best-practices"]' "$MANIFEST" 2>/dev/null)
SEO=$(jq -r '.[0].summary.seo' "$MANIFEST" 2>/dev/null)
: "${PERF:=0}"
: "${ACCESS:=0}"
: "${BEST:=0}"
: "${SEO:=0}"
echo "perf=$PERF" >> $GITHUB_OUTPUT
echo "accessibility=$ACCESS" >> $GITHUB_OUTPUT
echo "best_practices=$BEST" >> $GITHUB_OUTPUT
echo "seo=$SEO" >> $GITHUB_OUTPUT
else
echo "perf=0" >> $GITHUB_OUTPUT
echo "accessibility=0" >> $GITHUB_OUTPUT
echo "best_practices=0" >> $GITHUB_OUTPUT
echo "seo=0" >> $GITHUB_OUTPUT
fi
- name: Debug links
run: |
echo 'Links payload:'
echo '${{ steps.lighthouse.outputs.links }}'
- name: Extract report links
id: report_links
run: |
REPORT='${{ steps.lighthouse.outputs.links }}'
if [ -z "$REPORT" ] || [ "$REPORT" = "null" ]; then
echo "primary=" >> "$GITHUB_OUTPUT"
echo "list=" >> "$GITHUB_OUTPUT"
exit 0
fi
PRIMARY=$(printf '%s' "$REPORT" | jq -r 'to_entries[0].value // empty')
printf '%s' "$REPORT" \
| jq -r 'to_entries[] | [.key, .value] | @tsv' > links.tsv
: > links.md
while IFS=$'\t' read -r PATH URL; do
case "$PATH" in
*/) ICON="🏠" ;;
*/posts) ICON="πŸ“" ;;
*/retrospections) ICON="πŸ’­" ;;
*) ICON="πŸ”—" ;;
esac
echo "${ICON} [${PATH}](${URL})" >> links.md
done < links.tsv
LIST=$(awk '{printf "%s\\n", $0}' links.md)
echo "primary=$PRIMARY" >> "$GITHUB_OUTPUT"
echo "list=$LIST" >> "$GITHUB_OUTPUT"
- name: Send to Discord
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
PERF: ${{ steps.parse.outputs.perf }}
ACCESS: ${{ steps.parse.outputs.accessibility }}
BEST: ${{ steps.parse.outputs.best_practices }}
SEO: ${{ steps.parse.outputs.seo }}
DEPLOY_URL: ${{ github.event.deployment_status.target_url }}
REPORT_URL: ${{ steps.report_links.outputs.primary }}
REPORT_LIST: ${{ steps.report_links.outputs.list }}
COMMIT_SHA: ${{ github.sha }}
run: |
if [ -z "$DISCORD_WEBHOOK" ]; then
echo "DISCORD_WEBHOOK is not set. Skipping Discord notification."
exit 0
fi
PERF_SCORE=$(printf '%.0f' $(echo "$PERF * 100" | bc))
ACCESS_SCORE=$(printf '%.0f' $(echo "$ACCESS * 100" | bc))
BEST_SCORE=$(printf '%.0f' $(echo "$BEST * 100" | bc))
SEO_SCORE=$(printf '%.0f' $(echo "$SEO * 100" | bc))
if (( $(echo "$PERF >= 0.9" | bc -l) )); then
COLOR=3066993
elif (( $(echo "$PERF >= 0.5" | bc -l) )); then
COLOR=15844367
else
COLOR=15158332
fi
get_emoji() {
local score=$1
if (( $(echo "$score >= 0.9" | bc -l) )); then
echo "🟒"
elif (( $(echo "$score >= 0.5" | bc -l) )); then
echo "🟑"
else
echo "πŸ”΄"
fi
}
PERF_EMOJI=$(get_emoji $PERF)
ACCESS_EMOJI=$(get_emoji $ACCESS)
BEST_EMOJI=$(get_emoji $BEST)
SEO_EMOJI=$(get_emoji $SEO)
curl -H "Content-Type: application/json" \
-d "{
\"embeds\": [{
\"title\": \"πŸ”¦ Lighthouse CI Report\",
\"description\": \"Performance analysis completed for deployment\",
\"color\": $COLOR,
\"fields\": [
{\"name\": \"$PERF_EMOJI Performance\", \"value\": \"**$PERF_SCORE**/100\", \"inline\": true},
{\"name\": \"$ACCESS_EMOJI Accessibility\", \"value\": \"**$ACCESS_SCORE**/100\", \"inline\": true},
{\"name\": \"$BEST_EMOJI Best Practices\", \"value\": \"**$BEST_SCORE**/100\", \"inline\": true},
{\"name\": \"$SEO_EMOJI SEO\", \"value\": \"**$SEO_SCORE**/100\", \"inline\": true},
{\"name\": \"πŸ”— Links\", \"value\": \"$REPORT_LIST\", \"inline\": false}
],
\"footer\": {\"text\": \"Commit: ${COMMIT_SHA:0:7}\"},
\"timestamp\": \"$(date -u +%Y-%m-%dT%H:%M:%S.000Z)\"
}]
}" \
$DISCORD_WEBHOOK