summaryrefslogtreecommitdiff
path: root/pipelines/debian.ick
blob: c6fe573b0825332cdb3d2c80450d632546c0e168 (plain)
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
# Lars Wirzenius.
# 
# Feel free to use this as you wish. It is simple enough that it is
# probably not even copyrightable.

pipelines:

  # Install build-dependencies for a Debian build, by checking
  # debian/control for what's missing. The sources parameter is used
  # to find all the source trees: for each location, if debian/oontrol
  # exists as the location, look for missing build-dependencies.

  - pipeline: ick/install_debian_build_dependencies
    parameters:
      - sources
    actions:
      - python: |
          import os, subprocess

          def RUN(*args, **kwargs):
            print('Executing:', args)
            print('kwargs:', kwargs)
            return subprocess.run(args, **kwargs)

          def OUT(*args, **kwargs):
            x = RUN(*args, stdout=subprocess.PIPE, **kwargs)
            return x.stdout.decode('UTF-8')

          def ERR(*args, **kwargs):
            x = RUN(*args, stderr=subprocess.PIPE, **kwargs)
            return x.stderr.decode('UTF-8')

          def is_package_name(s):
            ok = "abcdefghijklmnopqrstyvwxyz"
            ok += ok.upper()
            ok += "0123456789.-"
            return all(c in ok for c in s)

          sources = params['sources']
          for source in sources:
            dirname = source['location']
            control = os.path.join(dirname, 'debian', 'control')
            if os.path.exists(control):
              err = ERR('dpkg-checkbuilddeps', cwd=dirname)
              print('err', err)
              pat = 'Unmet build dependencies: '
              if pat in err:
                parts = err.split(pat)
                missing = [x for x in parts[1].split() if is_package_name(x)]
                print('missing', missing)
                for name in missing:
                  RUN('apt-get', 'install', '-y', name)
        where: container


  # Build Debian packages. This is a CI build, which means a new
  # debian/changelog entry is created, with a version number that
  # contains the build number. This way every build results in a new
  # package version.
  #
  # The build will be done in each location in the sources parameter,
  # where debian/control exists.

  - pipeline: ick/build_deb_ci
    parameters:
      - sources
    actions:
      - python: |
          import os, subprocess

          def RUN(*args, **kwargs):
            print('Executing:', args)
            print('kwargs:', kwargs)
            return subprocess.run(args, **kwargs)

          def OUT(*args, **kwargs):
            x = RUN(*args, stdout=subprocess.PIPE, **kwargs)
            return x.stdout.decode('UTF-8')

          sources = params['sources']
          for source in sources:
            dirname = source['location']
            control = os.path.join(dirname, 'debian', 'control')
            if os.path.exists(control):
              src = OUT('dpkg-parsechangelog', '-S', 'Source')
              print('src', src)

              ver = OUT('dpkg-parsechangelog', '-S', 'Version')
              print('ver', ver)

              if '-' in ver:
                parts = ver.split('-')
                ver = '-'.join(ver_parts[:-1])
              ver += '.0ci{}-1'.format(os.environ['BUILD_NUMBER'])
              print('ver', ver)

              tarball = '../{}_{}.orig.tar.xz'.format(src, ver)
              print('tarball', tarball)

              RUN('dch', '-v', ver, 'CI build')
              RUN('dch', '-r', '')
              RUN('sh', '-c', 'git archive HEAD | xz > {}'.format(tarball))
              RUN('dpkg-buildpackage', '-us', '-uc')
        where: container

  # Upload all *.changes files at the root of the workspace.

  - pipeline: ick/upload_debs
    actions:
      - action: dput
        where: host