Skip to content

Commit db58604

Browse files
authored
ci: add integrity checks for website urls (dotansimha#8085)
1 parent ed07ffb commit db58604

File tree

7 files changed

+329
-56
lines changed

7 files changed

+329
-56
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Website Integrity
2+
on:
3+
pull_request:
4+
paths:
5+
- 'website/**'
6+
jobs:
7+
website-check:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v3
12+
- name: Fetch
13+
run: git fetch origin master
14+
- name: Use Node 18
15+
uses: actions/setup-node@master
16+
with:
17+
node-version: 18
18+
cache: 'yarn'
19+
20+
- name: Cache Node Modules
21+
uses: actions/cache@v3
22+
id: node-modules-cache-website-integrity
23+
with:
24+
path: '**/node_modules'
25+
key: ${{runner.os}}-18-node-modules-${{hashFiles('yarn.lock')}}
26+
restore-keys: |
27+
${{runner.os}}-18-node-modules-
28+
- name: Install Dependencies using Yarn
29+
run: yarn install --ignore-engines --frozen-lockfile --immutable
30+
if: steps.node-modules-cache-website-integrity.outputs.cache-hit != 'true'
31+
32+
- name: Build Packages
33+
run: yarn build
34+
35+
- name: Build Website
36+
run: yarn workspace website run build
37+
38+
- name: Compare
39+
run: git diff origin/${{ github.base_ref }}.. -- website/route-lockfile.txt
40+
41+
- name: Diff to file
42+
if: always()
43+
id: diff_result
44+
run: |
45+
OUTPUT=$(git diff origin/${{ github.base_ref }}.. -- website/route-lockfile.txt)
46+
OUTPUT="${OUTPUT//'%'/'%25'}"
47+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
48+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
49+
echo "::set-output name=result::$OUTPUT"
50+
51+
- name: Publish a message
52+
if: always() && contains(steps.diff_result.outputs.result, 'diff')
53+
uses: marocchino/sticky-pull-request-comment@v2
54+
with:
55+
message: |
56+
```diff
57+
${{ steps.diff_result.outputs.result }}
58+
```

website/next-sitemap.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('next-sitemap').IConfig} */
2+
3+
module.exports = {
4+
siteUrl: process.env.SITE_URL || 'https://www.graphql-code-generator.com',
5+
};

