Skip to content

Commit

Permalink
Merge pull request #1175 from tubone24/test
Browse files Browse the repository at this point in the history
test
  • Loading branch information
tubone24 authored Dec 28, 2022
2 parents 909a44b + 9911e86 commit 506c680
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 8 deletions.
76 changes: 74 additions & 2 deletions .github/workflows/previewDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ jobs:
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- name: Cat cli.txt
- name: Create Netlify Draft URL Message
run: |
cat cli.txt
sed -i '1s/^/## Deploy Preview\\n/g' cli.txt
sed -i -z 's/\n/\\n/g' cli.txt
sed -i -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" cli.txt
cat cli.txt
- name: Post Netlify CLI Comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -213,7 +212,79 @@ jobs:
-H "Authorization: token ${GITHUB_TOKEN}" \
-d "{\"body\": \"$(cat cli.txt)\"}" \
${URL}
- name: get Netlify Draft URL
id: get-netlify-draft-url
run: |
echo "draftUrl=$(cat cli.txt | sed -r 's/.*Website Draft URL: (.*)\\n\\nIf everything.*/\1/')" >> $GITHUB_OUTPUT
outputs:
draftUrl: ${{ steps.get-netlify-draft-url.outputs.draftUrl }}

lighthouse:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: https://npm.pkg.github.com/
scope: '@tubone24'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cache
${{ steps.yarn-cache-dir-path.outputs.dir }}
node_modules
.cache
public
key: ${{ runner.os }}-build-${{ env.cache-version }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-version }}-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-build-
${{ runner.os }}-
- name: yarn install
env:
GATSBY_GITHUB_CLIENT_SECRET: ${{secrets.GATSBY_GITHUB_CLIENT_SECRET}}
GATSBY_GITHUB_CLIENT_ID: ${{secrets.GATSBY_GITHUB_CLIENT_ID}}
GATSBY_ALGOLIA_SEARCH_API_KEY: ${{secrets.GATSBY_ALGOLIA_SEARCH_API_KEY}}
GATSBY_ALGOLIA_INDEX_NAME: ${{secrets.GATSBY_ALGOLIA_INDEX_NAME}}
GATSBY_ALGOLIA_APP_ID: ${{secrets.GATSBY_ALGOLIA_APP_ID}}
GATSBY_ALGOLIA_ADMIN_API_KEY: ${{secrets.GATSBY_ALGOLIA_ADMIN_API_KEY}}
GATSBY_GITHUB_SHA: ${{ github.sha }}
FAUNADB_SERVER_SECRET: ${{secrets.FAUNADB_SERVER_SECRET}}
NETLIFY_ENV: deploy-preview
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: yarn install --frozen-lockfile
- name: run lighthouse benchmark
run: yarn benchmark ${{ needs.build.outputs.draftUrl }} ci
- name: summarize scores
run: |
touch summarize.txt
echo '# Lighthouse Score' >> summarize.txt
echo '## Desktop' >> summarize.txt
echo '' >> summarize.txt
cat benchmark/summary/desktop-*.txt | sed -z 's/\n/\\n/g' >> summarize.txt
echo '' >> summarize.txt
echo '' >> summarize.txt
echo '## Mobile' >> summarize.txt
echo '' >> summarize.txt
cat benchmark/summary/mobile-*.txt | sed -z 's/\n/\\n/g' >> summarize.txt
sed -i -z 's/\n/\\n/g' summarize.txt
- name: Post Lighthouse Score Comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: ${{ github.event.pull_request.comments_url }}
run: |
curl -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-d "{\"body\": \"$(cat summarize.txt)\"}" \
${URL}
dep-check:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -331,3 +402,4 @@ jobs:
-H "Authorization: token ${GITHUB_TOKEN}" \
-d "{\"body\": \"$(cat cli.txt)\"}" \
${URL}
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
The MIT License (MIT)

Copyright (c) 2011-2022 tubone

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

And

The src/content (BLOG ARTICLE) under the CC-BY.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,14 @@ The components used in my blog are managed using Storybook.

After production deploy, Run and report Lighthouse.

