push-containers.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. actions: write
  134. strategy:
  135. fail-fast: False
  136. matrix:
  137. include: ${{fromJson(needs.determine-targets.outputs.target)}}
  138. uses: ./.github/workflows/build.yml
  139. with:
  140. target: ${{ matrix.target }}
  141. subtarget: ${{ matrix.subtarget }}
  142. build_toolchain: true
  143. build_external_toolchain: true
  144. upload_external_toolchain: true
  145. push-toolchain-container:
  146. name: Push Target Toolchain container
  147. if: ${{ github.repository_owner == 'openwrt' }}
  148. needs: [ determine-container-info, determine-targets, build ]
  149. runs-on: ubuntu-latest
  150. strategy:
  151. fail-fast: False
  152. matrix:
  153. include: ${{fromJson(needs.determine-targets.outputs.target)}}
  154. permissions:
  155. contents: read
  156. packages: write
  157. steps:
  158. - name: Checkout
  159. uses: actions/checkout@v3
  160. with:
  161. path: 'openwrt'
  162. - name: Download external toolchain from build job
  163. uses: actions/download-artifact@v3
  164. with:
  165. name: ${{ matrix.target }}-${{ matrix.subtarget }}-external-toolchain
  166. path: openwrt
  167. - name: Find external toolchain name
  168. id: get-toolchain-name
  169. working-directory: openwrt
  170. run: |
  171. TOOLCHAIN_NAME=$(ls | grep toolchain-${{ matrix.target }}-${{ matrix.subtarget }})
  172. echo "toolchain-name=$TOOLCHAIN_NAME" >> $GITHUB_OUTPUT
  173. - name: Login to GitHub Container Registry
  174. uses: docker/login-action@v2
  175. with:
  176. registry: ghcr.io
  177. username: ${{ github.actor }}
  178. password: ${{ secrets.GITHUB_TOKEN }}
  179. - name: Build and push
  180. uses: docker/build-push-action@v3
  181. with:
  182. context: openwrt
  183. push: true
  184. tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/toolchain:${{ matrix.target }}-${{ matrix.subtarget }}-${{ needs.determine-container-info.outputs.container-tag }}
  185. file: openwrt/.github/workflows/Dockerfile.toolchain
  186. build-args: |
  187. OWNER_LC=${{ needs.determine-container-info.outputs.owner-lc }}
  188. CONTAINER_TAG=${{ needs.determine-container-info.outputs.container-tag }}
  189. TOOLCHAIN_NAME=${{ steps.get-toolchain-name.outputs.toolchain-name }}