build-openwrt.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #=================================================
  2. # https://github.com/P3TERX/Actions-OpenWrt
  3. # Description: Build OpenWrt using GitHub Actions
  4. # Lisence: MIT
  5. # Author: P3TERX
  6. # Blog: https://p3terx.com
  7. #=================================================
  8. name: Build OpenWrt
  9. on:
  10. # push:
  11. # branches:
  12. # - master
  13. schedule:
  14. - cron: 0 16 * * 6
  15. watch:
  16. types: started
  17. env:
  18. REPO_URL: https://github.com/openwrt/openwrt
  19. REPO_BRANCH: master
  20. CONFIG_FILE: X86_64.config
  21. DIY_SH: diy.sh
  22. FREE_UP_DISK: true
  23. SSH_ACTIONS: false
  24. UPLOAD_BIN_DIR: false
  25. UPLOAD_FIRMWARE: true
  26. UPLOAD_COWTRANSFER: false
  27. TZ: Asia/Shanghai
  28. jobs:
  29. build:
  30. if: github.event.repository.owner.id == github.event.sender.id
  31. runs-on: ubuntu-latest
  32. steps:
  33. - name: Checkout
  34. uses: actions/checkout@master
  35. - name: Initialization environment
  36. env:
  37. DEBIAN_FRONTEND: noninteractive
  38. run: |
  39. sudo swapoff /swapfile
  40. sudo rm -rf /swapfile /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
  41. sudo -E apt-get -qq update
  42. sudo -E apt-get -qq install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs gcc-multilib g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler ccache xsltproc rename
  43. sudo -E apt-get -qq autoremove --purge
  44. sudo -E apt-get -qq clean
  45. curl -fsSL https://raw.githubusercontent.com/P3TERX/dotfiles/master/.bashrc >> ~/.bashrc
  46. - name: Clone source code
  47. run: git clone --depth 1 $REPO_URL -b $REPO_BRANCH openwrt
  48. - name: Free up disk space
  49. if: env.FREE_UP_DISK == 'true'
  50. env:
  51. DEBIAN_FRONTEND: noninteractive
  52. run: |
  53. sudo mkdir -p -m 777 /mnt/openwrt/build_dir/hostpkg /mnt/openwrt/build_dir/host openwrt/build_dir /mnt/openwrt/dl /mnt/openwrt/feeds /mnt/openwrt/staging_dir
  54. ln -s /mnt/openwrt/build_dir/hostpkg openwrt/build_dir/hostpkg
  55. ln -s /mnt/openwrt/build_dir/host openwrt/build_dir/host
  56. ln -s /mnt/openwrt/dl openwrt/dl
  57. ln -s /mnt/openwrt/staging_dir openwrt/staging_dir
  58. - name: Update feeds
  59. run: cd openwrt && ./scripts/feeds update -a
  60. - name: Install feeds
  61. run: cd openwrt && ./scripts/feeds install -a
  62. - name: Load custom configuration
  63. run: |
  64. [ -e files ] && mv files openwrt/files
  65. [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config
  66. chmod +x $DIY_SH
  67. cd openwrt
  68. ../$DIY_SH
  69. make defconfig
  70. - name: SSH connection to Actions
  71. uses: P3TERX/debugger-action@master
  72. if: env.SSH_ACTIONS == 'true'
  73. - name: Download package
  74. id: package
  75. run: |
  76. cd openwrt
  77. make download -j8
  78. find dl -size -1024c -exec ls -l {} \;
  79. find dl -size -1024c -exec rm -f {} \;
  80. - name: Compile the firmware
  81. id: compile
  82. run: |
  83. cd openwrt
  84. echo -e "$(($(nproc)+1)) thread compile"
  85. make -j$(($(nproc)+1)) || make -j1 V=s
  86. echo "::set-output name=status::success"
  87. - name: Upload bin directory
  88. uses: actions/upload-artifact@master
  89. if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true'
  90. with:
  91. name: OpenWrt_bin
  92. path: openwrt/bin
  93. - name: Organize files
  94. id: organize
  95. if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
  96. run: |
  97. mkdir firmware && find openwrt/bin/targets/*/*/* -maxdepth 0 -name "*uefi-gpt*" -or -name "*combined*" -or -name "*.vmdk" -or -name "sha256sums" | xargs -i mv -f {} ./firmware/
  98. cp openwrt/.config ./firmware/config.txt
  99. cd firmware
  100. echo "::set-env name=FIRMWARE::$PWD"
  101. echo "::set-output name=status::success"
  102. - name: Upload firmware directory
  103. uses: actions/upload-artifact@master
  104. if: steps.organize.outputs.status == 'success' && !cancelled()
  105. with:
  106. name: OpenWrt_firmware
  107. path: ${{ env.FIRMWARE }}
  108. - name: Get current date
  109. id: date
  110. run: echo "::set-output name=date::$(date +'%m/%d,%Y')"
  111. - name: Upload binaries to release
  112. uses: svenstaro/upload-release-action@v1-release
  113. if: steps.compile.outputs.status == 'success' && !cancelled()
  114. with:
  115. repo_token: ${{ secrets.REPO_TOKEN }}
  116. file: ${{ env.FIRMWARE }}/*
  117. tag: ${{steps.date.outputs.date}}
  118. overwrite: true
  119. file_glob: true
  120. - name: Upload firmware to cowtransfer
  121. if: env.UPLOAD_COWTRANSFER == 'true' && !cancelled()
  122. run: |
  123. curl -sL https://git.io/cowtransfer | sh
  124. ./cowtransfer-uploader -s -p 8 ${{ env.FIRMWARE }}/*