Skip to content

Commit 2b1dcb1

Browse files
authored
Merge pull request github#20709 from github/repo-sync
repo sync
2 parents 02f27ca + 83cdf0b commit 2b1dcb1

File tree

5 files changed

+108
-12
lines changed

5 files changed

+108
-12
lines changed

.github/workflows/sync-search-elasticsearch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ jobs:
8686
run: |
8787
mkdir /tmp/records
8888
npm run sync-search-indices -- \
89-
-l ${{ matrix.language }} \
90-
-o /tmp/records \
89+
--language ${{ matrix.language }} \
90+
--out-directory /tmp/records \
9191
--no-compression --no-lunr-index
9292
9393
ls -lh /tmp/records

.github/workflows/sync-search-pr.yml

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Sync search - PR
22

3-
# **What it does**: Tries running the sync-search when relevant files change.
3+
# **What it does**: This does what `sync-sarch-elasticsearch.yml` does but
4+
# with a localhost Elasticsearch and only for English.
45
# **Why we have it**: To test that the script works and the popular pages json is valid.
56
# **Who does it impact**: Docs engineering.
67

@@ -21,10 +22,26 @@ concurrency:
2122
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
2223
cancel-in-progress: true
2324

25+
env:
26+
# Yes, it's hardcoded but it makes all the steps look exactly the same
27+
# as they do in `sync-search-elasticsearch.yml` where it uses
28+
# that `${{ env.ELASTICSEARCH_URL }}`
29+
ELASTICSEARCH_URL: http://localhost:9200
30+
2431
jobs:
2532
lint:
26-
runs-on: ubuntu-latest
33+
runs-on: ${{ fromJSON('["ubuntu-latest", "ubuntu-20.04-xl"]')[github.repository == 'github/docs-internal'] }}
2734
steps:
35+
- uses: getong/elasticsearch-action@95b501ab0c83dee0aac7c39b7cea3723bef14954
36+
with:
37+
# # Make sure this matches production and `test.yml`
38+
elasticsearch version: '7.11.1'
39+
host port: 9200
40+
container port: 9200
41+
host node port: 9300
42+
node port: 9300
43+
discovery type: 'single-node'
44+
2845
- name: Check out repo
2946
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748
3047

@@ -46,9 +63,57 @@ jobs:
4663
- name: Build
4764
run: npm run build
4865

49-
- name: Run sync-search
66+
- name: Start the server in the background
67+
env:
68+
ENABLE_DEV_LOGGING: false
69+
run: |
70+
npm run sync-search-server > /tmp/stdout.log 2> /tmp/stderr.log &
71+
72+
# first sleep to give it a chance to start
73+
sleep 6
74+
curl --retry-connrefused --retry 4 -I http://localhost:4002/
75+
76+
- if: ${{ failure() }}
77+
name: Debug server outputs on errors
78+
run: |
79+
echo "____STDOUT____"
80+
cat /tmp/stdout.log
81+
echo "____STDERR____"
82+
cat /tmp/stderr.log
83+
84+
- name: Scrape records into a temp directory
5085
env:
51-
# Set filtered to only these so it doesn't run for too long.
52-
LANGUAGE: en
53-
VERSION: free-pro-team@latest
54-
run: npm run sync-search
86+
# If a reusable, or anything in the `data/*` directory is deleted
87+
# you might get a
88+
#
89+
# RenderError: Can't find the key 'site.data.reusables...' in the scope
90+
#
91+
# But that'll get fixed in the next translation pipeline. For now,
92+
# let's just accept an empty string instead.
93+
THROW_ON_EMPTY: false
94+
95+
run: |
96+
mkdir /tmp/records
97+
npm run sync-search-indices -- \
98+
--language en \
99+
--version dotcom \
100+
--out-directory /tmp/records \
101+
--no-compression --no-lunr-index
102+
103+
ls -lh /tmp/records
104+
105+
- name: Check that Elasticsearch is accessible
106+
run: |
107+
curl --fail --retry-connrefused --retry 5 -I ${{ env.ELASTICSEARCH_URL }}
108+
109+
- name: Index into Elasticsearch
110+
run: |
111+
./script/search/index-elasticsearch.js \
112+
--language en \
113+
--version dotcom \
114+
--source-directory /tmp/records
115+
116+
- name: Check created indexes and aliases
117+
run: |
118+
curl --fail --retry-connrefused --retry 5 ${{ env.ELASTICSEARCH_URL }}/_cat/indices?v
119+
curl --fail --retry-connrefused --retry 5 ${{ env.ELASTICSEARCH_URL }}/_cat/indices?v

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
if: ${{ matrix.test-group == 'content' }}
5656
uses: getong/elasticsearch-action@95b501ab0c83dee0aac7c39b7cea3723bef14954
5757
with:
58+
# Make sure this matches production and `sync-search-pr.yml`
5859
elasticsearch version: '7.11.1'
5960
host port: 9200
6061
container port: 9200

lib/hydro.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import got from 'got'
55

66
import statsd from '../lib/statsd.js'
77
import FailBot from '../lib/failbot.js'
8-
98
const TIME_OUT_TEXT = 'ms has passed since batch creation'
109

1110
const MOCK_HYDRO_POST =

script/search/sync-search-indices.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@
77
//
88
// [end-readme]
99

10+
import assert from 'assert'
1011
import path from 'path'
1112

1213
import { program, Option } from 'commander'
1314

1415
import { languageKeys } from '../../lib/languages.js'
15-
import { allVersionKeys } from '../../lib/all-versions.js'
16+
import { allVersions } from '../../lib/all-versions.js'
1617
import searchSync from './sync.js'
1718

19+
const shortNames = Object.fromEntries(
20+
Object.values(allVersions).map((info) => {
21+
const shortName = info.hasNumberedReleases
22+
? info.miscBaseName + info.currentRelease
23+
: info.miscBaseName
24+
return [shortName, info]
25+
})
26+
)
27+
28+
const allVersionKeys = [...Object.keys(shortNames), ...Object.keys(allVersions)]
29+
1830
const DEFAULT_OUT_DIRECTORY = path.join('lib', 'search', 'indexes')
1931

2032
program
@@ -84,6 +96,25 @@ async function main(opts) {
8496
}
8597
}
8698

99+
// A `--version` or `process.env.VERSION` was specified, we need to convert
100+
// it to the long name. I.e. `free-pro-team@latest`. Not `dotcom`.
101+
// But it could also have beeb specified as `all` which means that `version`
102+
// here ill be `undefined` which is also OK.
103+
// const indexVersion = shortNames[version].hasNumberedReleases
104+
// ? shortNames[version].currentRelease
105+
// : shortNames[version].miscBaseName
106+
107+
let indexVersion
108+
if (version && version !== 'all') {
109+
// If it has been specified, it needs to be in the "long-form".
110+
// I.e. `[email protected]` not `ghes-3.5`.
111+
indexVersion = version in shortNames ? shortNames[version].version : version
112+
}
113+
assert(
114+
!indexVersion || indexVersion in allVersions,
115+
`version must be undefined or one of ${Object.keys(allVersions)}`
116+
)
117+
87118
let dryRun = false
88119
if ('dryRun' in opts) {
89120
dryRun = opts.dryRun
@@ -101,7 +132,7 @@ async function main(opts) {
101132
dryRun,
102133
language,
103134
notLanguage,
104-
version,
135+
version: indexVersion,
105136
outDirectory,
106137
compressFiles,
107138
generateLunrIndex,

0 commit comments

Comments
 (0)