@@ -69,6 +69,11 @@ variables:
69
69
- if : $CI_COMMIT_REF_NAME =~ /^release-parachains-v[0-9].*$/ # i.e. release-parachains-v1.0, release-parachains-v2.1rc1, release-parachains-v3000
70
70
- if : $CI_COMMIT_REF_NAME =~ /^polkadot-v[0-9]+\.[0-9]+.*$/ # i.e. polkadot-v1.0.99, polkadot-v2.1rc1
71
71
72
+ .pr-refs : &pr-refs
73
+ # these jobs run always*
74
+ rules :
75
+ - if : $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
76
+
72
77
.publish-refs : &publish-refs
73
78
rules :
74
79
- if : $CI_COMMIT_REF_NAME == "master"
@@ -107,6 +112,23 @@ variables:
107
112
tags :
108
113
- kubernetes-parity-build
109
114
115
+ # ### stage: .pre
116
+
117
+ # checks code format and fails if formatting is required
118
+ # the code will be formatted automatically and the pipeline will be restarted
119
+ cargo-fmt :
120
+ stage : .pre
121
+ << : *pr-refs
122
+ << : *kubernetes-env
123
+ before_script :
124
+ - echo PROJECT_NAME=$CI_PROJECT_NAME > fmt.env
125
+ - echo PR_BRANCH_NAME=$(curl -s https://api.github.com/repos/paritytech/${CI_PROJECT_NAME}/pulls/${CI_COMMIT_REF_NAME} | jq -r ".head.ref") >> fmt.env
126
+ script :
127
+ - cargo +nightly fmt --check
128
+ artifacts :
129
+ reports :
130
+ dotenv : fmt.env
131
+
110
132
# ### stage: test
111
133
112
134
test-linux-stable :
@@ -601,3 +623,17 @@ cancel-pipeline:
601
623
project : " parity/infrastructure/ci_cd/pipeline-stopper"
602
624
# remove branch, when pipeline-stopper for substrate and polakdot is updated to the same branch
603
625
branch : " as-improve"
626
+
627
+ # this job will automatically format code and rerun pipeline if cargo-fmt job fails
628
+ auto-fmt :
629
+ stage : .post
630
+ rules :
631
+ - if : $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs
632
+ when : on_failure
633
+ needs :
634
+ - job : cargo-fmt
635
+ variables :
636
+ PROJECT_NAME : " ${CI_PROJECT_NAME}"
637
+ PR_BRANCH_NAME : " ${PR_BRANCH_NAME}"
638
+ trigger :
639
+ project : " parity/infrastructure/ci_cd/auto-fmt"
0 commit comments