-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
70 lines (70 loc) · 2.44 KB
/
.gitlab-ci.yml
File metadata and controls
70 lines (70 loc) · 2.44 KB
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
# generate job triggered by push; Netlify build triggered by same event
generate:
stage: build
except:
refs:
- schedules
- triggers
image:
name: antora/antora:2.2.0
cache:
paths:
- .cache/
script:
- antora --fetch --url=https://gitlab.com/$CI_PROJECT_PATH/-/jobs/$CI_JOB_ID/artifacts/browse/public antora-playbook.yml
artifacts:
expire_in: 1 week
paths:
- public/
# deploy/netlify job triggered by nightly schedule
trigger/netlify:
stage: build
only:
refs:
- schedules
variables:
- $NETLIFY_BUILD_HOOK
image:
name: antora/antora:2.2.0
script:
- curl -X POST -d '' -s $NETLIFY_BUILD_HOOK
# index job triggered when production Netlify deploy succeeds
# CI_PIPELINE_SOURCE=trigger, TRIGGER_ACTION=index, and CI_COMMIT_REF_NAME=master
# a trigger cannot see merge requests, so there's no concern of them triggering this job
index:
stage: build
only:
refs:
- triggers
variables:
# TRIGGER_ACTION defined by outgoing webhook in Netlify
- $TRIGGER_ACTION == "index"
except:
# variables use OR logic
variables:
# ALGOLIA_APP_ID and ALGOLIA_API_KEY defined in CI configuration
- $ALGOLIA_APP_ID == null
- $ALGOLIA_API_KEY == null
image:
name: algolia/docsearch-scraper:steady
entrypoint: [""]
variables:
APPLICATION_ID: $ALGOLIA_APP_ID
API_KEY: $ALGOLIA_API_KEY
CONFIG: $CI_PROJECT_DIR/docsearch/config.json
before_script:
- apt-get -qq update
- apt-get install -y jq > /dev/null
script:
# only index every other day
- if [ $(( $(date +%-d) % 2 )) -eq 0 ]; then echo "Skip day."; exit 0; fi
# just to be safe, verify the ref name is master; exit otherwise
- if [ "$CI_COMMIT_REF_NAME" != "master" ]; then echo "Expected ref to be master."; exit 1; fi
- cd /root
# TODO remove workaround once https://github.com/algolia/docsearch-scraper/issues/425 is resolved
- sed -i '/config[.]update_nb_hits/d' src/index.py
- ALGOLIA_IDX_NAME=$(cat $CONFIG | jq -r '.index_name')
# TODO remove workaround once https://github.com/algolia/docsearch-scraper/issues/426 is resolved
- INDEXING_IN_PROGRESS=$(curl -s -H "X-Algolia-Application-Id:$ALGOLIA_APP_ID" -H "X-Algolia-API-Key:$ALGOLIA_API_KEY" "https://$ALGOLIA_APP_ID-dsn.algolia.net/1/indexes/${ALGOLIA_IDX_NAME}_tmp" | jq -r '.status? != 404')
- if [ "$INDEXING_IN_PROGRESS" == "true" ]; then echo "Indexing already in progress. Skipping."; exit 0; fi
- pipenv run python -m src.index