![lighthouse](https://i.imgur.com/NG260hR.png)

<https://tubone24.github.io/blog/lh/report.html>

Also, create PR, Check Lighthouse score via [pagespeedapi.runpagespeed](https://developers.google.com/speed/docs/insights/rest/v5/pagespeedapi/runpagespeed) and Comment your PR.

![lighthouseScoreWithGitHubComments](https://i.imgur.com/LZmrqgS.png)

## Bundle Analyzer

After production deploy, Run and report Bundle Analyzer.
Expand Down Expand Up @@ -265,3 +271,10 @@ Use Terraform Cloud to change Netlify configuration values.
## Automatic security vulnerability

[Brightsec](https://brightsec.com/)

# License

- The source code under the MIT LICENSE.
- `src/content` under the CC-BY [![CC-BY](https://i.creativecommons.org/l/by/4.0/88x31.png)](http://creativecommons.org/licenses/by/4.0/)

[tubone boyaki]: https://blog.tubone-project24.xyz "tubone boyaki"
Empty file added benchmark/summary/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"jest-environment-jsdom": "29.1.2",
"jest-location-mock": "1.0.9",
"lint-staged": "13.0.3",
"memlab": "1.1.30",
"memlab": "1.1.36",
"netlify-cli": "12.5.0",
"netlify-lambda": "2.0.15",
"nyc": "15.1.0",
Expand Down
19 changes: 18 additions & 1 deletion scripts/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,29 @@ const PAGE_SPEED_INSIGHTS_URL =
"https://www.googleapis.com/pagespeedonline/v5/runPagespeed";

const saveJsonFile = (obj, client) => {
const dateString = dayjs().format("yyyymmddhhMMss");
const dateString = dayjs().format("YYYYMMDDHHmmSSS");
const path = `./benchmark/raw/${client}-raw-${dateString}-${VERSION}.json`;
fs.writeFileSync(path, JSON.stringify(obj));
const lhPath = `./benchmark/${client}-lh-${dateString}-${VERSION}.json`;
fs.writeFileSync(lhPath, JSON.stringify(obj.lighthouseResult));
};

const summarizeScore = (obj, client) => {
const dateString = dayjs().format("YYYYMMDDHHmmSSS");
const path = `./benchmark/summary/${client}-${dateString}-${VERSION}.txt`;
const lighthouseResult = obj.lighthouseResult;
const summaryText = `performance: ${
lighthouseResult.categories.performance.score * 100
}\naccessibility: ${
lighthouseResult.categories.accessibility.score * 100
}\nbest-practices: ${
lighthouseResult.categories["best-practices"].score * 100
}\nseo: ${lighthouseResult.categories.seo.score * 100}\npwa: ${
lighthouseResult.categories.pwa.score * 100
}`;
fs.writeFileSync(path, summaryText);
};

const main = async () => {
for (const client of ["desktop", "mobile"]) {
const params = {
Expand Down Expand Up @@ -54,6 +70,7 @@ const main = async () => {
}

saveJsonFile(result.data, client);
summarizeScore(result.data, client);
}
};
(async () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17880,10 +17880,10 @@ memfs@^3.1.2, memfs@^3.2.2:
dependencies:
fs-monkey "^1.0.3"

[email protected].30:
version "1.1.30"
resolved "https://registry.yarnpkg.com/memlab/-/memlab-1.1.30.tgz#ca78f7d024c0e219a2e73a98f6bbc95c92711c9e"
integrity sha512-O0i6UM5XPRJUR+6ktaV1tmqUFwevMO4O5oqyIKGC9Fsxw3nXmCtVJCEYeMHD1Eucfgpy/O7QJApmqrdwNN9yag==
[email protected].36:
version "1.1.36"
resolved "https://registry.yarnpkg.com/memlab/-/memlab-1.1.36.tgz#4dabea770f5e1c697903de31b13fd6f72d3d806b"
integrity sha512-xRMnnDI88gNmkEaD0LOtFaCsVrsnKr6Z2ejL10ZITfdv8mS7XYbNEiTM/A5Lk2pNhPFdO+NqnEKH89EHQNwwgA==
dependencies:
"@memlab/api" "^1.0.11"
"@memlab/cli" "^1.0.11"
Expand Down

0 comments on commit 506c680

Please sign in to comment.