.gitlab-ci.yml 5.98 KB
Newer Older
Addshore's avatar
Addshore committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
image: docker:19.03.12

variables:
  # When you use the dind service, you must instruct Docker to talk with
  # the daemon started inside of the service. The daemon is available
  # with a network connection instead of the default
  # /var/run/docker.sock socket. Docker 19.03 does this automatically
  # by setting the DOCKER_HOST in
  # https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
  #
  # The 'docker' hostname is the alias of the service container as described at
  # https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services.
  #
  # Specify to Docker where to create the certificates. Docker
  # creates them automatically on boot, and creates
  # `/certs/client` to share between the service and job
  # container, thanks to volume mount from config.toml
  DOCKER_TLS_CERTDIR: "/certs"

stages:
  - test
Addshore's avatar
Addshore committed
22
  - build
Addshore's avatar
Addshore committed
23
  - integration
Addshore's avatar
Addshore committed
24
25
26
  - release-build
  - release-upload
  - release-publish
Addshore's avatar
Addshore committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

# The plan would be for this cache to be reused by all jobs.
# Caches curently end up cached per runner, per job concurrency level and per md5 of path?
# So there are potentially 12 caches that end up needing to be populated right now?
# https://forum.gitlab.com/t/confusion-around-ci-docker-cache-volumes-and-sharing-across-jobs-concurrency/56793
# Docker cache volumes look like this runner-<short-token>-project-<id>-concurrent-<concurrency-id>-cache-<md5-of-path>
cache:
  - key: mediawiki
    paths:
      - mediawiki

services:
  - name: docker:19.03.12-dind

test:
    stage: test
    needs: []
    cache: {}
    image: docker-registry.wikimedia.org/golang:1.13-3
46
47
48
    artifacts:
      reports:
        cobertura: coverage.xml
Addshore's avatar
Addshore committed
49
50
    script:
      - make test
51
52
      - go get github.com/boumenot/gocover-cobertura
      - gocover-cobertura < coverage.txt > coverage.xml
Addshore's avatar
Addshore committed
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
checks:
    stage: test
    needs: []
    cache: {}
    image: docker-registry.wikimedia.org/golang:1.13-3
    parallel:
      matrix:
        - CHECK: lint
        - CHECK: vet
        - CHECK: staticcheck
    script:
      # XDG_CACHE_HOME is needed by staticcheck
      - export XDG_CACHE_HOME=/tmp/mwcli-cache
      - make $CHECK

Addshore's avatar
Addshore committed
69
70
71
72
73
74
75
76
77
78
79
build:
    stage: build
    needs: []
    cache: {}
    image: docker-registry.wikimedia.org/golang:1.13-3
    artifacts:
      paths:
        - bin/
    script:
      - make

Addshore's avatar
Addshore committed
80
81
82
83
84
85
86
87
88
89
90

integration-general:
    stage: integration
    needs: [checks,test,build]
    dependencies:
      - build
    parallel:
      matrix:
        - TEST: general-commands.sh
    before_script:
      # libc6-compat needed because https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
Addshore's avatar
Addshore committed
91
      - apk add --no-cache libc6-compat bash
Addshore's avatar
Addshore committed
92
93
94
95
    script:
      - ./tests/$TEST

integration-docker:
Addshore's avatar
Addshore committed
96
    stage: integration
97
    needs: [checks,test,build]
Addshore's avatar
Addshore committed
98
99
100
101
102
103
104
105
106
    dependencies:
      - build
    parallel:
      matrix:
        - TEST: docker-mw-extra-commands.sh
        - TEST: docker-mw-install-all-the-dbs.sh
        - TEST: docker-mw-mysql-suspend-resume-destroy.sh
    before_script:
      # libc6-compat needed because https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
107
      - apk add --no-cache libc6-compat bash docker-compose curl composer
Addshore's avatar
Addshore committed
108
109
110
111
      - ./tests/cache-mediawiki.sh
      - ./tests/setup.sh
    script:
      - ./tests/$TEST
Addshore's avatar
Addshore committed
112
113
114
115
116
117

release-build:
    stage: release-build
    needs: [build]
    cache: {}
    image: docker-registry.wikimedia.org/golang:1.13-3
118
119
120
    # artifacts:
    #   paths:
    #     - _release/
Addshore's avatar
Addshore committed
121
122
123
    script:
      # Ideally make would not be needed, only release? But it is needed to install deps currently?
      - make
Addshore's avatar
Addshore committed
124
      - make release VERSION=${CI_COMMIT_TAG:-$CI_COMMIT_BRANCH}
125
126
127
128
129
130
131
132
      # This next part should be in release-upload, but https://phabricator.wikimedia.org/T292372
      - >
        if [ -n "$CI_COMMIT_TAG" ]; then
          for release_path in  $(find ./_release -type f); do
            release_file=$(echo $release_path | sed "s/.*\///")
            curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ${release_path} "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/mwcli/${CI_COMMIT_TAG}/${release_file}"
          done
        fi
Addshore's avatar
Addshore committed
133
134
135
136
137

release-upload:
  only:
    - tags
  stage: release-upload
Addshore's avatar
Addshore committed
138
  needs: [integration-general, integration-docker, release-build]
Addshore's avatar
Addshore committed
139
140
141
142
143
144
145
146
  dependencies:
    - release-build
  # Has 1 requirement of curl, could be replaced by a wmf releng image?
  image: alpine:latest
  before_script:
    - apk add curl
  # https://docs.gitlab.com/ee/user/packages/generic_packages/#publish-a-generic-package-by-using-cicd
  script:
147
148
149
150
151
152
    - echo "Placeholder job, as a conditional upload currently happens as part of release-build awaiting decision on https://phabricator.wikimedia.org/T292372"
    # - >
    #   for release_path in  $(find ./_release -type f); do
    #     release_file=$(echo $release_path | sed "s/.*\///")
    #     curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ${release_path} "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/mwcli/${CI_COMMIT_TAG}/${release_file}"
    #   done
Addshore's avatar
Addshore committed
153
154
155
156
157
158
159
160
161
162

release-publish:
  only:
    - tags
  stage: release-publish
  needs: [release-build, release-upload]
  dependencies:
    - release-build
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  script:
Addshore's avatar
Addshore committed
163
    - (echo "## ${CI_COMMIT_TAG}" && echo "CHANGELOG extracted from https://gitlab.wikimedia.org/releng/cli/-/blob/main/CHANGELOG.md" && sed "/^## ${CI_COMMIT_TAG}$/,/^## /"'!d'";//d;/\^$/d" CHANGELOG.md) > .gitlab.description.md
Addshore's avatar
Addshore committed
164
165
166
167
168
169
    - assets_links=""
    - >
      for release_path in  $(find ./_release -type f); do
        release_file=$(echo $release_path | sed "s/.*\///")
        assets_links="${assets_links} --assets-link {\"name\":\"${release_file}\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/mwcli/${CI_COMMIT_TAG}/${release_file}\"}"
      done
170
    - release-cli create --name "Release $CI_COMMIT_TAG" --description ".gitlab.description.md" --released-at "${CI_COMMIT_TIMESTAMP}" ${assets_links}