.gitlab-ci.yml 10.8 KB
Newer Older
1
2
# .gitlab-ci.yml
#
3
4
# polkadot
#
5
6
7
# pipelines can be triggered manually in the web
# setting DEPLOY_TAG will only deploy the tagged image

gabriel klawitter's avatar
gabriel klawitter committed
8
9
10
stages:
  - test
  - build
11
12
13
  - publish
  - deploy

Denis_P's avatar
Denis_P committed
14
image:                             paritytech/ci-linux:production
gabriel klawitter's avatar
gabriel klawitter committed
15
16

variables:
Denis_P's avatar
Denis_P committed
17
  GIT_STRATEGY:                    fetch
18
  GIT_DEPTH:                       100
gabriel klawitter's avatar
gabriel klawitter committed
19
  CI_SERVER_NAME:                  "GitLab CI"
Denis_P's avatar
Denis_P committed
20
  DOCKER_OS:                       "debian:stretch"
21
  ARCH:                            "x86_64"
22

23
.collect-artifacts:                &collect-artifacts
gabriel klawitter's avatar
gabriel klawitter committed
24
25
26
  artifacts:
    name:                          "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
    when:                          on_success
27
    expire_in:                     28 days
gabriel klawitter's avatar
gabriel klawitter committed
28
    paths:
Denis_P's avatar
Denis_P committed
29
      - artifacts/
gabriel klawitter's avatar
gabriel klawitter committed
30

31
.kubernetes-env:                   &kubernetes-env
32
33
34
  tags:
    - kubernetes-parity-build
  environment:
35
    name: parity-build
gabriel klawitter's avatar
gabriel klawitter committed
36

37
.docker-env:                       &docker-env
38
39
  retry:
    max: 2
40
    when:
41
42
43
      - runner_system_failure
      - unknown_failure
      - api_failure
44
45
  interruptible:                   true
  dependencies:                    []
46
47
48
  tags:
    - linux-docker

Denis_P's avatar
Denis_P committed
49
50
51
52
53
.compiler_info:                    &compiler_info
  before_script:
    - rustup show
    - cargo --version
    - sccache -s
gabriel klawitter's avatar
gabriel klawitter committed
54

55
.build-refs:                       &build-refs
56
  only:
57
58
59
60
61
62
63
64
65
66
67
    - master
    - schedules
    - web
    - /^v[0-9]+\.[0-9]+.*$/        # i.e. v1.0, v2.1rc1

.test-refs:                        &test-refs
  only:
    - master
    - schedules
    - web
    - /^v[0-9]+\.[0-9]+.*$/        # i.e. v1.0, v2.1rc1
68
    - /^[0-9]+$/
69

70
71
72
73
#### stage:                        test

check-runtime:
  stage:                           test
Denis_P's avatar
Denis_P committed
74
  image:                           paritytech/tools:latest
75
76
77
78
79
80
81
82
  <<:                              *kubernetes-env
  only:
    - /^[0-9]+$/
  variables:
    GITLAB_API:                    "https://gitlab.parity.io/api/v4"
    GITHUB_API_PROJECT:            "parity%2Finfrastructure%2Fgithub-api"
  script:
    - ./scripts/gitlab/check_runtime.sh
83
  interruptible:                   true
84
85
86
87
  allow_failure:                   true

check-line-width:
  stage:                           test
Denis_P's avatar
Denis_P committed
88
  image:                           paritytech/tools:latest
89
90
91
92
93
  <<:                              *kubernetes-env
  only:
    - /^[0-9]+$/
  script:
    - ./scripts/gitlab/check_line_width.sh
94
  interruptible:                   true
95
96
  allow_failure:                   true

97
publish-draft-release:
98
99
100
101
102
  stage:                           test
  only:
    - tags
    - /^v[0-9]+\.[0-9]+\.[0-9]+.*$/        # i.e. v1.0.1, v2.1.0rc1
  script:
103
    - apt-get -y update; apt-get -y install jq
104
    - ./scripts/gitlab/publish_draft_release.sh
