lib-template.yml 1.67 KB
Newer Older
1
2
3
4
5
stages:
    - build
    - test
    - release

6
7
8
9
variables:
    PROJECT_NAME: Test
    CRATE_NAME: test

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
include:
    - project: bp3d/cargo-gitlab
      file: base-template.yml

#------------------#
# Release pipeline #
#------------------#
get-version:
    stage: build
    image: debian:stable
    only:
        - master
    script:
        # Part 1 > extract the version line
        # Part 2 > extract the version string itself
        # Part 3 > remove colors
Yuri6037's avatar
Yuri6037 committed
26
        - grep -P 'version = "\d.\d.\d"' Cargo.toml | grep -oP '\d.\d.\d' | head -1 | cat > versionfile.txt
27
28
29
30
31
32
33
34
35
36
37
38
39
    artifacts:
        paths:
            - versionfile.txt

build-release-test:
    stage: build
    only:
        - master
    extends:
        - .unix-base-job
    script:
        - startsection build "Build release & test"
        - cargo build --release
Yuri6037's avatar
Yuri6037 committed
40
        - cargo test --release
41
42
43
44
        - endsection build

publish:
    stage: release
45
    dependencies: []
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    only:
        - master
    extends:
        - .unix-base-job
    script:
        - startsection build "Push to crates.io"
        - cargo login ${RELEASE_TOKEN}
        - cargo publish --dry-run
        - cargo publish
        - endsection build

create-release:
    stage: release
    image: registry.gitlab.com/gitlab-org/release-cli:latest
    needs:
        - get-version
    only:
        - master
    script:
        - PACKAGE_VERSION=$(cat versionfile.txt)
        - echo "Creating release v${PACKAGE_VERSION}..."
        - |
68
69
            release-cli create --name "${PROJECT_NAME} release ${PACKAGE_VERSION}" --tag-name ${PACKAGE_VERSION} \
              --assets-link "{\"name\":\"Crates.io release\",\"url\":\"https://crates.io/crates/${CRATE_NAME}\"}" \