aboutsummaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: 9778cfc4af2d11824173d94c4331ca712a72c9b3 (plain) (blame)
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
stages:
  - check
  - test
  - build
  - release

variables:
  CARGO_HOME: "$CI_PROJECT_DIR/.cargo"

default:
  image: rust:1.93
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - target
      - .cargo/registry
      - .cargo/git

check:
  stage: check
  script:
    - rustup component add rustfmt clippy
    - cargo fmt --all -- --check
    - cargo clippy --all-targets --all-features -- -D warnings
  only:
    - branches
    - tags

test:
  stage: test
  script:
    - cargo test --all
  needs:
    - check
  only:
    - branches
    - tags

build:
  stage: build
  needs:
    - test
  # Run only for semver-like tags "vX.Y.Z".
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/'
      when: on_success
    - when: never
  script:
    # Install system linkers for musl & ARM64.
    - apt-get update
    - apt-get install -y musl-tools gcc-aarch64-linux-gnu
    # Add Rust targets.
    - rustup target add x86_64-unknown-linux-musl
    - rustup target add aarch64-unknown-linux-gnu
    - rustup target add aarch64-unknown-linux-musl
    # aarch64-musl cross toolchain (musl.cc).
    - curl -fsSL https://musl.cc/aarch64-linux-musl-cross.tgz | tar xz -C /opt
    - export PATH="/opt/aarch64-linux-musl-cross/bin:$PATH"
    # Set per-target environment variables to prevent wrong tools being used.
    # x86_64-unknown-linux-musl.
    - export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-linux-musl-gcc
    # aarch64-unknown-linux-gnu.
    - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
    - export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
    - export AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar
    # aarch64-unknown-linux-musl.
    - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc
    - export CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc
    - export AR_aarch64_unknown_linux_musl=aarch64-linux-musl-ar
    # Build all four variants.
    - cargo build --release # x86_64-gnu.
    - cargo build --release --target x86_64-unknown-linux-musl
    - cargo build --release --target aarch64-unknown-linux-gnu
    - cargo build --release --target aarch64-unknown-linux-musl
    # Package binaries with clear naming
    - mkdir -p dist
    - cp target/release/oreilly-epub
         dist/oreilly-epub-linux-x86_64
    - cp target/x86_64-unknown-linux-musl/release/oreilly-epub
         dist/oreilly-epub-linux-x86_64-musl
    - cp target/aarch64-unknown-linux-gnu/release/oreilly-epub
         dist/oreilly-epub-linux-aarch64
    - cp target/aarch64-unknown-linux-musl/release/oreilly-epub
         dist/oreilly-epub-linux-aarch64-musl
  artifacts:
    name: "oreilly-epub-$CI_COMMIT_TAG"
    paths:
      - dist/
    expire_in: 1 week

release:
  stage: release
  needs:
    - job: build
      artifacts: true
  image: registry.gitlab.com/gitlab-org/cli:latest
  # Run only for semver-like tags "vX.Y.Z".
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/'
      when: on_success
    - when: never
  script:
    # Visual inspection for debugging.
    - ls -lh dist/
    # Authenticate glab using CLI tokens.
    - glab auth login --job-token $CI_JOB_TOKEN
    # Create (or update) the Release for this tag.
    - glab release create "$CI_COMMIT_TAG"
        --name "oreilly-epub $CI_COMMIT_TAG"
        --notes "Automated release for $CI_COMMIT_TAG"
        --use-package-registry
        "dist/oreilly-epub-linux-x86_64#Linux x86_64#package"
        "dist/oreilly-epub-linux-x86_64-musl#Linux x86_64 (musl)#package"
        "dist/oreilly-epub-linux-aarch64#Linux ARM64#package"
        "dist/oreilly-epub-linux-aarch64-musl#Linux ARM64 (musl)#package"