push-containers.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. name: Build and Push prebuilt tools container
  2. on:
  3. push:
  4. paths:
  5. - 'tools/**'
  6. - '.github/workflows/build-tools.yml'
  7. - '.github/workflows/push-containers.yml'
  8. - '.github/workflows/Dockerfile.tools'
  9. permissions:
  10. contents: read
  11. concurrency:
  12. group: ${{ github.workflow }}
  13. cancel-in-progress: true
  14. jobs:
  15. build-linux-buildbot:
  16. name: Build tools with buildbot container
  17. if: ${{ github.repository_owner == 'openwrt' }}
  18. uses: ./.github/workflows/build-tools.yml
  19. with:
  20. generate_prebuilt_artifacts: true
  21. push-tools-container:
  22. needs: build-linux-buildbot
  23. name: Push prebuilt tools container
  24. if: ${{ github.repository_owner == 'openwrt' }}
  25. runs-on: ubuntu-latest
  26. permissions:
  27. contents: read
  28. packages: write
  29. steps:
  30. - name: Set lower case owner name
  31. env:
  32. OWNER: ${{ github.repository_owner }}
  33. run: |
  34. echo "OWNER_LC=${OWNER,,}" >> "$GITHUB_ENV"
  35. # Per branch tools container tag
  36. # By default stick to latest
  37. # For official test targetting openwrt stable branch
  38. # Get the branch or parse the tag and push dedicated tools containers
  39. # Any branch that will match this pattern openwrt-[0-9][0-9].[0-9][0-9]
  40. # will refresh the tools container with the matching tag.
  41. # (example branch openwrt-22.03 -> tools:openwrt-22.03)
  42. # (example branch openwrt-22.03-test -> tools:openwrt-22.03)
  43. - name: Determine tools container tag
  44. run: |
  45. CONTAINER_TAG=latest
  46. if [ ${{ github.ref_type }} == "branch" ]; then
  47. if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
  48. CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\).*/\1/')"
  49. fi
  50. elif [ ${{ github.ref_type }} == "tag" ]; then
  51. if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
  52. CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
  53. fi
  54. fi
  55. echo "Tools container to push tools:$CONTAINER_TAG"
  56. echo "CONTAINER_TAG=$CONTAINER_TAG" >> "$GITHUB_ENV"
  57. - name: Checkout
  58. uses: actions/checkout@v3
  59. with:
  60. path: 'openwrt'
  61. - name: Download prebuilt tools from build job
  62. uses: actions/download-artifact@v3
  63. with:
  64. name: linux-buildbot-prebuilt-tools
  65. path: openwrt
  66. - name: Extract prebuild tools
  67. working-directory: openwrt
  68. run: tar -xf tools.tar
  69. - name: Login to GitHub Container Registry
  70. uses: docker/login-action@v2
  71. with:
  72. registry: ghcr.io
  73. username: ${{ github.actor }}
  74. password: ${{ secrets.GITHUB_TOKEN }}
  75. - name: Build and push
  76. uses: docker/build-push-action@v3
  77. with:
  78. context: openwrt
  79. push: true
  80. tags: ghcr.io/${{ env.OWNER_LC }}/tools:${{ env.CONTAINER_TAG }}
  81. file: openwrt/.github/workflows/Dockerfile.tools