-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update dynamic badge for pull requests
- Loading branch information
1 parent
06e1740
commit 88d02fa
Showing
2 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
name: Unlighthouse | ||
|
||
on: [pull_request] | ||
on: | ||
push: | ||
branches: | ||
main | ||
pull_request: | ||
|
||
permissions: | ||
pull-requests: write | ||
|
@@ -12,20 +16,29 @@ jobs: | |
COMMENT_ID: unlighthouse-node${{matrix.node-version}} | ||
PORT: 8000 | ||
CLOUDFLARE_PROJECT: hellobart-unlighthouse | ||
CLOUDFLARE_BRANCH: pull-${{ github.event.pull_request.number }} | ||
strategy: | ||
matrix: | ||
node-version: [18] | ||
steps: | ||
- name: Create initial comment | ||
uses: marocchino/[email protected] | ||
if: github.ref != 'refs/heads/main' | ||
with: | ||
header: ${{ env.COMMENT_ID }} | ||
message: | | ||
⚡️ Lighthouse report | ||
![loading](https://github.com/bartvdbraak/hellob.art/assets/3996360/0e00b3fc-d5f9-490b-9aa7-07cb4b59f85f) | ||
- name: Set variables based on trigger | ||
run: | | ||
echo "Discovering the environment stage:" | ||
if [[ ${{ github.ref == 'refs/heads/main' }} ]]; then | ||
echo "CLOUDFLARE_BRANCH=main" >> $GITHUB_ENV | ||
else | ||
echo "CLOUDFLARE_BRANCH=pull-${{ github.event.pull_request.number }}" >> $GITHUB_ENV | ||
fi | ||
- name: Checkout repository | ||
uses: actions/[email protected] | ||
|
||
|
@@ -84,6 +97,7 @@ jobs: | |
const formatScore = score => `${Math.round(score * 100)} (${score})`; | ||
const getEmoji = score => score >= 0.9 ? '🟢' : score >= 0.5 ? '🟠' : '🔴'; | ||
const getColor = score => score >= 0.9 ? 'green' : score >= 0.5 ? 'orange' : 'red'; | ||
const score = res => `${getEmoji(res)} ${formatScore(res)}`; | ||
|
@@ -115,16 +129,31 @@ jobs: | |
].join('\n'); | ||
core.setOutput("comment", comment); | ||
core.setOutput("score", `${result.summary.score}`); | ||
core.setOutput("scoreColor", getColor(result.summary.score)); | ||
- name: Update comment with result | ||
uses: marocchino/[email protected] | ||
if: github.ref != 'refs/heads/main' | ||
with: | ||
header: ${{ env.COMMENT_ID }} | ||
message: ${{ steps.create_result_content.outputs.comment }} | ||
|
||
- name: Create Lighthouse Score badge | ||
uses: schneegans/[email protected] | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
auth: ${{ secrets.GIST_SECRET }} | ||
gistID: 795a3d6af5b0db5754cf7279898c3c16 | ||
filename: hellob.art-unlighthouse.json | ||
namedLogo: Lighthouse | ||
label: Lighthouse | ||
message: ${{ steps.create_result_content.outputs.score }} | ||
color: ${{ steps.create_result_content.outputs.scoreColor }} | ||
|
||
- name: Update comment on failure | ||
uses: marocchino/[email protected] | ||
if: ${{ failure() }} | ||
if: failure() && github.ref != 'refs/heads/main' | ||
with: | ||
header: ${{ env.COMMENT_ID }} | ||
message: | | ||
|
@@ -134,7 +163,7 @@ jobs: | |
- name: Update comment on cancel | ||
uses: marocchino/[email protected] | ||
if: ${{ cancelled() }} | ||
if: cancelled() && github.ref != 'refs/heads/main' | ||
with: | ||
header: ${{ env.COMMENT_ID }} | ||
message: | | ||
|
This file contains 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