s3krit's avatar
s3krit committed
105
106
  interruptible:                   true
  allow_failure:                   true
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
test-deterministic-wasm:
  stage:                           test
  <<:                              *docker-env
  except:
  script:
    # build runtime
    - WASM_BUILD_NO_COLOR=1 cargo build --verbose --release -p kusama-runtime -p polkadot-runtime -p westend-runtime
    # make checksum
    - sha256sum target/release/wbuild/target/wasm32-unknown-unknown/release/*.wasm > checksum.sha256
    # clean up – FIXME: can we reuse some of the artifacts?
    - cargo clean
    # build again
    - WASM_BUILD_NO_COLOR=1 cargo build --verbose --release -p kusama-runtime -p polkadot-runtime -p westend-runtime
    # confirm checksum
    - sha256sum -c checksum.sha256


Denis_P's avatar
Denis_P committed
125
test-linux-stable:                 &test
gabriel klawitter's avatar
gabriel klawitter committed
126
  stage:                           test
127
128
  <<:                              *test-refs
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
129
  <<:                              *compiler_info
130
131
132
133
  variables:
    RUST_TOOLCHAIN: stable
    # Enable debug assertions since we are running optimized builds for testing
    # but still want to have debug assertions.
134
    RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
135
    TARGET: native
136
  script:
137
    - time cargo test --all --release --verbose --locked --features runtime-benchmarks
Denis_P's avatar
Denis_P committed
138
    - sccache -s
139

140
141
142
143
144
145
146
147
check-web-wasm:                    &test
  stage:                           test
  <<:                              *test-refs
  <<:                              *docker-env
  <<:                              *compiler_info
  script:
    # WASM support is in progress. As more and more crates support WASM, we
    # should add entries here. See https://github.com/paritytech/polkadot/issues/625
148
149
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path runtime/polkadot/Cargo.toml
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path runtime/kusama/Cargo.toml
150
151
152
153
154
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path erasure-coding/Cargo.toml
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path parachain/Cargo.toml
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path primitives/Cargo.toml
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path rpc/Cargo.toml
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path statement-table/Cargo.toml
155
    - time cargo build --locked --target=wasm32-unknown-unknown --manifest-path cli/Cargo.toml --no-default-features --features browser
156
    - sccache -s
157

158
159
160
161
162
163
164
165
166
167
check-runtime-benchmarks:          &test
  stage:                           test
  <<:                              *test-refs
  <<:                              *docker-env
  <<:                              *compiler_info
  script:
    # Check that the node will compile with `runtime-benchmarks` feature flag.
    - time cargo check --features runtime-benchmarks
    - sccache -s

168
169
170
171
172
173
174
build-wasm-release:
  stage:                          build
  <<:                             *collect-artifacts
  <<:                             *docker-env
  <<:                             *compiler_info
  # Note: We likely only want to do this for tagged releases, hence the 'only:'
  only:
175
    - /^v[0-9]+\.[0-9]+.*$/        # i.e. v1.0, v2.1rc1
176
177
178
179
180
181
  script:
    - time wasm-pack build --target web --out-dir wasm --release cli -- --no-default-features --features browser
    - mkdir -p ./artifacts/wasm
    - cd ./cli/wasm/
    - for f in polkadot_cli*; do sha256sum "${f}" > "${f}.sha256"; done
    - mv ./polkadot_cli* ../../artifacts/wasm/.
182

Denis_P's avatar
Denis_P committed
183
build-linux-release:               &build
gabriel klawitter's avatar
gabriel klawitter committed
184
  stage:                           build
185
  <<:                              *collect-artifacts
186
187
  <<:                              *build-refs
  <<:                              *docker-env
Denis_P's avatar
Denis_P committed
188
  <<:                              *compiler_info
gabriel klawitter's avatar
gabriel klawitter committed
189
  script:
190
191
192
    - time cargo build --release --verbose
    - mkdir -p ./artifacts
    - mv ./target/release/polkadot ./artifacts/.
193
    - sha256sum ./artifacts/polkadot | tee ./artifacts/polkadot.sha256
194
    - VERSION="${CI_COMMIT_REF_NAME}" # will be tag or branch name
195
    - if [ "${CI_COMMIT_TAG}" ]; then
196
197
        EXTRATAG="latest";
      else
198
199
200
        EXTRATAG="$(./artifacts/polkadot --version |
          sed -n -r 's/^polkadot ([0-9.]+.*-[0-9a-f]{7,13})-.*$/\1/p')";
        EXTRATAG="${CI_COMMIT_REF_NAME}-${EXTRATAG}-$(cut -c 1-8 ./artifacts/polkadot.sha256)";
201
202
203
204
      fi
    - echo "Polkadot version = ${VERSION} (EXTRATAG ${EXTRATAG})"
    - echo -n ${VERSION} > ./artifacts/VERSION
    - echo -n ${EXTRATAG} > ./artifacts/EXTRATAG
205
    - cp -r scripts/docker/* ./artifacts
Denis_P's avatar
Denis_P committed
206
    - sccache -s
207

208
209
210
211
212
213
214

generate-impl-guide:
  stage:                          build
  image:
    name: michaelfbryan/mdbook-docker-image:latest
    entrypoint: [""]
  script:
215
    - mdbook build roadmap/implementers-guide
216

217
.publish-build:                    &publish-build
218
219
  stage:                           publish
  dependencies:
220
    - build-linux-release
221
    - build-wasm-release
Denis_P's avatar
Denis_P committed
222
  cache:                           {}
223
224
  <<:                              *build-refs
  <<:                              *kubernetes-env
225
226
  before_script:
    - test -s ./artifacts/VERSION || exit 1
227
228
229
230
231
    - test -s ./artifacts/EXTRATAG || exit 1
    - VERSION="$(cat ./artifacts/VERSION)"
    - EXTRATAG="$(cat ./artifacts/EXTRATAG)"
    - echo "Polkadot version = ${VERSION} (EXTRATAG ${EXTRATAG})"

232
233
234
235
236
237
publish-docker-release:
  <<:                              *publish-build
  image:                           docker:stable
  services:
    - docker:dind
  <<:                              *collect-artifacts
238
  variables:
239
240
241
242
243
    DOCKER_HOST:                   tcp://localhost:2375
    DOCKER_DRIVER:                 overlay2
    GIT_STRATEGY:                  none
    # DOCKERFILE:                  scripts/docker/Dockerfile
    CONTAINER_IMAGE:               parity/polkadot
244
  script:
245
246
247
248
    - test "$Docker_Hub_User_Parity" -a "$Docker_Hub_Pass_Parity"
        || ( echo "no docker credentials provided"; exit 1 )
    - docker login -u "$Docker_Hub_User_Parity" -p "$Docker_Hub_Pass_Parity"
    - docker info
249
    - cd ./artifacts
250
    - docker build
Denis_P's avatar
Denis_P committed
251
      --build-arg VCS_REF="${CI_COMMIT_SHA}"
252
      --build-arg BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
253
      --tag $CONTAINER_IMAGE:$VERSION
254
      --tag $CONTAINER_IMAGE:$EXTRATAG .
255
    - docker push $CONTAINER_IMAGE:$VERSION
256
    - docker push $CONTAINER_IMAGE:$EXTRATAG
257
258
  after_script:
    - docker logout
259
260
261
262
263
    # only VERSION information is needed for the deployment
    - find ./artifacts/ -depth -not -name VERSION -not -name artifacts -delete

publish-s3-release:
  <<:                              *publish-build
Denis_P's avatar
Denis_P committed
264
  image:                           paritytech/awscli:latest
265
266
267
268
269
  variables:
    GIT_STRATEGY:                  none
    BUCKET:                        "releases.parity.io"
    PREFIX:                        "polkadot/${ARCH}-${DOCKER_OS}"
  script:
270
    - echo "uploading objects to https://${BUCKET}/${PREFIX}/${VERSION}"
271
    - aws s3 sync ./artifacts/ s3://${BUCKET}/${PREFIX}/${VERSION}/
272
    - echo "update objects at https://${BUCKET}/${PREFIX}/${EXTRATAG}"
273
274
    - find ./artifacts -type f | while read file; do
      name="${file#./artifacts/}";
275
      aws s3api copy-object
276
        --copy-source ${BUCKET}/${PREFIX}/${VERSION}/${name}
277
        --bucket ${BUCKET} --key ${PREFIX}/${EXTRATAG}/${name};
278
      done
279
280
281
    - |
      cat <<-EOM
      |
282
      |  polkadot binary paths:
283
284
285
286
287
      |
      |  - https://${BUCKET}/${PREFIX}/${EXTRATAG}/polkadot
      |  - https://${BUCKET}/${PREFIX}/${VERSION}/polkadot
      |
      EOM
288
  after_script:
289
    - aws s3 ls s3://${BUCKET}/${PREFIX}/${EXTRATAG}/
290
        --recursive --human-readable --summarize
291

292
293
deploy-polkasync-kusama:
  stage:                           deploy
294
  <<:                              *build-refs
295
  variables:
296
297
    POLKADOT_CI_COMMIT_NAME:       "${CI_COMMIT_REF_NAME}"
    POLKADOT_CI_COMMIT_REF:        "${CI_COMMIT_REF}"
298
  allow_failure:                   true
299
  trigger:                         "parity/infrastructure/parity-testnet"
300
301
302
303
304

#### stage:                       .post

check-labels:
  stage:                          .post
Denis_P's avatar
Denis_P committed
305
  image:                          paritytech/tools:latest
306
307
308
309
  <<:                             *kubernetes-env
  only:
    - /^[0-9]+$/
  script:
310
    - ./scripts/gitlab/check_labels.sh