forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Warmup getRemoteJSON's cache | ||
|
||
description: Run the script that prepares the disk-cache for getRemoteJSON | ||
|
||
inputs: | ||
restore-only: | ||
description: Only attempt to restore, don't warm up | ||
required: false | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
# The caching technique here is to unboundedly add and add to the cache. | ||
# You "wrap" the step that appends to disk and it will possibly retrieve | ||
# some from the cache, then save it when it's got more in it. | ||
- name: Cache .remotejson-cache (restore) | ||
# You can't use a SHA on these. Only possible with `actions/cache@SHA...` | ||
uses: actions/cache/restore@v3 | ||
with: | ||
path: .remotejson-cache | ||
key: remotejson-cache- | ||
restore-keys: remotejson-cache- | ||
|
||
# When we use this composite action from the workflows like | ||
# Azure Preview Deploy and Azure Production Deploy, we don't have | ||
# any Node installed or any of its packages. I.e. we never | ||
# run `npm ci` in those actions. For security sake. | ||
# So we can't do things that require Node code. | ||
# Tests and others will omit the `restore-only` input, but | ||
# prepping for Docker build and push, will set it to a non-empty | ||
# string which basically means "If you can restore it, great. | ||
# If not, that's fine, don't bother". | ||
- name: Run script | ||
if: ${{ inputs.restore-only == '' }} | ||
shell: bash | ||
run: node script/warmup-remotejson.js | ||
|
||
- name: Cache .remotejson-cache (save) | ||
if: ${{ inputs.restore-only == '' }} | ||
uses: actions/cache/save@v3 | ||
with: | ||
path: .remotejson-cache | ||
key: remotejson-cache-${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ jobs: | |
|
||
- name: Build | ||
run: npm run build | ||
|
||
- uses: ./.github/actions/warmup-remotejson-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env node | ||
|
||
// [start-readme] | ||
// | ||
// This calls a function directly that is used by our archived enterprise | ||
// middleware. Namely, the `getRemoteJSON` function. That function is | ||
// able to use the disk to cache responses quite aggressively. So when | ||
// it's been run once, with the same disk, next time it can draw from disk | ||
// rather than having to rely on network. | ||
// | ||
// We have this script to avoid excessive network fetches in production | ||
// where, due to production deploys restarting new Node services, we | ||
// can't rely on in-memory caching often enough. | ||
// | ||
// The list of URLs hardcoded in here is based on analyzing the URLs that | ||
// were logged as tags in Datadog for entries that couldn't rely on | ||
// in-memory cache. | ||
// | ||
// [end-readme] | ||
|
||
import { program } from 'commander' | ||
import semver from 'semver' | ||
|
||
import getRemoteJSON from '../middleware/get-remote-json.js' | ||
import { | ||
deprecated, | ||
firstReleaseStoredInBlobStorage, | ||
lastVersionWithoutArchivedRedirectsFile, | ||
} from '../lib/enterprise-server-releases.js' | ||
|
||
program | ||
.description( | ||
"Visit a bunch of archived redirects.json URLs to warm up getRemoteJSON's disk cache" | ||
) | ||
.parse(process.argv) | ||
|
||
main() | ||
|
||
function version2url(version) { | ||
const inBlobStorage = semver.gte( | ||
semver.coerce(version).raw, | ||
semver.coerce(firstReleaseStoredInBlobStorage).raw | ||
) | ||
return inBlobStorage | ||
? `https://githubdocs.azureedge.net/enterprise/${version}/redirects.json` | ||
: `https://github.github.com/help-docs-archived-enterprise-versions/${version}/redirects.json` | ||
} | ||
|
||
function withArchivedRedirectsFile(version) { | ||
return semver.eq( | ||
semver.coerce(version).raw, | ||
semver.coerce(lastVersionWithoutArchivedRedirectsFile).raw | ||
) | ||
} | ||
|
||
async function main() { | ||
const urls = [] | ||
for (const version of deprecated) { | ||
if (withArchivedRedirectsFile(version)) { | ||
break | ||
} | ||
urls.push(version2url(version)) | ||
} | ||
const config = { | ||
retry: { limit: 3 }, | ||
timeout: { response: 1000 }, | ||
} | ||
console.time(`Time to fetch ${urls.length} URLs`) | ||
await Promise.all(urls.map((url) => getRemoteJSON(url, config))) | ||
console.timeEnd(`Time to fetch ${urls.length} URLs`) | ||
} |