-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
183 lines (167 loc) · 6.43 KB
/
.gitlab-ci.yml
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# .gitlab-ci.yml
#
# substrate-contracts-node
#
# pipelines can be triggered manually in the web
stages:
- fmt
- build-linux
- build-mac
- publish
variables:
GIT_STRATEGY: fetch
GIT_DEPTH: 100
CARGO_INCREMENTAL: 0
CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
workflow:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH
.collect-artifacts: &collect-artifacts
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
when: on_success
expire_in: 7 days
paths:
- artifacts/
.docker-env: &docker-env
image: paritytech/ci-linux:production
before_script:
- cargo -vV
- rustc -vV
- rustup show
- bash --version
- mkdir -p ${CARGO_TARGET_DIR}
- ./scripts/ci/pre_cache.sh
- sccache -s
interruptible: true
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure
tags:
- linux-docker
.kubernetes-env: &kubernetes-env
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure
interruptible: true
tags:
- kubernetes-parity-build
.build-refs: &build-refs
rules:
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_REF_NAME == "master"
- if: $CI_COMMIT_REF_NAME == "tags"
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
- if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
.publish-refs: &publish-refs
rules:
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
### stage: fmt
fmt:
stage: fmt
<<: *docker-env
script:
- cargo +nightly fmt --verbose --all -- --check
### stage: build-linux
build-linux:
stage: build-linux
<<: *docker-env
<<: *collect-artifacts
<<: *build-refs
script:
- time cargo build --release
- time cargo test --release --all
- mkdir -p ./artifacts/substrate-contracts-node-linux/
- cp ${CARGO_TARGET_DIR}/release/substrate-contracts-node ./artifacts/substrate-contracts-node-linux/substrate-contracts-node
### stage: build-mac
build-mac:
stage: build-mac
<<: *docker-env
<<: *collect-artifacts
# we run the mac build only when we actually want to publish
<<: *publish-refs
before_script:
- unset CARGO_TARGET_DIR
script:
- time cargo build --release
- mkdir -p ./artifacts/substrate-contracts-node-mac/
- cp target/release/substrate-contracts-node ./artifacts/substrate-contracts-node-mac/substrate-contracts-node
tags:
- osx
publish:
stage: publish
<<: *kubernetes-env
image: paritytech/tools:latest
<<: *publish-refs
needs:
- job: build-linux
artifacts: true
- job: build-mac
artifacts: true
variables:
VAULT_SERVER_URL: "https://vault.parity-mgmt-vault.parity.io"
VAULT_AUTH_PATH: "gitlab-parity-io-jwt"
VAULT_AUTH_ROLE: "cicd_gitlab_parity_${CI_PROJECT_NAME}"
secrets:
GITHUB_TOKEN:
vault: cicd/gitlab/parity/GITHUB_TOKEN@kv
file: false
script:
- git describe --tags
- TAG_NAME=`git describe --tags`
- echo "tag name ${TAG_NAME}"
- tar -czvf ./substrate-contracts-node-linux.tar.gz ./artifacts/substrate-contracts-node-linux/substrate-contracts-node
- tar -czvf ./substrate-contracts-node-mac.tar.gz ./artifacts/substrate-contracts-node-mac/substrate-contracts-node
- 'curl https://api.github.com/repos/paritytech/substrate-contracts-node/releases
--fail-with-body
-H "Cookie: logged_in=no"
-H "Authorization: token ${GITHUB_TOKEN}"'
- 'curl https://api.github.com/repos/paritytech/substrate-contracts-node/releases
--fail-with-body
-H "Cookie: logged_in=no"
-H "Authorization: token ${GITHUB_TOKEN}" | jq .'
- 'RELEASE_ID=$(curl https://api.github.com/repos/paritytech/substrate-contracts-node/releases
--fail-with-body
-H "Cookie: logged_in=no"
-H "Authorization: token ${GITHUB_TOKEN}"
| jq -r ".[] | select(.tag_name == \"$TAG_NAME\") | .id");
echo "release id if existent: ${RELEASE_ID}"'
- 'if [ -z "$RELEASE_ID" ]; then
RESP=$(curl -X "POST" "https://api.github.com/repos/paritytech/substrate-contracts-node/releases"
--fail-with-body
-H "Cookie: logged_in=no"
-H "Authorization: token ${GITHUB_TOKEN}"
-H "Content-Type: application/json; charset=utf-8"
-d $"{
\"tag_name\": \"${TAG_NAME}\",
\"name\": \"${TAG_NAME}\",
\"prerelease\": false,
\"draft\": true
}");
echo "api response ${RESP}";
RELEASE_ID=$(echo $RESP | jq -r .id);
echo "release id of created release ${RELEASE_ID}";
fi'
- echo "release id ${RELEASE_ID}"
- 'curl -X "POST" "https://uploads.github.com/repos/paritytech/substrate-contracts-node/releases/$RELEASE_ID/assets?name=substrate-contracts-node-linux.tar.gz"
--fail-with-body
-H "Cookie: logged_in=no"
-H "Authorization: token ${GITHUB_TOKEN}"
-H "Content-Type: application/octet-stream"
--data-binary @"./substrate-contracts-node-linux.tar.gz"'
- 'curl -X "POST" "https://uploads.github.com/repos/paritytech/substrate-contracts-node/releases/$RELEASE_ID/assets?name=substrate-contracts-node-mac.tar.gz"
--fail-with-body
-H "Cookie: logged_in=no"
-H "Authorization: token ${GITHUB_TOKEN}"
-H "Content-Type: application/octet-stream"
--data-binary @"./substrate-contracts-node-mac.tar.gz"'