Skip to content

Commit

Permalink
split jobs based per url
Browse files Browse the repository at this point in the history
  • Loading branch information
ZibanPirate committed Sep 15, 2024
1 parent 6233a95 commit ec9d014
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.reusable.lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,42 @@ on:
required: true

jobs:
urls-for-lighthouse:
runs-on: ubuntu-latest
env:
LH_TEST_BASE_URL: ${{ inputs.testBaseUrl }}
steps:
- name: "Git"
uses: actions/checkout@v4
- name: "Nodejs"
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- run: npm ci
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build output (ubuntu-latest, 20)
- run: npx lerna run generate:lh-report --scope "@dzcode.io/web"
- name: Define Urls
id: define-urls
run: |
node web/lighthouserc.cjs --output-urls >> "$GITHUB_OUTPUT"
outputs:
urls: ${{ steps.define-urls.outputs.urls }}

lighthouse:
needs: urls-for-lighthouse
runs-on: ubuntu-latest
strategy:
matrix:
url: ${{fromJson(needs.urls-for-lighthouse.outputs.urls)}}
env:
LH_TEST_BASE_URL: ${{ inputs.testBaseUrl }}
LH_SERVER_BASE_URL: ${{ inputs.serverBaseUrl }}
LH_SERVER_TOKEN: ${{ inputs.stage == 'staging' && secrets.LH_SERVER_TOKEN_STG || secrets.LH_SERVER_TOKEN_PRD }}
LH_OVERWRITE_URL: ${{ matrix.url }}

steps:
- name: "Git"
Expand Down
18 changes: 11 additions & 7 deletions web/lighthouserc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ const { allLanguages } = require("@dzcode.io/models/dist/language");
const baseUrl = process.env.LH_TEST_BASE_URL;
const serverBaseUrl = process.env.LH_SERVER_BASE_URL;
const token = process.env.LH_SERVER_TOKEN;
const overwriteURL = process.env.LH_OVERWRITE_URL;

let urls = ["", "/contribute", "/team", "/projects", "/faq"];

const args = process.argv.slice(2);
if (args.includes("--output-urls")) {
console.log(`urls=${JSON.stringify(urls)}`);
} else if (overwriteURL) {
urls = [overwriteURL];
}

module.exports = {
ci: {
collect: {
url: [
"",
// "/contribute",
// "/team",
// "/projects",
// "/faq",
].reduce((acc, path) => {
url: urls.reduce((acc, path) => {
return acc.concat(
allLanguages.map(({ code }) => `${baseUrl}${code === "en" ? "" : `/${code}`}${path}`),
);
Expand Down

0 comments on commit ec9d014

Please sign in to comment.