packaging.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. ---
  2. # Handles building of binary packages for the agent.
  3. name: Packages
  4. on:
  5. pull_request:
  6. branches:
  7. - master
  8. - develop
  9. workflow_dispatch:
  10. inputs:
  11. type:
  12. name: Package build type
  13. default: devel
  14. required: true
  15. version:
  16. name: Package version
  17. required: false
  18. env:
  19. DISABLE_TELEMETRY: 1
  20. concurrency:
  21. group: packages-${{ github.ref }}-${{ github.event_name }}
  22. cancel-in-progress: true
  23. jobs:
  24. matrix:
  25. name: Prepare Build Matrix
  26. runs-on: ubuntu-latest
  27. outputs:
  28. matrix: ${{ steps.set-matrix.outputs.matrix }}
  29. steps:
  30. - name: Checkout
  31. uses: actions/checkout@v2
  32. - name: Prepare tools
  33. run: |
  34. sudo apt-get update && sudo apt-get install -y python3-ruamel.yaml
  35. - name: Read build matrix
  36. id: set-matrix
  37. shell: python3 {0}
  38. run: |
  39. from ruamel.yaml import YAML
  40. import json
  41. yaml = YAML(typ='safe')
  42. entries = list()
  43. with open('.github/data/distros.yml') as f:
  44. data = yaml.load(f)
  45. for i, v in enumerate(data['include']):
  46. if 'packages' in data['include'][i]:
  47. for arch in data['include'][i]['packages']['arches']:
  48. entries.append({
  49. 'distro': data['include'][i]['distro'],
  50. 'version': data['include'][i]['version'],
  51. 'pkgclouddistro': data['include'][i]['packages']['repo_distro'],
  52. 'format': data['include'][i]['packages']['type'],
  53. 'base_image': data['include'][i]['base_image'] if 'base_image' in data['include'][i] else data['include'][i]['distro'],
  54. 'platform': data['platform_map'][arch],
  55. 'arch': arch
  56. })
  57. entries.sort(key=lambda k: (k['arch'], k['distro'], k['version']))
  58. matrix = json.dumps({'include': entries}, sort_keys=True)
  59. print('Generated Matrix: ' + matrix)
  60. print('::set-output name=matrix::' + matrix)
  61. build:
  62. name: Build
  63. runs-on: ubuntu-latest
  64. env:
  65. DOCKER_CLI_EXPERIMENTAL: enabled
  66. needs:
  67. - matrix
  68. strategy:
  69. matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
  70. # We intentiaonally disable the fail-fast behavior so that a
  71. # build failure for one version doesn't prevent us from publishing
  72. # successfully built and tested packages for another version.
  73. fail-fast: false
  74. max-parallel: 8
  75. steps:
  76. - name: Checkout PR # Checkout the PR if it's a PR.
  77. if: github.event_name == 'pull_request'
  78. uses: actions/checkout@v2
  79. with:
  80. fetch-depth: 0 # We need full history for versioning
  81. submodules: recursive
  82. - name: Checkout Tag # Otherwise check out the tag that triggered this.
  83. if: github.event_name == 'workflow_dispatch'
  84. uses: actions/checkout@v2
  85. with:
  86. ref: ${{ github.event.ref }}
  87. fetch-depth: 0 # We need full history for versioning
  88. submodules: recursive
  89. - name: Check Base Branch
  90. run: |
  91. if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  92. echo "runtype=${{ github.event.inputs.type }}" >> $GITHUB_ENV
  93. case "${{ github.event.inputs.type }}" in
  94. "release")
  95. echo "repo=${{ secrets.PACKAGE_CLOUD_REPO }}" >> $GITHUB_ENV
  96. echo "pkg_version=${{ github.event.inputs.version }}" >> $GITHUB_ENV
  97. echo "pkg_retention_days=365" >> $GITHUB_ENV
  98. ;;
  99. "nightly")
  100. echo "repo=${{ secrets.PACKAGE_CLOUD_REPO }}-edge" >> $GITHUB_ENV
  101. echo "pkg_version=${{ github.event.inputs.version }}" >> $GITHUB_ENV
  102. echo "pkg_retention_days=30" >> $GITHUB_ENV
  103. ;;
  104. *)
  105. echo "repo=${{ secrets.PACKAGE_CLOUD_REPO }}-devel" >> $GITHUB_ENV
  106. echo "pkg_version=0.${GITHUB_SHA}" >> $GITHUB_ENV
  107. echo "pkg_retention_days=30" >> $GITHUB_ENV
  108. ;;
  109. esac
  110. else
  111. echo "runtype=test" >> $GITHUB_ENV
  112. echo "pkg_version=$(cut -d'-' -f 1 packaging/version | sed -e 's/^v//')" >> $GITHUB_ENV
  113. fi
  114. - name: Setup QEMU
  115. if: matrix.platform != 'linux/amd64' && matrix.platform != 'linux/i386'
  116. uses: docker/setup-qemu-action@v1
  117. - name: Prepare Docker Environment
  118. shell: bash
  119. run: |
  120. echo '{"cgroup-parent": "/actions_job", "experimental": true}' | sudo tee /etc/docker/daemon.json 2>/dev/null
  121. sudo service docker restart
  122. - name: Set Base Image Version
  123. shell: bash
  124. run: |
  125. if [ -z "${{ matrix.alias }}" ] ; then
  126. echo "version=${{ matrix.version }}" >> $GITHUB_ENV
  127. else
  128. echo "version=${{ matrix.alias }}" >> $GITHUB_ENV
  129. fi
  130. - name: Fetch base image
  131. uses: nick-invision/retry@v2
  132. with:
  133. max_attempts: 3
  134. retry_wait_seconds: 30
  135. timeout_seconds: 900
  136. command: |
  137. docker pull --platform ${{ matrix.platform }} ${{ matrix.base_image }}:${{ env.version }}
  138. docker pull --platform ${{ matrix.platform }} netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}
  139. - name: Build Packages
  140. shell: bash
  141. run: |
  142. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e VERSION=${{ env.pkg_version }} --platform=${{ matrix.platform }} -v $PWD:/netdata netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}
  143. - name: Test Packages
  144. shell: bash
  145. run: |
  146. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e DISTRO=${{ matrix.distro }} -e VERSION=${{ env.pkg_version }} -e DISTRO_VERSION=${{ env.version }} --platform=${{ matrix.platform }} -v $PWD:/netdata ${{ matrix.base_image }}:${{ env.version }} /netdata/.github/scripts/pkg-test.sh
  147. - name: Save Packages
  148. uses: actions/upload-artifact@v2
  149. with:
  150. name: ${{ matrix.distro }}-${{ matrix.version }}-${{ matrix.arch }}-packages
  151. path: ${{ github.workspace }}/artifacts/*
  152. - name: Upload to PackageCloud
  153. if: github.event_name == 'workflow_dispatch'
  154. shell: bash
  155. env:
  156. PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
  157. run: |
  158. echo "Packages to upload:\n$(ls artifacts/*.${{ matrix.format }})"
  159. for pkgfile in artifacts/*.${{ matrix.format }} ; do
  160. .github/scripts/package_cloud_wrapper.sh yank ${{ env.repo }}/${{ matrix.pkgclouddistro }} $(basename ${pkgfile}) || true
  161. .github/scripts/package_cloud_wrapper.sh push ${{ env.repo }}/${{ matrix.pkgclouddistro }} ${pkgfile}
  162. done
  163. - name: Clean
  164. if: github.event_name == 'workflow_dispatch'
  165. shell: bash
  166. env:
  167. REPO: ${{ env.repo }}
  168. PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
  169. PACKAGE_CLOUD_RETENTION_DAYS: ${{ env.pkg_retention_days }}
  170. run: .github/scripts/old_package_purging.sh
  171. - name: Failure Notification
  172. uses: rtCamp/action-slack-notify@v2
  173. env:
  174. SLACK_COLOR: 'danger'
  175. SLACK_ICON_EMOJI: ':github-actions:'
  176. SLACK_TITLE: 'Package Build failed:'
  177. SLACK_USERNAME: 'GitHub Actions'
  178. SLACK_MESSAGE: "${{ matrix.pkgclouddistro }} ${{ matrix.version }} package build for ${{ matrix.arch }} failed."
  179. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  180. if: >-
  181. ${{
  182. failure()
  183. && github.event_name != 'pull_request'
  184. && startsWith(github.ref, 'refs/heads/master')
  185. }}