push-containers.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. name: Build and Push prebuilt tools container
  2. on:
  3. push:
  4. paths:
  5. - 'include/version.mk'
  6. - 'tools/**'
  7. - '.github/workflows/build-tools.yml'
  8. - '.github/workflows/push-containers.yml'
  9. - '.github/workflows/Dockerfile.tools'
  10. - 'toolchain/**'
  11. - '.github/workflows/build.yml'
  12. - '.github/workflows/toolchain.yml'
  13. - '.github/workflows/Dockerfile.toolchain'
  14. branches-ignore:
  15. - master
  16. permissions:
  17. contents: read
  18. concurrency:
  19. group: ${{ github.workflow }}
  20. cancel-in-progress: true
  21. jobs:
  22. determine-container-info:
  23. name: Determine needed info to push containers
  24. if: ${{ github.repository_owner == 'openwrt' }}
  25. runs-on: ubuntu-latest
  26. outputs:
  27. owner-lc: ${{ steps.generate-owner-lc.outputs.owner-lc }}
  28. container-tag: ${{ steps.determine-container-tag.outputs.container-tag }}
  29. steps:
  30. - name: Set lower case owner name
  31. id: generate-owner-lc
  32. env:
  33. OWNER: ${{ github.repository_owner }}
  34. run: |
  35. echo "owner-lc=${OWNER,,}" >> "$GITHUB_OUTPUT"
  36. # Per branch tools container tag
  37. # By default stick to latest
  38. # For official test targetting openwrt stable branch
  39. # Get the branch or parse the tag and push dedicated tools containers
  40. # Any branch that will match this pattern openwrt-[0-9][0-9].[0-9][0-9]
  41. # will refresh the tools container with the matching tag.
  42. # (example branch openwrt-22.03 -> tools:openwrt-22.03)
  43. # (example branch openwrt-22.03-test -> tools:openwrt-22.03)
  44. - name: Determine tools container tag
  45. id: determine-container-tag
  46. run: |
  47. CONTAINER_TAG=latest
  48. if [ ${{ github.ref_type }} == "branch" ]; then
  49. if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
  50. CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\).*/\1/')"
  51. fi
  52. elif [ ${{ github.ref_type }} == "tag" ]; then
  53. if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
  54. CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
  55. fi
  56. fi
  57. echo "Container tag to push for tools and toolchain is $CONTAINER_TAG"
  58. echo "container-tag=$CONTAINER_TAG" >> "$GITHUB_OUTPUT"
  59. build-linux-buildbot:
  60. name: Build tools with buildbot container
  61. if: ${{ github.repository_owner == 'openwrt' }}
  62. uses: ./.github/workflows/build-tools.yml
  63. with:
  64. generate_prebuilt_artifacts: true
  65. push-tools-container:
  66. needs: [ determine-container-info, build-linux-buildbot ]
  67. if: ${{ github.repository_owner == 'openwrt' }}
  68. name: Push prebuilt tools container
  69. runs-on: ubuntu-latest
  70. permissions:
  71. contents: read
  72. packages: write
  73. steps:
  74. - name: Checkout
  75. uses: actions/checkout@v3
  76. with:
  77. path: 'openwrt'
  78. - name: Download prebuilt tools from build job
  79. uses: actions/download-artifact@v3
  80. with:
  81. name: linux-buildbot-prebuilt-tools
  82. path: openwrt
  83. - name: Extract prebuild tools
  84. working-directory: openwrt
  85. run: tar -xf tools.tar
  86. - name: Login to GitHub Container Registry
  87. uses: docker/login-action@v2
  88. with:
  89. registry: ghcr.io
  90. username: ${{ github.actor }}
  91. password: ${{ secrets.GITHUB_TOKEN }}
  92. - name: Build and push
  93. uses: docker/build-push-action@v3
  94. with:
  95. context: openwrt
  96. push: true
  97. tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/tools:${{ needs.determine-container-info.outputs.container-tag }}
  98. file: openwrt/.github/workflows/Dockerfile.tools
  99. determine-targets:
  100. name: Set targets
  101. if: ${{ github.repository_owner == 'openwrt' }}
  102. runs-on: ubuntu-latest
  103. outputs:
  104. target: ${{ steps.find_targets.outputs.target }}
  105. steps:
  106. - name: Checkout
  107. uses: actions/checkout@v3
  108. - name: Set targets
  109. id: find_targets
  110. run: |
  111. export TARGETS="$(perl ./scripts/dump-target-info.pl targets 2>/dev/null \
  112. | awk '{ print $1 }')"
  113. JSON='['
  114. FIRST=1
  115. for TARGET in $TARGETS; do
  116. TUPLE='{"target":"'"$(echo $TARGET | cut -d "/" -f 1)"'","subtarget":"'"$(echo $TARGET | cut -d "/" -f 2)"'"}'
  117. [[ $FIRST -ne 1 ]] && JSON="$JSON"','
  118. JSON="$JSON""$TUPLE"
  119. FIRST=0
  120. done
  121. JSON="$JSON"']'
  122. echo -e "\n---- targets ----\n"
  123. echo "$JSON"
  124. echo -e "\n---- targets ----\n"
  125. echo "target=$JSON" >> $GITHUB_OUTPUT
  126. build:
  127. name: Build Target Toolchain
  128. if: ${{ github.repository_owner == 'openwrt' }}
  129. needs: [ determine-targets, push-tools-container ]
  130. permissions:
  131. contents: read
  132. packages: read
  133. strategy:
  134. fail-fast: False
  135. matrix:
  136. include: ${{fromJson(needs.determine-targets.outputs.target)}}
  137. uses: ./.github/workflows/build.yml
  138. with:
  139. target: ${{ matrix.target }}
  140. subtarget: ${{ matrix.subtarget }}
  141. build_toolchain: true
  142. build_external_toolchain: true
  143. upload_external_toolchain: true
  144. push-toolchain-container:
  145. name: Push Target Toolchain container
  146. if: ${{ github.repository_owner == 'openwrt' }}
  147. needs: [ determine-container-info, determine-targets, build ]
  148. runs-on: ubuntu-latest
  149. strategy:
  150. fail-fast: False
  151. matrix:
  152. include: ${{fromJson(needs.determine-targets.outputs.target)}}
  153. permissions:
  154. contents: read
  155. packages: write
  156. steps:
  157. - name: Checkout
  158. uses: actions/checkout@v3
  159. with:
  160. path: 'openwrt'
  161. - name: Download external toolchain from build job
  162. uses: actions/download-artifact@v3
  163. with:
  164. name: ${{ matrix.target }}-${{ matrix.subtarget }}-external-toolchain
  165. path: openwrt
  166. - name: Find external toolchain name
  167. id: get-toolchain-name
  168. working-directory: openwrt
  169. run: |
  170. TOOLCHAIN_NAME=$(ls | grep toolchain-${{ matrix.target }}-${{ matrix.subtarget }})
  171. echo "toolchain-name=$TOOLCHAIN_NAME" >> $GITHUB_OUTPUT
  172. - name: Login to GitHub Container Registry
  173. uses: docker/login-action@v2
  174. with:
  175. registry: ghcr.io
  176. username: ${{ github.actor }}
  177. password: ${{ secrets.GITHUB_TOKEN }}
  178. - name: Build and push
  179. uses: docker/build-push-action@v3
  180. with:
  181. context: openwrt
  182. push: true
  183. tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/toolchain:${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.determine-container-info.outputs.container-tag }}
  184. file: openwrt/.github/workflows/Dockerfile.toolchain
  185. build-args: |
  186. OWNER_LC=${{ needs.determine-container-info.outputs.owner-lc }}
  187. CONTAINER_TAG=${{ needs.determine-container-info.outputs.container-tag }}
  188. TOOLCHAIN_NAME=${{ steps.get-toolchain-name.outputs.toolchain-name }}