.gitlab-ci.yml 2.84 KB
Newer Older
1
2
default:
  image: "archlinux:latest"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
3

4
stages:
5
  - lint
6
  - build
7
  - publish
8

Christian Rebischke's avatar
Christian Rebischke committed
9
shellcheck:
10
  stage: lint
11
12
  before_script:
    - pacman -Syu --needed --noconfirm shellcheck
Christian Rebischke's avatar
Christian Rebischke committed
13
  script:
14
    - shellcheck **/*.sh
Christian Rebischke's avatar
Christian Rebischke committed
15
16

shfmt:
17
  stage: lint
18
19
  before_script:
    - pacman -Syu --needed --noconfirm shfmt
Christian Rebischke's avatar
Christian Rebischke committed
20
  script:
21
    - shfmt -i 2 -ci -d **/*.sh
Christian Rebischke's avatar
Christian Rebischke committed
22

23
.build:
24
  stage: build
25
  before_script:
26
    - pacman -Syu --needed --noconfirm qemu-headless libisoburn
27
  script:
28
29
30
31
32
33
34
35
    - |
      # If we're building a tagged release, use the tag (without the 'v' prefix) as the
      # BUILD_VERSION. Otherwise, determine a new BUILD_VERSION.
      if [[ -n "$CI_COMMIT_TAG" ]]; then
        echo "BUILD_VERSION=${CI_COMMIT_TAG/v/}" > build.env
      else
        echo "BUILD_VERSION=$(date +%Y%m%d).$CI_JOB_ID" > build.env
      fi
36
37
    - export $(< build.env)
    - ./build-host.sh
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
38
39
40
41
42
43
44
  after_script:
    - echo "image_size_megabytes{image=\"qcow2\"} $(du -m output/*cloudimg*qcow2)" > metrics.txt
    - echo "image_size_megabytes{image=\"libvirt\"} $(du -m output/*libvirt*box)" >> metrics.txt
    - echo "image_size_megabytes{image=\"virtualbox\"} $(du -m output/*virtualbox*box)" >> metrics.txt
  artifacts:
    reports:
      metrics: metrics.txt
45
      dotenv: build.env
46
47
48
49
50

build:
  extends: .build
  except:
    - master
51
52
    - schedules
    - tags
53

54
build:secure:
55
56
57
58
59
  extends: .build
  tags:
    - secure
  only:
    - master
60
61
    - schedules
    - tags
62
  artifacts:
63
    name: "output"
64
    paths:
65
      - "output/*"
66
    expire_in: 2d
67

68
69
70
71
72
73
74
75
76
77
78
79
tag_release:
  stage: publish
  tags:
    - secure
  only:
    refs:
      - schedules
    variables:
      - $SCHEDULED_PUBLISH == "TRUE"
  before_script:
    - pacman -Syu --needed --noconfirm httpie
  script:
80
    - >
81
82
83
84
        export ASSET_LINKS="{ \"links\": [ \
          { \"name\": \"Vagrant Cloud Release\", \"url\": \"https://app.vagrantup.com/archlinux/boxes/archlinux/versions/$BUILD_VERSION\" }, \
          { \"name\": \"qcow2 Image\", \"url\": \"https://gitlab.archlinux.org/archlinux/arch-boxes/-/jobs/artifacts/master/raw/output/Arch-Linux-x86_64-cloudimg-$BUILD_VERSION.qcow2?job=build:secure\" } \
        ]}"
85
86
87
88
89
    - http --ignore-stdin "$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases"
        "JOB-TOKEN:$CI_JOB_TOKEN"
        "name=v$BUILD_VERSION"
        "tag_name=v$BUILD_VERSION"
        "ref=$CI_COMMIT_SHA"
90
        "assets:=$ASSET_LINKS"
91

92
93
94
publish:
  stage: publish
  tags:
95
    - secure
96
97
  only:
    - tags
98
  before_script:
99
    - pacman -Syu --needed --noconfirm vagrant
100
  script:
101
    - vagrant cloud auth login --token "${VAGRANT_API_TOKEN}"
102
103
    - vagrant cloud auth login --check
    - vagrant cloud box show archlinux/archlinux
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
104
105
    - vagrant cloud publish archlinux/archlinux "${BUILD_VERSION}" libvirt output/Arch-Linux-x86_64-libvirt-*.box --release -f
    - vagrant cloud publish archlinux/archlinux "${BUILD_VERSION}" virtualbox output/Arch-Linux-x86_64-virtualbox-*.box --release -f