website/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"scripts": {
66
"algolia-sync": "node scripts/algolia-ci.mjs",
7+
"postbuild": "npx next-sitemap && node scripts/sitemap-ci.mjs",
78
"start": "yarn generate-json-config && next start",
89
"build": "yarn generate-json-config && next build",
910
"dev": "concurrently -r 'next-remote-watch ./docs ./src/pages/_app.tsx' 'wait-on -s 1 http://localhost:3000'",
@@ -22,6 +23,7 @@
2223
"concurrently": "7.2.2",
2324
"esbuild-register": "3.3.3",
2425
"eslint-config-next": "12.2.2",
26+
"fast-xml-parser": "^4.0.9",
2527
"jsonpath": "1.1.1",
2628
"typescript": "4.7.4",
2729
"wait-on": "6.0.1"
@@ -87,12 +89,13 @@
8789
"next-i18next": "11.0.0",
8890
"next-remote-watch": "1.0.0",
8991
"next-seo": "5.4.0",
92+
"next-sitemap": "^3.1.10",
9093
"node-polyfill-webpack-plugin": "2.0.0",
9194
"react": "17.0.2",
9295
"react-dom": "17.0.2",
96+
"react-icons": "4.4.0",
9397
"react-markdown": "8.0.3",
9498
"react-select": "5.4.0",
95-
"react-icons": "4.4.0",
9699
"react-use": "17.4.0",
97100
"remark-admonitions": "1.2.1",
98101
"shiki": "0.10.1",

website/public/config.schema.json

Lines changed: 105 additions & 55 deletions
Large diffs are not rendered by default.

website/route-lockfile.txt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
/docs/advanced/generated-files-colocation
3+
/docs/advanced/how-does-it-work
4+
/docs/advanced/profiler
5+
/docs/advanced/programmatic-usage
6+
/docs/config-reference/codegen-config
7+
/docs/config-reference/config-field
8+
/docs/config-reference/documents-field
9+
/docs/config-reference/lifecycle-hooks
10+
/docs/config-reference/multiproject-config
11+
/docs/config-reference/naming-convention
12+
/docs/config-reference/require-field
13+
/docs/config-reference/schema-field
14+
/docs/custom-codegen
15+
/docs/custom-codegen/contributing
16+
/docs/custom-codegen/extend-schema
17+
/docs/custom-codegen/index
18+
/docs/custom-codegen/plugin-structure
19+
/docs/custom-codegen/using-visitor
20+
/docs/custom-codegen/validate-configuration
21+
/docs/getting-started
22+
/docs/getting-started/codegen-config -> /docs/config-reference/codegen-config
23+
/docs/getting-started/config-field -> /docs/config-reference/config-field
24+
/docs/getting-started/config-reference/codegen-config -> /docs/config-reference/codegen-config
25+
/docs/getting-started/development-workflow
26+
/docs/getting-started/documents-field -> /docs/config-reference/documents-field
27+
/docs/getting-started/how-does-it-work -> /docs/advanced/how-does-it-work
28+
/docs/getting-started/index
29+
/docs/getting-started/installation
30+
/docs/getting-started/lifecycle-hooks -> /docs/config-reference/lifecycle-hooks
31+
/docs/getting-started/naming-convention -> /docs/config-reference/naming-convention
32+
/docs/getting-started/require-field -> /docs/config-reference/require-field
33+
/docs/getting-started/schema-field -> /docs/config-reference/schema-field
34+
/docs/guides/angular
35+
/docs/guides/front-end-typescript-only
36+
/docs/guides/further-reading
37+
/docs/guides/graphql-modules
38+
/docs/guides/graphql-server-apollo-yoga
39+
/docs/guides/react
40+
/docs/guides/svelte
41+
/docs/guides/vue
42+
/docs/integrations/apollo-local-state
43+
/docs/integrations/create-react-app
44+
/docs/integrations/federation
45+
/docs/integrations/gatsby
46+
/docs/integrations/prettier
47+
/docs/integrations/vscode
48+
/docs/migration/from-0-13
49+
/docs/migration/from-0-18
50+
/plugins
51+
/plugins/add
52+
/plugins/c-sharp-operations
53+
/plugins/flow-operations
54+
/plugins/flow-resolvers
55+
/plugins/fragment-matcher
56+
/plugins/gql-tag-operations-preset
57+
/plugins/graphql-modules-preset
58+
/plugins/hasura-allow-list
59+
/plugins/import-types-preset
60+
/plugins/introspection
61+
/plugins/java
62+
/plugins/java-apollo-android
63+
/plugins/java-resolvers
64+
/plugins/jsdoc
65+
/plugins/kotlin
66+
/plugins/named-operations-object
67+
/plugins/near-operation-file-preset
68+
/plugins/reason-client
69+
/plugins/relay-operation-optimizer
70+
/plugins/schema-ast
71+
/plugins/time
72+
/plugins/typed-document-node
73+
/plugins/typescript
74+
/plugins/typescript-apollo-angular
75+
/plugins/typescript-apollo-client-helpers
76+
/plugins/typescript-apollo-next
77+
/plugins/typescript-document-nodes
78+
/plugins/typescript-generic-sdk
79+
/plugins/typescript-graphql-files-modules
80+
/plugins/typescript-graphql-request
81+
/plugins/typescript-mongodb
82+
/plugins/typescript-msw
83+
/plugins/typescript-oclif
84+
/plugins/typescript-operations
85+
/plugins/typescript-react-apollo
86+
/plugins/typescript-react-query
87+
/plugins/typescript-resolvers
88+
/plugins/typescript-rtk-query
89+
/plugins/typescript-stencil-apollo
90+
/plugins/typescript-svelte-apollo
91+
/plugins/typescript-type-graphql
92+
/plugins/typescript-urql
93+
/plugins/typescript-validation-schema
94+
/plugins/typescript-vue-apollo
95+
/plugins/typescript-vue-apollo-smart-ops
96+
/plugins/typescript-vue-urql
97+
/plugins/urql-introspection

website/scripts/sitemap-ci.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { XMLParser } from 'fast-xml-parser';
2+
import { fileURLToPath } from 'url';
3+
import { dirname } from 'path';
4+
import * as fs from 'fs';
5+
import * as path from 'path';
6+
import config from '../next.config.mjs';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
10+
const sitemapPath = path.join(__dirname, '..', 'public', 'sitemap-0.xml');
11+
const lockfilePath = path.join(__dirname, '..', 'route-lockfile.txt');
12+
13+
async function main() {
14+
const parser = new XMLParser();
15+
16+
const d = parser.parse(fs.readFileSync(sitemapPath, 'utf-8'));
17+
18+
const routes = d.urlset.url.map(url => url.loc.replace(`https://www.graphql-code-generator.com`, ``));
19+
20+
const redirectsPointingToNonExistingStuff = [];
21+
22+
const redirects = await config.redirects();
23+
24+
for (const redirect of redirects) {
25+
if (routes.includes(redirect.destination) === false) {
26+
redirectsPointingToNonExistingStuff.push(redirect);
27+
} else {
28+
routes.push(`${redirect.source} -> ${redirect.destination}`);
29+
}
30+
}
31+
32+
fs.writeFileSync(lockfilePath, routes.sort().join(`\n`) + `\n`);
33+
}
34+
35+
main();

yarn.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,11 @@
20722072
human-id "^1.0.2"
20732073
prettier "^1.19.1"
20742074

2075+
"@corex/deepmerge@^4.0.29":
2076+
version "4.0.29"
2077+
resolved "https://registry.yarnpkg.com/@corex/deepmerge/-/deepmerge-4.0.29.tgz#af9debf07d7f6b0d2a9d04a266abf2c1418ed2f6"
2078+
integrity sha512-q/yVUnqckA8Do+EvAfpy7RLdumnBy9ZsducMUtZTvpdbJC7azEf1hGtnYYxm0QfphYxjwggv6XtH64prvS1W+A==
2079+
20752080
"@cspotcode/source-map-support@^0.8.0":
20762081
version "0.8.1"
20772082
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
@@ -7558,6 +7563,13 @@ fast-shallow-equal@^1.0.0:
75587563
resolved "https://registry.yarnpkg.com/fast-shallow-equal/-/fast-shallow-equal-1.0.0.tgz#d4dcaf6472440dcefa6f88b98e3251e27f25628b"
75597564
integrity sha512-HPtaa38cPgWvaCFmRNhlc6NG7pv6NUHqjPgVAkWGoB9mQMwYB27/K0CvOM5Czy+qpT3e8XJ6Q4aPAnzpNpzNaw==
75607565

7566+
fast-xml-parser@^4.0.9:
7567+
version "4.0.9"
7568+
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-4.0.9.tgz#3a81dab7b4952b8d38f0136d28bd055b80ed6512"
7569+
integrity sha512-4G8EzDg2Nb1Qurs3f7BpFV4+jpMVsdgLVuG1Uv8O2OHJfVCg7gcA53obuKbmVqzd4Y7YXVBK05oJG7hzGIdyzg==
7570+
dependencies:
7571+
strnum "^1.0.5"
7572+
75617573
fastest-stable-stringify@^2.0.2:
75627574
version "2.0.2"
75637575
resolved "https://registry.yarnpkg.com/fastest-stable-stringify/-/fastest-stable-stringify-2.0.2.tgz#3757a6774f6ec8de40c4e86ec28ea02417214c76"
@@ -11184,6 +11196,14 @@ [email protected]:
1118411196
resolved "https://registry.yarnpkg.com/next-seo/-/next-seo-5.4.0.tgz#37a7784b30b3f70cec3fa0d77f9dde5990822d24"
1118511197
integrity sha512-R9DhajPwJnR/lsF2hZ8cN8uqr5CVITsRrCG1AF5+ufcaybKYOvnH8sH9MaH4/hpkps3PQ9H71S7J7SPYixAYzQ==
1118611198

11199+
next-sitemap@^3.1.10:
11200+
version "3.1.10"
11201+
resolved "https://registry.yarnpkg.com/next-sitemap/-/next-sitemap-3.1.10.tgz#876d0373330874e48c86a849eab94dc1bb439e17"
11202+
integrity sha512-IslH1nxY5p/3+cdjFiXDFSfchUJ0R+Flvm/T/01y7xokA/hd4rnuU+Jh0ZEZ92j7zBgwPUp1KTg0B41zuSpVHw==
11203+
dependencies:
11204+
"@corex/deepmerge" "^4.0.29"
11205+
minimist "^1.2.6"
11206+
1118711207
1118811208
version "12.2.2"
1118911209
resolved "https://registry.yarnpkg.com/next/-/next-12.2.2.tgz#029bf5e4a18a891ca5d05b189b7cd983fd22c072"
@@ -13610,6 +13630,11 @@ strip-json-comments@^3.1.0, strip-json-comments@^3.1.1:
1361013630
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
1361113631
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==
1361213632

13633+
strnum@^1.0.5:
13634+
version "1.0.5"
13635+
resolved "https://registry.yarnpkg.com/strnum/-/strnum-1.0.5.tgz#5c4e829fe15ad4ff0d20c3db5ac97b73c9b072db"
13636+
integrity sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==
13637+
1361313638
style-to-object@^0.3.0:
1361413639
version "0.3.0"
1361513640
resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-0.3.0.tgz#b1b790d205991cc783801967214979ee19a76e46"

0 commit comments

Comments
 (0)