-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,901 additions
and
3,155 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Auto Merge Dependabot GitHub Actions Updates | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
|
||
jobs: | ||
auto-merge: | ||
if: github.actor == 'dependabot[bot]' | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Auto-merge Dependabot PRs | ||
run: | | ||
gh pr merge ${{ github.event.pull_request.number }} --squash --admin | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
|
@@ -9,49 +9,187 @@ jobs: | |
generate_lighthouse_audit: | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
contents: write | ||
actions: read | ||
|
||
steps: | ||
# wait arbitrary 120s for the build to finish, changes it if your builds are longer. Potential fix: https://github.com/marketplace/actions/await-for-vercel-deployment | ||
- run: sleep 120 | ||
- name: Retrieve Vercel Project and Team Info | ||
id: fetch_vercel_info | ||
env: | ||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
run: | | ||
# Extract the repository name | ||
project_name="${GITHUB_REPOSITORY##*/}" | ||
echo "Using project name: $project_name" | ||
# Fetch team info first | ||
teams_response=$(curl -s \ | ||
-H "Authorization: Bearer $VERCEL_TOKEN" \ | ||
"https://api.vercel.com/v2/teams") | ||
# Get the team ID for darkroom-engineering | ||
team_id=$(echo "$teams_response" | jq -r '.teams[] | select(.slug=="darkroom-engineering") | .id') | ||
echo "Retrieved Team ID: $team_id" | ||
# Fetch projects using team ID | ||
response=$(curl -s \ | ||
-H "Authorization: Bearer $VERCEL_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
"https://api.vercel.com/v9/projects?teamId=$team_id") | ||
# Get project ID for matching project name | ||
project_id=$(echo "$response" | jq -r ".projects[] | select(.name==\"$project_name\") | .id") | ||
echo "Retrieved Project ID: $project_id" | ||
# Set environment variables | ||
echo "VERCEL_TEAM_ID=$team_id" >> $GITHUB_ENV | ||
echo "VERCEL_PROJECT_ID=$project_id" >> $GITHUB_ENV | ||
- name: Capture Vercel preview URL | ||
id: vercel_preview_url | ||
uses: zentered/[email protected] | ||
env: | ||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
with: | ||
# find project id here: https://vercel.com/darkroom-engineering/satus/settings | ||
vercel_team_id: 'darkroom-engineering' | ||
vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID }} | ||
- uses: actions/[email protected] | ||
vercel_team_id: ${{ env.VERCEL_TEAM_ID }} | ||
vercel_project_id: ${{ env.VERCEL_PROJECT_ID }} | ||
|
||
- name: Wait for Vercel Deployment | ||
uses: UnlyEd/[email protected] | ||
id: await-vercel | ||
env: | ||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
with: | ||
deployment-url: "${{ steps.vercel_preview_url.outputs.preview_url }}" | ||
timeout: 300 # 5 minutes timeout | ||
poll-interval: 10 | ||
continue-on-error: true # Allow the workflow to continue even if deployment fails | ||
|
||
- name: Check deployment status | ||
id: deployment_check | ||
run: | | ||
if [ "${{ steps.await-vercel.outcome }}" == "failure" ]; then | ||
echo "deployment_failed=true" >> $GITHUB_OUTPUT | ||
echo "error_message=⚠️ Vercel deployment failed or timed out. Lighthouse audit could not be performed." >> $GITHUB_OUTPUT | ||
else | ||
echo "deployment_failed=false" >> $GITHUB_OUTPUT | ||
fi | ||
- uses: actions/checkout@v4 | ||
if: steps.deployment_check.outputs.deployment_failed != 'true' | ||
|
||
- name: Audit preview URL with Lighthouse | ||
id: lighthouse_audit | ||
if: steps.deployment_check.outputs.deployment_failed != 'true' | ||
uses: treosh/lighthouse-ci-action@v12 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
urls: | | ||
"https://${{ steps.vercel_preview_url.outputs.preview_url }}" | ||
uploadArtifacts: true | ||
temporaryPublicStorage: true | ||
|
||
- name: Format lighthouse score | ||
id: format_lighthouse_score | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary | ||
const link = ${{ steps.lighthouse_audit.outputs.manifest }}[0].url | ||
const formatResult = (res) => Math.round((res * 100)) | ||
Object.keys(result).forEach(key => result[key] = formatResult(result[key])) | ||
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴' | ||
const comment = [ | ||
try { | ||
// Check if deployment failed | ||
const deploymentFailed = '${{ steps.deployment_check.outputs.deployment_failed }}' === 'true'; | ||
if (deploymentFailed) { | ||
core.setOutput("comment", '${{ steps.deployment_check.outputs.error_message }}'); | ||
return; | ||
} | ||
// Add debug logging to see the raw output | ||
console.log('Raw lighthouse audit output:', JSON.stringify(${{ steps.lighthouse_audit.outputs.manifest }}, null, 2)); | ||
console.log('Raw links output:', JSON.stringify(${{ steps.lighthouse_audit.outputs.links }}, null, 2)); | ||
// Parse manifest with error checking | ||
let manifest; | ||
try { | ||
manifest = JSON.parse(JSON.stringify(${{ steps.lighthouse_audit.outputs.manifest }})); | ||
} catch (e) { | ||
throw new Error(`Failed to parse manifest: ${e.message}`); | ||
} | ||
// Validate manifest structure | ||
if (!manifest || !Array.isArray(manifest) || manifest.length === 0) { | ||
throw new Error('Lighthouse manifest is invalid or empty'); | ||
} | ||
// Get the first (and presumably only) result | ||
const result = manifest[0].summary; | ||
if (!result) { | ||
console.log('Full manifest structure:', JSON.stringify(manifest, null, 2)); | ||
throw new Error('Lighthouse summary is undefined in manifest'); | ||
} | ||
// Parse and validate links | ||
let links; | ||
try { | ||
links = JSON.parse(JSON.stringify(${{ steps.lighthouse_audit.outputs.links }})); | ||
} catch (e) { | ||
throw new Error(`Failed to parse links: ${e.message}`); | ||
} | ||
if (!links) { | ||
throw new Error('Lighthouse links are undefined'); | ||
} | ||
if (Object.keys(links).length === 0) { | ||
throw new Error('Lighthouse links object is empty'); | ||
} | ||
// Helper functions | ||
const formatResult = (res) => { | ||
if (typeof res !== 'number') { | ||
console.log(`Warning: Invalid result value: ${res}`); | ||
return 0; | ||
} | ||
return Math.round(res * 100); | ||
}; | ||
const score = (res) => { | ||
const numericRes = typeof res === 'number' ? res : 0; | ||
return numericRes >= 0.9 ? '🟢' : numericRes >= 0.5 ? '🟠' : '🔴'; | ||
}; | ||
// Generate report | ||
const reportUrl = manifest[0].url || Object.values(links)[0]; | ||
const formattedScores = [ | ||
`⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this commit:`, | ||
'', | ||
`${score(result.performance)} Performance: ${formatResult(result.performance)}`, | ||
`${score(result.accessibility)} Accessibility: ${formatResult(result.accessibility)}`, | ||
`${score(result['best-practices'])} Best practices: ${formatResult(result['best-practices'])}`, | ||
`${score(result.seo)} SEO: ${formatResult(result.seo)}`, | ||
'', | ||
`${score(result.performance)} Performance: ${result.performance}`, | ||
`${score(result.accessibility)} Accessibility: ${result.accessibility}`, | ||
`${score(result['best-practices'])} Best practices: ${result['best-practices']}`, | ||
`${score(result.seo)} SEO: ${result.seo}`, | ||
' ', | ||
`*Lighthouse ran on ${link} | ||
core.setOutput("comment", comment); | ||
`*Lighthouse ran on [${reportUrl}](${reportUrl})*` | ||
].join('\n'); | ||
// Set output | ||
core.setOutput("comment", formattedScores); | ||
} catch (error) { | ||
// Enhanced error logging | ||
console.error('Full error:', error); | ||
console.error('Error stack:', error.stack); | ||
// Set a user-friendly error message as the comment | ||
const errorMessage = '⚠️ Failed to generate Lighthouse report. Please check the workflow logs for more details.'; | ||
core.setOutput("comment", errorMessage); | ||
core.setFailed(`Formatting failed: ${error.message}`); | ||
} | ||
- name: Create commit comment | ||
uses: peter-evans/commit-comment@v3 | ||
with: | ||
body: | | ||
"${{ steps.format_lighthouse_score.outputs.comment }}" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
body: ${{ steps.format_lighthouse_score.outputs.comment }} |
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
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
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
Oops, something went wrong.
d4da350
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡️ Lighthouse report for the changes in this commit:
🟢 Performance: 98
🟢 Accessibility: 90
🟢 Best practices: 96
🟠 SEO: 63
Lighthouse ran on https://satus-cqoxvqujc-darkroom-engineering.vercel.app/