diff --git a/.github/workflows/previewDeploy.yml b/.github/workflows/previewDeploy.yml index 2f15d7169a..c82910bdfc 100644 --- a/.github/workflows/previewDeploy.yml +++ b/.github/workflows/previewDeploy.yml @@ -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 }} @@ -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: @@ -331,3 +402,4 @@ jobs: -H "Authorization: token ${GITHUB_TOKEN}" \ -d "{\"body\": \"$(cat cli.txt)\"}" \ ${URL} + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..6c4ec43200 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md index 71b76f80df..57fe887561 100644 --- a/README.md +++ b/README.md @@ -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) + +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. @@ -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" diff --git a/benchmark/summary/.gitkeep b/benchmark/summary/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/package.json b/package.json index 037971215c..fb55e60ea0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/benchmark.js b/scripts/benchmark.js index 2c9fe24957..111952e578 100644 --- a/scripts/benchmark.js +++ b/scripts/benchmark.js @@ -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 = { @@ -54,6 +70,7 @@ const main = async () => { } saveJsonFile(result.data, client); + summarizeScore(result.data, client); } }; (async () => { diff --git a/yarn.lock b/yarn.lock index 0a98492d0a..0d0d265932 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17880,10 +17880,10 @@ memfs@^3.1.2, memfs@^3.2.2: dependencies: fs-monkey "^1.0.3" -memlab@1.1.30: - version "1.1.30" - resolved "https://registry.yarnpkg.com/memlab/-/memlab-1.1.30.tgz#ca78f7d024c0e219a2e73a98f6bbc95c92711c9e" - integrity sha512-O0i6UM5XPRJUR+6ktaV1tmqUFwevMO4O5oqyIKGC9Fsxw3nXmCtVJCEYeMHD1Eucfgpy/O7QJApmqrdwNN9yag== +memlab@1.1.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"