summaryrefslogtreecommitdiffstats
path: root/.github/workflows/packaging.yml
blob: 9b15cf94b412d70c464b3c87e4f7b975f8375bd5 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
---
# Handles building of binary packages for the agent.
name: Packages
on:
  pull_request:
    types:
      - opened
      - reopened
      - labeled
      - synchronize
  push:
    branches:
      - master
  workflow_dispatch:
    inputs:
      type:
        description: Package build type
        default: devel
        required: true
      version:
        description: Package version
        required: false
env:
  DISABLE_TELEMETRY: 1
  REPO_PREFIX: netdata/netdata
concurrency:
  group: packages-${{ github.ref }}-${{ github.event_name }}
  cancel-in-progress: true
jobs:
  file-check: # Check what files changed if we’re being run in a PR or on a push.
    name: Check Modified Files
    runs-on: ubuntu-latest
    outputs:
      run: ${{ steps.check-run.outputs.run }}
    steps:
      - name: Checkout
        id: checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          submodules: recursive
      - name: Check files
        id: file-check
        uses: tj-actions/changed-files@v39
        with:
          since_last_remote_commit: ${{ github.event_name != 'pull_request' }}
          files: |
            **.c
            **.cc
            **.h
            **.hh
            **.in
            netdata.spec.in
            configure.ac
            **/Makefile*
            Makefile*
            .github/data/distros.yml
            .github/workflows/packaging.yml
            .github/scripts/gen-matrix-packaging.py
            .github/scripts/pkg-test.sh
            build/**
            packaging/*.sh
            packaging/*.checksums
            packaging/*.version
            contrib/debian/**
            aclk/aclk-schemas/
            ml/dlib/
            mqtt_websockets
            web/server/h2o/libh2o
          files_ignore: |
            **.md
      - name: Check Run
        id: check-run
        run: |
          if [ "${{ steps.file-check.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
            echo 'run=true' >> "${GITHUB_OUTPUT}"
          else
            echo 'run=false' >> "${GITHUB_OUTPUT}"
          fi

  matrix:
    name: Prepare Build Matrix
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - name: Checkout
        id: checkout
        uses: actions/checkout@v4
      - name: Prepare tools
        id: prepare
        run: |
          sudo apt-get update && sudo apt-get install -y python3-ruamel.yaml
      - name: Read build matrix
        id: set-matrix
        run: |
          if [ "${{ github.event_name }}" = "pull_request" ] && \
             [ "${{ !contains(github.event.pull_request.labels.*.name, 'run-ci/packaging') }}" = "true" ]; then
            matrix="$(.github/scripts/gen-matrix-packaging.py 1)"
          else
            matrix="$(.github/scripts/gen-matrix-packaging.py 0)"
          fi
          echo "Generated matrix: ${matrix}"
          echo "matrix=${matrix}" >> "${GITHUB_OUTPUT}"
      - name: Failure Notification
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_COLOR: 'danger'
          SLACK_ICON_EMOJI: ':github-actions:'
          SLACK_TITLE: 'Package Build matrix generation failed:'
          SLACK_USERNAME: 'GitHub Actions'
          SLACK_MESSAGE: |-
              ${{ github.repository }}: Failed to generate build matrix for package build.
              Checkout: ${{ steps.checkout.outcome }}
              Prepare Tools: ${{ steps.prepare.outcome }}
              Read Build Matrix: ${{ steps.set-matrix.outcome }}
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
        if: >-
          ${{
            failure()
            && github.event_name != 'pull_request'
            && startsWith(github.ref, 'refs/heads/master')
            && github.repository == 'netdata/netdata'
          }}

  version-check:
    name: Version check
    runs-on: ubuntu-latest
    outputs:
      repo: ${{ steps.check-version.outputs.repo }}
      version: ${{ steps.check-version.outputs.version }}
      retention: ${{ steps.check-version.outputs.retention }}
    steps:
      - name: Checkout
        id: checkout
        uses: actions/checkout@v4
      - name: Check Version
        id: check-version
        run: |
          if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
            case "${{ github.event.inputs.type }}" in
              "release")
                echo "repo=${REPO_PREFIX}" >> "${GITHUB_OUTPUT}"
                echo "version=${{ github.event.inputs.version }}" >> "${GITHUB_OUTPUT}"
                echo "retention=365" >> "${GITHUB_OUTPUT}"
                ;;
              "nightly")
                echo "repo=${REPO_PREFIX}-edge" >> "${GITHUB_OUTPUT}"
                echo "version=$(tr -d 'v' < packaging/version)" >> "${GITHUB_OUTPUT}"
                echo "retention=30" >> "${GITHUB_OUTPUT}"
                ;;
              *)
                echo "repo=${REPO_PREFIX}-devel" >> "${GITHUB_OUTPUT}"
                echo "version=0.${GITHUB_SHA}" >> "${GITHUB_OUTPUT}"
                echo "retention=30" >> "${GITHUB_OUTPUT}"
                ;;
            esac
          else
            echo "version=$(cut -d'-' -f 1 packaging/version | tr -d 'v')" >> "${GITHUB_OUTPUT}"
            echo "retention=0" >> "${GITHUB_OUTPUT}"
          fi
      - name: Failure Notification
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_COLOR: 'danger'
          SLACK_ICON_EMOJI: ':github-actions:'
          SLACK_TITLE: 'Package Build version check failed:'
          SLACK_USERNAME: 'GitHub Actions'
          SLACK_MESSAGE: |-
              ${{ github.repository }}: Failed to generate version information for package build.
              Checkout: ${{ steps.checkout.outcome }}
              Check Version: ${{ steps.check-version.outcome }}
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
        if: >-
          ${{
            failure()
            && github.event_name != 'pull_request'
            && startsWith(github.ref, 'refs/heads/master')
            && github.repository == 'netdata/netdata'
          }}

  build:
    name: Build
    runs-on: ubuntu-latest
    env:
      DOCKER_CLI_EXPERIMENTAL: enabled
    needs:
      - matrix
      - version-check
      - file-check
    strategy:
      matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
      # We intentiaonally disable the fail-fast behavior so that a
      # build failure for one version doesn't prevent us from publishing
      # successfully built and tested packages for another version.
      fail-fast: false
      max-parallel: 8
    steps:
      - name: Skip Check
        id: skip
        if: needs.file-check.outputs.run != 'true'
        run: echo "SKIPPED"
      - name: Checkout
        id: checkout
        if: needs.file-check.outputs.run == 'true'
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # We need full history for versioning
          submodules: recursive
      - name: Setup QEMU
        id: qemu
        if: matrix.platform != 'linux/amd64' && matrix.platform != 'linux/i386' && needs.file-check.outputs.run == 'true'
        uses: docker/setup-qemu-action@v3
      - name: Prepare Docker Environment
        id: docker-config
        if: needs.file-check.outputs.run == 'true'
        shell: bash
        run: |
          echo '{"cgroup-parent": "actions-job.slice", "experimental": true}' | sudo tee /etc/docker/daemon.json 2>/dev/null
          sudo service docker restart
      - name: Fetch images
        id: fetch-images
        if: needs.file-check.outputs.run == 'true'
        uses: nick-invision/retry@v2
        with:
          max_attempts: 3
          retry_wait_seconds: 30
          timeout_seconds: 900
          command: |
            docker pull --platform ${{ matrix.platform }} ${{ matrix.base_image }}
            docker pull --platform ${{ matrix.platform }} netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-v1
      - name: Build Packages
        id: build
        if: needs.file-check.outputs.run == 'true'
        shell: bash
        run: |
          docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e VERSION=${{ needs.version-check.outputs.version }} \
                     --platform=${{ matrix.platform }} -v "$PWD":/netdata netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-v1
      - name: Save Packages
        id: artifacts
        if: needs.file-check.outputs.run == 'true'
        continue-on-error: true
        uses: actions/upload-artifact@v3
        with:
          name: ${{ matrix.distro }}-${{ matrix.version }}-${{ matrix.arch }}-packages
          path: ${{ github.workspace }}/artifacts/*
      - name: Test Packages
        id: test
        if: needs.file-check.outputs.run == 'true'
        shell: bash
        run: |
          docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e DISTRO=${{ matrix.distro }} \
                     -e VERSION=${{ needs.version-check.outputs.version }} -e DISTRO_VERSION=${{ matrix.version }} \
                     --platform=${{ matrix.platform }} -v "$PWD":/netdata ${{ matrix.base_image }} \
                     /netdata/.github/scripts/pkg-test.sh
      - name: Upload to PackageCloud
        id: upload
        if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
        continue-on-error: true
        shell: bash
        env:
          PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
        run: |
          printf "Packages to upload:\n%s" "$(ls artifacts/*.${{ matrix.format }})"
          for pkgfile in artifacts/*.${{ matrix.format }} ; do
            .github/scripts/package_cloud_wrapper.sh yank ${{ needs.version-check.outputs.repo }}/${{ matrix.repo_distro }} \
            "$(basename "${pkgfile}")" || true
            .github/scripts/package_cloud_wrapper.sh push ${{ needs.version-check.outputs.repo }}/${{ matrix.repo_distro }} "${pkgfile}"
          done
      - name: SSH setup
        id: ssh-setup
        if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.NETDATABOT_PACKAGES_SSH_KEY }}
          name: id_ecdsa
          known_hosts: ${{ secrets.PACKAGES_KNOWN_HOSTS }}
      - name: Upload to packages.netdata.cloud
        id: package-upload
        if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
        run: |
          .github/scripts/package-upload.sh \
          ${{ matrix.repo_distro }} \
          ${{ matrix.arch }} \
          ${{ matrix.format }} \
          ${{ needs.version-check.outputs.repo }}
      - name: Failure Notification
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_COLOR: 'danger'
          SLACK_ICON_EMOJI: ':github-actions:'
          SLACK_TITLE: 'Package Build failed:'
          SLACK_USERNAME: 'GitHub Actions'
          SLACK_MESSAGE: |-
              ${{ github.repository }}: ${{ matrix.repo_distro }} ${{ matrix.version }} package build for ${{ matrix.arch }} failed.
              Checkout: ${{ steps.checkout.outcome }}
              Setup QEMU: ${{ steps.qemu.outcome }}
              Setup Docker: ${{ steps.docker-config.outcome }}
              Fetch images: ${{ steps.fetch-images.outcome }}
              Build: ${{ steps.build.outcome }}
              Test: ${{ steps.test.outcome }}
              Publish to PackageCloud: ${{ steps.upload.outcome }}
              Import SSH Key: ${{ steps.ssh-setup.outcome }}
              Publish to packages.netdata.cloud: ${{ steps.package-upload.outcome }}
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
        if: >-
          ${{
            failure()
            && github.event_name != 'pull_request'
            && startsWith(github.ref, 'refs/heads/master')
            && github.repository == 'netdata/netdata'
            && needs.file-check.outputs.run == 'true'
          }}