-
Notifications
You must be signed in to change notification settings - Fork 26
/
Earthfile
162 lines (140 loc) · 4.67 KB
/
Earthfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
VERSION 0.8
ARG nodeVersion="lts"
ARG npmVersion="latest"
ARG --global docusaurusVersion="latest"
ARG --global docusaurusProject="docusaurus-gqlmd"
FROM docker.io/library/node:$nodeVersion-alpine
RUN export NODE_ENV=ci
RUN npm install -g npm@$npmVersion
RUN npm config set update-notifier false
WORKDIR /graphql-markdown
deps:
COPY package.json package-lock.json tsconfig.json tsconfig.base.json ./
COPY --dir config packages scripts ./
RUN npm ci
lint:
FROM +deps
RUN npm run ts:check
RUN npm run prettier -- --check
RUN npm run lint
build:
FROM +lint
RUN npm run build
unit-test:
FROM +build
RUN npm run test:ci /unit
integration-test:
FROM +build
RUN npm run test:ci /integration
mutation-test:
FROM +deps
RUN npm run stryker --workspaces --if-present -- --reporters progress,html
IF [ ! $(EARTHLY_CI) ]
SAVE ARTIFACT reports AS LOCAL ./reports
END
build-package:
FROM +build
ARG --required package
WORKDIR /graphql-markdown
RUN npm pack --workspace @graphql-markdown/$package | tail -n 1 | xargs -t -I{} mv {} graphql-markdown-$package.tgz
SAVE ARTIFACT graphql-markdown-$package.tgz
build-project:
FROM +build
WORKDIR /
IF [ "$docusaurusVersion" = "2" ]
RUN npx --quiet create-docusaurus@$docusaurusVersion "$docusaurusProject" classic --skip-install
ELSE
RUN npx --quiet create-docusaurus@$docusaurusVersion "$docusaurusProject" classic --skip-install --javascript
END
WORKDIR /$docusaurusProject
RUN rm -rf docs; rm -rf blog; rm -rf src; rm -rf static/img
DO +INSTALL_DOCUSARUS
setup-project:
FROM +build-project
WORKDIR /$docusaurusProject
DO +INSTALL_GRAPHQL
DO +INSTALL_GQLMD
COPY --dir ./packages/docusaurus/tests/__data__ ./data
COPY --dir ./website/static/img ./static/img
COPY --dir ./website/src/css ./src/css
RUN mv ./data/.graphqlrc ./.graphqlrc
RUN mv ./data/docusaurus2-graphql-doc-build.js ./docusaurus2-graphql-doc-build.js
RUN mv ./data/docusaurus2-graphql-doc-nobuild.js ./docusaurus2-graphql-doc-nobuild.js
RUN mv ./data/scripts/config-plugin.js ./config-plugin.js
RUN node config-plugin.js
smoke-test:
FROM +setup-project
WORKDIR /$docusaurusProject
RUN npm install -g jest
RUN npm install graphql-config
COPY --dir ./packages/docusaurus/tests/e2e ./__tests__/e2e
COPY --dir ./packages/docusaurus/tests/helpers ./__tests__/helpers
RUN mv ./__tests__/e2e/jest.config.js ./jest.config.js
RUN npx jest --runInBand
smoke-run:
ARG options=
FROM +setup-project
WORKDIR /$docusaurusProject
DO +GQLMD --options=$options
RUN npm run build
RUN npm run clear
build-examples:
LET folderDocs="examples"
FROM +setup-project
WORKDIR /$docusaurusProject
RUN npm install prettier
RUN mkdir $folderDocs
LET folderExample="default"
LET idExample="default"
DO +GQLMD --options="--homepage data/anilist.md --schema https://graphql.anilist.co/ --base . --link /${folderDocs}/${folderExample} --force --pretty --deprecated group"
RUN mv docs ./$folderDocs/$folderExample
SET folderExample="group-by"
SET idExample="schema_with_grouping"
DO +GQLMD --id="${idExample}" --options="--homepage data/groups.md --schema data/${idExample}.graphql --groupByDirective @doc(category|=Common) --base . --link /${folderDocs}/${folderExample} --skip @noDoc --index --noParentType --noRelatedType --deprecated group --noApiGroup"
RUN mv docs ./$folderDocs/$folderExample
SAVE ARTIFACT ./$folderDocs
build-docs:
COPY ./website ./
COPY (+build-examples/examples) ./examples
COPY --dir docs .
COPY --dir api .
RUN npm install
RUN npx update-browserslist-db@latest
RUN npm run build
SAVE ARTIFACT --force ./build AS LOCAL build
build-image:
FROM +build-docs
EXPOSE 8080
ENTRYPOINT ["npm", "run", "serve", "--", "--host=0.0.0.0", "--port=8080"]
SAVE IMAGE graphql-markdown:docs
all:
BUILD +lint
BUILD +build
BUILD +unit-test
BUILD +integration-test
BUILD +smoke-test
# --- UDCs ---
GQLMD:
FUNCTION
ARG id
ARG options
RUN mkdir -p docs
IF [ ! $id ]
RUN npx docusaurus graphql-to-doc $options 2>&1 | tee ./run.log
ELSE
RUN npx docusaurus graphql-to-doc:${id} $options 2>&1 | tee ./run.log
END
RUN test `grep -c -i "An error occurred" run.log` -eq 0 && echo "Success" || (echo "Failed with errors"; exit 1)
INSTALL_GQLMD:
FUNCTION
FOR package IN $(node /graphql-markdown/scripts/build-packages.js)
COPY (+build-package/graphql-markdown-${package}.tgz --package=${package}) ./
RUN npm install ./graphql-markdown-${package}.tgz
END
INSTALL_DOCUSARUS:
FUNCTION
RUN npm install
RUN npm upgrade @docusaurus/core @docusaurus/preset-classic
INSTALL_GRAPHQL:
FUNCTION
RUN npm install graphql @graphql-tools/url-loader @graphql-tools/graphql-file-loader