Skip to content

Commit 085d37d

Browse files
committed
feat: only do full update per day
1 parent 879c3bf commit 085d37d

File tree

4 files changed

+150
-11
lines changed

4 files changed

+150
-11
lines changed

.github/actions/build/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ runs:
4444
key: ${{ runner.os }}-gatsby-public-cache-${{ github.run_id }}
4545
restore-keys: ${{ runner.os }}-gatsby-public-cache-
4646
save-always: true
47+
- name: cache graphql response
48+
uses: actions/cache@v4
49+
with:
50+
path: cached_graphql.json
51+
key: ${{ runner.os }}-github-graphql-response-${{ github.run_id }}
52+
restore-keys: ${{ runner.os }}-github-graphql-response-
53+
save-always: true
4754
- name: Restore cache
4855
shell: bash
4956
run: node gh-pages-cache-restore.js
@@ -55,6 +62,7 @@ runs:
5562
echo "modules.lsposed.org" > ./public/CNAME
5663
env:
5764
GRAPHQL_TOKEN: ${{ inputs.token }}
65+
REPO: ${{ inputs.repo }}
5866
GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES: true
5967
- name: clean up caches on failure
6068
if: ${{ failure() || cancelled() }}
@@ -63,6 +71,7 @@ runs:
6371
rm -rf public/*
6472
rm -rf public-cache/*
6573
rm -rf .cache/*
74+
rm -f cached_graphql.json
6675
- name: Refresh cache
6776
shell: bash
6877
run: node gh-pages-cache.js

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
repo:
1010
description: 'repo name'
1111
required: false
12+
schedule:
13+
- cron: "0 0 * * *"
1214

1315
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1416
permissions:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ yarn-error.log
7878
!.yarn/releases
7979
!.yarn/sdks
8080
!.yarn/versions
81+
82+
cached_graphql.json

gatsby-node.js

Lines changed: 137 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,112 @@ const { execFileSync } = require('child_process')
88

99
const { fetchFromGithub, replacePrivateImage } = require('./github-source')
1010

11+
function makeRepositoryQuery (name) {
12+
return gql`
13+
{
14+
repository(owner: "Xposed-Modules-Repo", name: "${name}") {
15+
name
16+
description
17+
url
18+
homepageUrl
19+
collaborators(affiliation: DIRECT, first: 100) {
20+
edges {
21+
node {
22+
login
23+
name
24+
}
25+
}
26+
}
27+
readme: object(expression: "HEAD:README.md") {
28+
... on Blob {
29+
text
30+
}
31+
}
32+
summary: object(expression: "HEAD:SUMMARY") {
33+
... on Blob {
34+
text
35+
}
36+
}
37+
scope: object(expression: "HEAD:SCOPE") {
38+
... on Blob {
39+
text
40+
}
41+
}
42+
sourceUrl: object(expression: "HEAD:SOURCE_URL") {
43+
... on Blob {
44+
text
45+
}
46+
}
47+
hide: object(expression: "HEAD:HIDE") {
48+
... on Blob {
49+
text
50+
}
51+
}
52+
additionalAuthors: object(expression: "HEAD:ADDITIONAL_AUTHORS") {
53+
... on Blob {
54+
text
55+
}
56+
}
57+
latestRelease {
58+
name
59+
url
60+
isDraft
61+
description
62+
descriptionHTML
63+
createdAt
64+
publishedAt
65+
updatedAt
66+
tagName
67+
isPrerelease
68+
releaseAssets(first: 50) {
69+
edges {
70+
node {
71+
name
72+
contentType
73+
downloadUrl
74+
downloadCount
75+
size
76+
}
77+
}
78+
}
79+
}
80+
releases(first: 20) {
81+
edges {
82+
node {
83+
name
84+
url
85+
isDraft
86+
description
87+
descriptionHTML
88+
createdAt
89+
publishedAt
90+
updatedAt
91+
tagName
92+
isPrerelease
93+
isLatest
94+
releaseAssets(first: 50) {
95+
edges {
96+
node {
97+
name
98+
contentType
99+
downloadUrl
100+
downloadCount
101+
size
102+
}
103+
}
104+
}
105+
}
106+
}
107+
}
108+
updatedAt
109+
createdAt
110+
stargazerCount
111+
}
112+
}
113+
`
114+
}
115+
116+
11117
const PAGINATION = 10
12118
function makeRepositoriesQuery (cursor) {
13119
const arg = cursor ? `, after: "${cursor}"` : ''
@@ -292,7 +398,7 @@ exports.sourceNodes = async (
292398
let cursor = null
293399
let page = 1
294400
let total
295-
const mergedResult = {
401+
let mergedResult = {
296402
data: {
297403
organization: {
298404
repositories: {
@@ -301,23 +407,43 @@ exports.sourceNodes = async (
301407
}
302408
}
303409
}
304-
while (true) {
305-
console.log(`Querying GitHub API, page ${page}, total ${Math.ceil(total / PAGINATION) || 'unknown'}, cursor: ${cursor}`)
306-
const result = await fetchFromGithub(makeRepositoriesQuery(cursor))
410+
const repo_name = process.env.REPO ? process.env.REPO.split('/')[1] : null
411+
if (repo_name && fs.existsSync('./cached_graphql.json')) {
412+
const data = fs.readFileSync('./cached_graphql.json')
413+
mergedResult = JSON.parse(data)
414+
mergedResult.data.organization.repositories.edges.forEach((value, index, array) => {
415+
if (value.node.name === repo_name) {
416+
array.splice(index, 1)
417+
}
418+
})
419+
console.log(`Fetching ${repo_name} from GitHub API`)
420+
const result = await fetchFromGithub(makeRepositoryQuery(repo_name))
307421
if (result.errors || !result.data) {
308422
const errMsg = result.errors || 'result.data is null'
309423
console.error(errMsg)
310424
throw errMsg
311425
}
312-
mergedResult.data.organization.repositories.edges =
313-
mergedResult.data.organization.repositories.edges.concat(result.data.organization.repositories.edges)
314-
if (!result.data.organization.repositories.pageInfo.hasNextPage) {
315-
break
426+
mergedResult.data.organization.repositories.edges.unshift({'node': result.data.repository})
427+
} else {
428+
while (true) {
429+
console.log(`Querying GitHub API, page ${page}, total ${Math.ceil(total / PAGINATION) || 'unknown'}, cursor: ${cursor}`)
430+
const result = await fetchFromGithub(makeRepositoriesQuery(cursor))
431+
if (result.errors || !result.data) {
432+
const errMsg = result.errors || 'result.data is null'
433+
console.error(errMsg)
434+
throw errMsg
435+
}
436+
mergedResult.data.organization.repositories.edges =
437+
mergedResult.data.organization.repositories.edges.concat(result.data.organization.repositories.edges)
438+
if (!result.data.organization.repositories.pageInfo.hasNextPage) {
439+
break
440+
}
441+
cursor = result.data.organization.repositories.pageInfo.endCursor
442+
total = result.data.organization.repositories.totalCount
443+
page++
316444
}
317-
cursor = result.data.organization.repositories.pageInfo.endCursor
318-
total = result.data.organization.repositories.totalCount
319-
page++
320445
}
446+
fs.writeFileSync('./cached_graphql.json', JSON.stringify(mergedResult))
321447
generateGatsbyNode(mergedResult, createNode)
322448
}
323449

0 commit comments

Comments
 (0)