-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
140 lines (132 loc) · 4.1 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
.buildkit:
image:
name: moby/buildkit:rootless
entrypoint: ["sh", "-c"]
variables:
BUILDKITD_FLAGS: --oci-worker-no-process-sandbox
before_script:
- |
mkdir -p ~/.docker && cat > ~/.docker/config.json <<EOF
{
"auths": {
"$CI_REGISTRY": {
"auth": "$(echo -n "$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" | base64)"
}
}
}
EOF
stages:
- update
- test
- build
test:typescript:
image: registry.inpt.fr/inp-net/images/go-just:1.24.0-1.39.0
stage: test
rules:
- when: always
before_script:
- apk add git npm jq
- cp -r typescript typescript_original
- just build
- just gen_typescript
script:
- cp events.go events_original.go
- |
if ! diff -q events.go events_original.go; then
echo "events.go changed, just gen_typescript and commit the changes"
exit 1
fi
- rm events_original.go
- |
for file in typescript/*.ts; do
if ! diff -q $file typescript_original/$(basename $file); then
diff typescript_original/$(basename $file) $file
echo "Generated file $file is different from original, please run 'just gen_typescript' and commit the changes"
exit 1
fi
done
- |
mkdir -p testarea; cd testarea
npm init -y
jq '.type = "module"' < package.json > package.json.new
mv package.json.new package.json
npm add -S git+$CI_PROJECT_URL#$CI_COMMIT_HASH
echo "import * as notella from '@inp-net/notella'; console.log(notella)" > index.js
node index.js > lib.txt
if ! diff -q lib.txt ../typescript_original/lib.txt; then
diff lib.txt ../typescript/lib.txt
echo Runtime library has different values, re-run just gen_typescript and commit the changes
exit 1
fi
test:up-to-date-prisma-schema:
image: registry.inpt.fr/inp-net/images/go-just:1.24.0-1.39.0
stage: test
rules:
- when: always
before_script:
- apk add curl
- just updateschema
- cp schema.prisma original_schema.prisma
script:
- |
if ! diff -q schema.prisma original_schema.prisma; then
echo "Generated schema.prisma is different from original, please run 'just updateschema' and commit the changes"
exit 1
fi
.gitops:
image: registry.inpt.fr/inp-net/images/go-just:1.24.0-1.39.0
before_script:
- git config --global user.name gitlab
- git config --global user.email "[email protected]"
- git remote remove gitlab_origin || true
- git remote add gitlab_origin https://bot:$BOT_TOKEN@$CI_SERVER_SHELL_SSH_HOST/$CI_PROJECT_PATH
update:prisma-schema:
extends: .gitops
stage: update
allow_failure: true
rules:
- if: $CI_PIPELINE_SOURCE == "pipeline"
- when: manual
script:
- apk add curl
- just updateschema $SCHEMA_RAW_URL
- git add schema.prisma
- 'git commit -m "chore(prisma): update schema.prisma after churros/churros change [ci release]"'
- git push gitlab_origin HEAD:main
release-new-patch-version:
extends: .gitops
stage: build
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_TITLE =~ /\[ci release]/
script:
- git fetch --tags
- latest_tag=$(git tag -l --sort=-v:refname | head -n 1)
- git tag $(echo $latest_tag | awk -F. '{OFS="."; $NF+=1; print $0}')
- git push gitlab_origin --tags
build:
extends: .buildkit
stage: build
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/
variables:
DEPLOY: "true"
script:
- |
if [ "$DEPLOY" == "true" ]; then
export TAG=$(echo $CI_COMMIT_TAG | sed 's/^v//')
else
export TAG=latest-$(echo $CI_COMMIT_SHA | cut -c-6)
fi
- |
buildctl-daemonless.sh build \
--frontend=dockerfile.v0 \
--local context=. \
--local dockerfile=. \
--opt build-arg:TAG=$TAG \
--output type=image,name=$CI_REGISTRY_IMAGE:v$TAG,push=$DEPLOY
- |
if [ "$DEPLOY" == "true"]; then
echo "Successfully built and pushed $CI_REGISTRY_IMAGE:v$TAG"
else
echo "Successfully built $CI_REGISTRY_IMAGE:v$TAG"
fi