packaging.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. jobs:
  19. build:
  20. name: Build
  21. runs-on: ubuntu-latest
  22. env:
  23. DOCKER_CLI_EXPERIMENTAL: enabled
  24. strategy:
  25. matrix:
  26. include:
  27. - {distro: debian, version: "9", pkgclouddistro: debian/stretch, format: deb, base_image: debian, platform: linux/amd64, arch: amd64}
  28. - {distro: debian, version: "9", pkgclouddistro: debian/stretch, format: deb, base_image: debian, platform: linux/i386, arch: i386}
  29. - {distro: debian, version: "10", pkgclouddistro: debian/buster, format: deb, base_image: debian, platform: linux/amd64, arch: amd64}
  30. - {distro: debian, version: "10", pkgclouddistro: debian/buster, format: deb, base_image: debian, platform: linux/i386, arch: i386}
  31. - {distro: ubuntu, version: "16.04", pkgclouddistro: ubuntu/xenial, format: deb, base_image: ubuntu, platform: linux/amd64, arch: amd64}
  32. - {distro: ubuntu, version: "16.04", pkgclouddistro: ubuntu/xenial, format: deb, base_image: ubuntu, platform: linux/i386, arch: i386}
  33. - {distro: ubuntu, version: "18.04", pkgclouddistro: ubuntu/bionic, format: deb, base_image: ubuntu, platform: linux/amd64, arch: amd64}
  34. - {distro: ubuntu, version: "18.04", pkgclouddistro: ubuntu/bionic, format: deb, base_image: ubuntu, platform: linux/i386, arch: i386}
  35. - {distro: ubuntu, version: "20.04", pkgclouddistro: ubuntu/focal, format: deb, base_image: ubuntu, platform: linux/amd64, arch: amd64}
  36. - {distro: ubuntu, version: "20.10", pkgclouddistro: ubuntu/groovy, format: deb, base_image: ubuntu, platform: linux/amd64, arch: amd64}
  37. - {distro: ubuntu, version: "21.04", pkgclouddistro: ubuntu/hirsute, format: deb, base_image: ubuntu, platform: linux/amd64, arch: amd64}
  38. - {distro: centos, version: "7", pkgclouddistro: el/7, format: rpm, base_image: centos, platform: linux/amd64, arch: amd64}
  39. - {distro: centos, version: "8", pkgclouddistro: el/8, format: rpm, base_image: centos, platform: linux/amd64, arch: amd64}
  40. - {distro: fedora, version: "32", pkgclouddistro: fedora/32, format: rpm, base_image: fedora, platform: linux/amd64, arch: amd64}
  41. - {distro: fedora, version: "33", pkgclouddistro: fedora/33, format: rpm, base_image: fedora, platform: linux/amd64, arch: amd64}
  42. - {distro: fedora, version: "34", pkgclouddistro: fedora/34, format: rpm, base_image: fedora, platform: linux/amd64, arch: amd64}
  43. - {distro: opensuse, version: "15.2", pkgclouddistro: opensuse/15.2, format: rpm, base_image: opensuse/leap, platform: linux/amd64, arch: amd64}
  44. # We intentiaonally disable the fail-fast behavior so that a
  45. # build failure for one version doesn't prevent us from publishing
  46. # successfully built and tested packages for another version.
  47. fail-fast: false
  48. steps:
  49. - name: Checkout PR # Checkout the PR if it's a PR.
  50. if: github.event_name == 'pull_request'
  51. uses: actions/checkout@v2
  52. with:
  53. fetch-depth: 0 # We need full history for versioning
  54. submodules: true
  55. - name: Checkout Tag # Otherwise check out the tag that triggered this.
  56. if: github.event_name == 'workflow_dispatch'
  57. uses: actions/checkout@v2
  58. with:
  59. ref: ${{ github.event.ref }}
  60. fetch-depth: 0 # We need full history for versioning
  61. submodules: true
  62. - name: Check Base Branch
  63. run: |
  64. if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  65. echo "runtype=${{ github.event.inputs.type }}" >> $GITHUB_ENV
  66. case "${{ github.event.inputs.type }}" in
  67. "release")
  68. echo "repo=${{ secrets.PACKAGE_CLOUD_REPO }}" >> $GITHUB_ENV
  69. echo "pkg_version=${{ github.event.inputs.version }}" >> $GITHUB_ENV
  70. echo "pkg_retention_days=365" >> $GITHUB_ENV
  71. ;;
  72. "nightly")
  73. echo "repo=${{ secrets.PACKAGE_CLOUD_REPO }}-edge" >> $GITHUB_ENV
  74. echo "pkg_version=${{ github.event.inputs.version }}" >> $GITHUB_ENV
  75. echo "pkg_retention_days=30" >> $GITHUB_ENV
  76. ;;
  77. *)
  78. echo "repo=${{ secrets.PACKAGE_CLOUD_REPO }}-devel" >> $GITHUB_ENV
  79. echo "pkg_version=0.${GITHUB_SHA}" >> $GITHUB_ENV
  80. echo "pkg_retention_days=30" >> $GITHUB_ENV
  81. ;;
  82. esac
  83. else
  84. echo "runtype=test" >> $GITHUB_ENV
  85. echo "pkg_version=$(cut -d'-' -f 1 packaging/version | sed -e 's/^v//')" >> $GITHUB_ENV
  86. fi
  87. - name: Setup QEMU
  88. if: matrix.platform != 'linux/amd64'
  89. uses: docker/setup-qemu-action@v1
  90. - name: Setup Buildx
  91. uses: docker/setup-buildx-action@v1
  92. - name: Prepare Docker Environment
  93. shell: bash
  94. run: |
  95. echo '{"cgroup-parent": "/actions_job", "experimental": true}' | sudo tee /etc/docker/daemon.json 2>/dev/null
  96. sudo service docker restart
  97. - name: Build Packages
  98. uses: docker/build-push-action@v2
  99. with:
  100. platforms: ${{ matrix.platform }}
  101. file: packaging/Dockerfile.packager
  102. tags: local/package-builder:${{ matrix.distro}}${{ matrix.version }}
  103. push: false
  104. load: true
  105. build-args: |
  106. ARCH=${{ matrix.arch }}
  107. DISTRO=${{ matrix.distro }}
  108. TEST_BASE=${{ matrix.base_image }}
  109. DISTRO_VERSION=${{ matrix.version }}
  110. PKG_VERSION=${{ env.pkg_version }}
  111. - name: Extract Packages
  112. shell: bash
  113. run: |
  114. mkdir -p artifacts
  115. docker run --platform ${{ matrix.platform }} -v $PWD/artifacts:/artifacts local/package-builder:${{ matrix.distro }}${{ matrix.version }}
  116. - name: Upload
  117. if: github.event_name == 'workflow_dispatch'
  118. shell: bash
  119. env:
  120. PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
  121. run: |
  122. echo "Packages to upload:\n$(ls artifacts/*.${{ matrix.format }})"
  123. for pkgfile in artifacts/*.${{ matrix.format }} ; do
  124. .github/scripts/package_cloud_wrapper.sh yank ${{ env.repo }}/${{ matrix.pkgclouddistro }} ${pkgfile} || true
  125. .github/scripts/package_cloud_wrapper.sh push ${{ env.repo }}/${{ matrix.pkgclouddistro }} ${pkgfile}
  126. done
  127. - name: Clean
  128. if: github.event_name == 'workflow_dispatch'
  129. shell: bash
  130. env:
  131. REPO: ${{ env.repo }}
  132. PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
  133. PACKAGE_CLOUD_RETENTION_DAYS: ${{ env.pkg_retention_days }}
  134. run: .github/scripts/old_package_purging.sh
  135. - name: Failure Notification
  136. uses: rtCamp/action-slack-notify@v2
  137. env:
  138. SLACK_COLOR: 'danger'
  139. SLACK_FOOTER:
  140. SLACK_ICON_EMOJI: ':github-actions:'
  141. SLACK_TITLE: 'Package Build failed:'
  142. SLACK_USERNAME: 'GitHub Actions'
  143. SLACK_MESSAGE: "${{ matrix.pkgclouddistro }} ${{ matrix.version }} package build for ${{ matrix.arch }} failed."
  144. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  145. if: >-
  146. ${{
  147. failure()
  148. && github.event_name != 'pull_request'
  149. && startsWith(github.ref, 'refs/heads/master')
  150. }}