.gitlab-ci.yml 4.59 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
51
    script:
      - go get -u golang.org/x/lint/golint
      - make test
52
53
      - go get github.com/boumenot/gocover-cobertura
      - gocover-cobertura < coverage.txt > coverage.xml
Addshore's avatar
Addshore committed
54

Addshore's avatar
Addshore committed
55
56
57
58
59
60
61
62
63
64
65
build:
    stage: build
    needs: []
    cache: {}
    image: docker-registry.wikimedia.org/golang:1.13-3
    artifacts:
      paths:
        - bin/
    script:
      - make

Addshore's avatar
Addshore committed
66
67
integration:
    stage: integration
Addshore's avatar
Addshore committed
68
    needs: [test,build]
Addshore's avatar
Addshore committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    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
      - apk add --no-cache libc6-compat bash docker-compose curl
      - ./tests/cache-mediawiki.sh
      - ./tests/setup.sh
    script:
      - ./tests/$TEST
Addshore's avatar
Addshore committed
83
84
85
86
87
88
89
90
91
92
93
94

release-build:
    stage: release-build
    needs: [build]
    cache: {}
    image: docker-registry.wikimedia.org/golang:1.13-3
    artifacts:
      paths:
        - _release/
    script:
      # Ideally make would not be needed, only release? But it is needed to install deps currently?
      - make
Addshore's avatar
Addshore committed
95
      - make release VERSION=${CI_COMMIT_TAG:-$CI_COMMIT_BRANCH}
Addshore's avatar
Addshore committed
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

release-upload:
  only:
    - tags
  stage: release-upload
  needs: [integration, release-build]
  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:
    - >
      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

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
125
    - (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
126
127
128
129
130
131
    - 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
Addshore's avatar
Addshore committed
132
    - release-cli create --name "Release $CI_COMMIT_TAG" --description "$.gitlab.description.md" --released-at "${CI_COMMIT_TIMESTAMP}" ${assets_links}