Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting set up to run Lighthouse & Pa11y on all URLs #198

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
35 changes: 30 additions & 5 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
name: Build and deploy to preview environment, run tests
'on': pull_request
jobs:
build_and_preview:
build_and_deploy:
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
runs-on: ubuntu-latest
outputs:
urls: ${{ steps.urls.outputs.urls }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand All @@ -31,7 +30,33 @@ jobs:
STRAPI_API_URL: '${{ secrets.STRAPI_API_URL }}'
STRAPI_TOKEN: '${{ secrets.STRAPI_TOKEN }}'
- uses: FirebaseExtended/action-hosting-deploy@v0
id: deploy
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_CA_IT_PROD_HOME_5918 }}'
projectId: ca-it-prod-home-5918
- name: Generate URLs
id: urls
uses: actions/github-script@v6
with:
script: |
const fs = require("fs");
const pages = fs.readFileSync('pages.txt', 'utf-8');
const urls = [];
pages.split(/\r?\n/).forEach(page => {
urls.push(`${{ steps.deploy.outputs.details_url }}${page}`);
});
core.setOutput('urls', urls.join('\n'));
lighthouse:
needs: build_and_deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lighthouse CI Action
id: lighthouse
uses: treosh/lighthouse-ci-action@v10
with:
temporaryPublicStorage: true
configPath: ./.lighthouserc.yml
urls: |
${{ needs.build_and_deploy.outputs.urls }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ public
.DS_Store
.env
.env.*
*.log
*.logpages.txt
.lighthouseci
pages.txt
static/greenhouse.css
3 changes: 3 additions & 0 deletions .lighthouserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ci:
assert:
preset: lighthouse:no-pwa
19 changes: 19 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,23 @@ exports.createResolvers = ({ createResolvers }) => {
}
}
})
}

exports.onPostBuild = async ({ graphql }) => {
const path = require("path")
const fs = require("fs").promises
const { data } = await graphql(`
{
pages: allSitePage {
nodes {
path
}
}
}
`)

return fs.writeFile(
path.resolve(__dirname, "pages.txt"),
data.pages.nodes.map(node => node.path).join("\n")
)
}
Loading