diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c972aa..ca3fc18 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,20 @@ jobs: uses: ./ with: url: 'https://github.com/' + id: lighthouse + - name: Comment output on PR + if: github.event_name == 'pull_request' + uses: unsplash/comment-on-pr@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + msg: "Here is your Lighthouse score:\n + \n + Performance: ${{ steps.lighthouse.outputs.performance }}\n + Accessibility: ${{ steps.lighthouse.outputs.accessibility }}\n + Best Practices: ${{ steps.lighthouse.outputs.practices }}\n + SEO: ${{ steps.lighthouse.outputs.seo }}\n + PWA: ${{ steps.lighthouse.outputs.pwa }}\n" - uses: actions/upload-artifact@master with: name: report diff --git a/README.md b/README.md index 512baef..a32a910 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,28 @@ jobs: On pull requests, the PR number will be extracted from the GitHub event data and used to generate the deploy preview URL as follows: `https://deploy-preview-[[PR_NUMBER]]--[[NETLIFY_SITE]].netlify.com`. You can combine the two above examples and include both `url` and `netlify_site` and run on `on: [push, pull_request]` and the appropriate URL will be automatically selected depending on the type of event. +### Comment output on PR + +Extends the previous + +```yaml +... +jobs: + audit: + runs-on: ubuntu-latest + steps: + - name: Audit live URL + uses: jakejarvis/lighthouse-action@master + with: + url: 'https://jarv.is/' + id: lighthouse + - name: Comment output on PR + uses: unsplash/comment-on-pr@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + msg: "Performance: ${{ steps.lighthouse.outputs.performance }}" +``` ## To-Do diff --git a/entrypoint.sh b/entrypoint.sh index 38fa935..7644095 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -48,4 +48,11 @@ printf "* Detailed results are saved here, use https://github.com/actions/upload printf " %s\n" "$OUTPUT_PATH.report.html" printf " %s\n" "$OUTPUT_PATH.report.json" +# Print scores, so they can be used in another action step. +echo "##[set-output name=performance;]$(echo "$SCORE_PERFORMANCE*100" | bc -l)" +echo "##[set-output name=accessibility;]$(echo "$SCORE_ACCESSIBILITY*100" | bc -l)" +echo "##[set-output name=practices;]$(echo "$SCORE_PRACTICES*100" | bc -l)" +echo "##[set-output name=seo;]$(echo "$SCORE_SEO*100" | bc -l)" +echo "##[set-output name=pwa;]$(echo "$SCORE_PWA*100" | bc -l)" + exit 0