利用github的actions 编译openwrt

openwrt

优势:免去自己搭建环境,利用GitHub的带宽

本次使用灯大的源,并借鉴KFERMercer的ci

plaintext
https://github.com/coolsnowwolf/lede
https://github.com/KFERMercer/OpenWrt-CI

#复制Fork coolsnowwolf的源

Fork Openwrt

https://github.com/coolsnowwolf/lede/fork

#编辑action文件

复制 https://github.com/KFERMercer/OpenWrt-CI/blob/master/openwrt-ci.yml 的内容编辑

放置到你fork的仓库的 .github/workflows/openwrt-ci.yml

#其中需要修改的

#启动

plaintext
on:
  push:
    branches: 
      - master

改为手动执行

plaintext
on:
  workflow_dispatch:

#自定义包

找到你需要安装的包名,官方https://openwrt.org/packages/index/start
Lean/coolsnowwolf 的软件包可以从 make defconfig 配置文件 .config 中找到
添加包到openwrt-ci.yml 中 cat >> .config <<EOF后面

#手动开始

先更新你的OpenWrt源-> Fetch upstream -> Fetch Merge

手动开始编译 Action -> OpenWrt-CI -> Run workflow

大概需要2-3小时,然后下载 ,下载OpenWrt_firmware即可

#初始内容

https://github.com/KFERMercer/OpenWrt-CI/blob/master/openwrt-ci.yml

plaintext
#
# This is free software, lisence use MIT.
# 
# Copyright (C) 2019 P3TERX <https://p3terx.com>
# Copyright (C) 2020 KFERMercer <[email protected]>
# 
# <https://github.com/KFERMercer/OpenWrt-CI>
#

name: OpenWrt-CI

on:
  push:
    branches: 
      - master
  # schedule:
  #   - cron: 0 20 * * *
  release:
    types: [published]

jobs:

  build_openwrt:

    name: Build OpenWrt firmware

    runs-on: ubuntu-latest

    if: github.event.repository.owner.id == github.event.sender.id

    steps:

      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: master

      - name: Space cleanup
        env:
          DEBIAN_FRONTEND: noninteractive
        run: |
          docker rmi `docker images -q`
          sudo rm -rf /usr/share/dotnet /etc/mysql /etc/php /etc/apt/sources.list.d /usr/local/lib/android
          sudo -E apt-get -y purge azure-cli ghc* zulu* hhvm llvm* firefox google* dotnet* powershell openjdk* adoptopenjdk* mysql* php* mongodb* dotnet* moby* snapd* || true
          sudo -E apt-get update
          sudo -E apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 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 antlr3 gperf swig libtinfo5
          sudo -E apt-get -y autoremove --purge
          sudo -E apt-get clean
          # sudo mkdir -p -m 777 /mnt/openwrt/bin /mnt/openwrt/build_dir/host /mnt/openwrt/build_dir/hostpkg /mnt/openwrt/dl /mnt/openwrt/feeds /mnt/openwrt/staging_dir
          # ln -s /mnt/openwrt/bin ./bin
          # mkdir -p ./build_dir
          # ln -s -f /mnt/openwrt/build_dir/host ./build_dir/host
          # ln -s -f /mnt/openwrt/build_dir/hostpkg ./build_dir/hostpkg
          # ln -s /mnt/openwrt/dl ./dl
          # ln -s /mnt/openwrt/feeds ./feeds
          # ln -s /mnt/openwrt/staging_dir ./staging_dir
          df -h
      - name: Update feeds
        run: |
          ./scripts/feeds update -a
          ./scripts/feeds install -a
      - name: Generate configuration file
        run: |
          rm -f ./.config*
          touch ./.config
          #
          # 在 cat >> .config <<EOF 到 EOF 之间粘贴你的编译配置, 需注意缩进关系
          # 例如:
          cat >> .config <<EOF
          CONFIG_TARGET_IMAGES_GZIP=y
          CONFIG_KERNEL_BUILD_USER="OpenWrt-CI"
          CONFIG_KERNEL_BUILD_DOMAIN="Azure"
          EOF
          #
          # ===============================================================
          # 
          sed -i 's/^[ \t]*//g' ./.config
          make defconfig
      - name: Make download
        run: |
          make download -j8 || make download -j1 V=s
          rm -rf $(find ./dl/ -size -1024c)
          df -h
      - name: Compile firmware
        run: |
          make -j$(nproc) || make -j1 V=s
          echo "======================="
          echo "Space usage:"
          echo "======================="
          df -h
          echo "======================="
          du -h ./ --max-depth=1
          du -h /mnt/openwrt/ --max-depth=1 || true
      - name: Prepare artifact
        run: |
          mkdir -p ./artifact/firmware
          mkdir -p ./artifact/package
          mkdir -p ./artifact/buildinfo
          rm -rf $(find ./bin/targets/ -type d -name "packages")
          cp -rf $(find ./bin/targets/ -type f) ./artifact/firmware/
          cp -rf $(find ./bin/packages/ -type f -name "*.ipk") ./artifact/package/
          cp -rf $(find ./bin/targets/ -type f -name "*.buildinfo" -o -name "*.manifest") ./artifact/buildinfo/
      - name: Deliver buildinfo
        uses: actions/upload-artifact@v2
        with:
          name: OpenWrt_buildinfo
          path: ./artifact/buildinfo/

      - name: Deliver package
        uses: actions/upload-artifact@v2
        with:
          name: OpenWrt_package
          path: ./artifact/package/

      - name: Deliver firmware
        uses: actions/upload-artifact@v2
        with:
          name: OpenWrt_firmware
          path: ./bin/targets/

      - name: Upload release asset
        if: github.event == 'release'
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.YOURTOKEN }}
          file: ./artifact/firmware/*
          tag: ${{ github.ref }}
          file_glob: true

#一个例子

plaintext
#
# This is free software, lisence use MIT.
# 
# Copyright (C) 2019 P3TERX <https://p3terx.com>
# Copyright (C) 2020 KFERMercer <[email protected]>
# 
# <https://github.com/KFERMercer/OpenWrt-CI>
#

name: OpenWrt-CI

on:
  workflow_dispatch:
  #push:
  #  branches: 
  #    - master
  # schedule:
  #   - cron: 0 20 * * *
  release:
    types: [published]

jobs:

  build_openwrt:

    name: Build OpenWrt firmware

    runs-on: ubuntu-latest

    if: github.event.repository.owner.id == github.event.sender.id

    steps:

      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: master

      - name: Space cleanup
        env:
          DEBIAN_FRONTEND: noninteractive
        run: |
          docker rmi `docker images -q`
          sudo rm -rf /usr/share/dotnet /etc/mysql /etc/php /etc/apt/sources.list.d /usr/local/lib/android
          sudo -E apt-get -y purge azure-cli ghc* zulu* hhvm llvm* firefox google* dotnet* powershell openjdk* adoptopenjdk* mysql* php* mongodb* dotnet* moby* snapd* || true
          sudo -E apt-get update
          sudo -E apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 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 antlr3 gperf swig libtinfo5
          sudo -E apt-get -y autoremove --purge
          sudo -E apt-get clean

          # sudo mkdir -p -m 777 /mnt/openwrt/bin /mnt/openwrt/build_dir/host /mnt/openwrt/build_dir/hostpkg /mnt/openwrt/dl /mnt/openwrt/feeds /mnt/openwrt/staging_dir
          # ln -s /mnt/openwrt/bin ./bin
          # mkdir -p ./build_dir
          # ln -s -f /mnt/openwrt/build_dir/host ./build_dir/host
          # ln -s -f /mnt/openwrt/build_dir/hostpkg ./build_dir/hostpkg
          # ln -s /mnt/openwrt/dl ./dl
          # ln -s /mnt/openwrt/feeds ./feeds
          # ln -s /mnt/openwrt/staging_dir ./staging_dir

          df -h          

      - name: Update feeds
        run: |
          echo "src-git helloworld https://github.com/fw876/helloworld.git" >> "feeds.conf.default"
          ./scripts/feeds update -a
          ./scripts/feeds install -a          

      - name: Generate configuration file
        run: |
          rm -f ./.config*
          touch ./.config

          #
          # 在 cat >> .config <<EOF 到 EOF 之间粘贴你的编译配置, 需注意缩进关系
          # 例如:

          cat >> .config <<EOF
          CONFIG_LUCI_LANG_en=y
          CONFIG_LUCI_LANG_zh-cn=y
          CONFIG_PACKAGE_luci-app-baidupcs-web=y
          CONFIG_PACKAGE_luci-app-cifs-mount=y
          CONFIG_PACKAGE_luci-app-wireguard=y
          CONFIG_PACKAGE_luci-app-https-dns-proxy=y
          CONFIG_PACKAGE_luci-app-netdata=y
          CONFIG_PACKAGE_luci-app-p910nd=y
          CONFIG_PACKAGE_luci-app-ssr-plus=y
          CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Hysteria=y
          CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_IPT2Socks=y
          CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan=y
          CONFIG_PACKAGE_luci-app-turboacc_INCLUDE_DNSFORWARDER=y
          CONFIG_PACKAGE_luci-app-turboacc_INCLUDE_DNSPROXY=y
          CONFIG_PACKAGE_luci-app-uugamebooster=y
          CONFIG_PACKAGE_luci-app-syncdial=y
          # CONFIG_PACKAGE_luci-app-unblockmusic is not set
          # CONFIG_PACKAGE_luci-app-ttyd is not set
          # CONFIG_PACKAGE_luci-app-xlnetacc is not set
          CONFIG_PACKAGE_luci-theme-argon=y
          CONFIG_PACKAGE_luci-theme-bootstrap=y
          CONFIG_PACKAGE_luci-theme-material=y
          CONFIG_PACKAGE_luci-theme-netgear=y
          CONFIG_PACKAGE_ddns-scripts_cloudflare.com-v4=y
          CONFIG_PACKAGE_ddns-scripts_no-ip_com=y
          CONFIG_PACKAGE_ddns-scripts_route53-v1=y
          CONFIG_PACKAGE_bind-dig=y
          CONFIG_PACKAGE_nano=y
          CONFIG_PACKAGE_qrencode=y
          CONFIG_PACKAGE_open-vm-tools=y
          CONFIG_PACKAGE_whois=y
          CONFIG_PACKAGE_nmap-ssl=y
          CONFIG_PACKAGE_ipv6helper=y
          EOF

          #
          # ===============================================================
          # 

          sed -i 's/^[ \t]*//g' ./.config
          make defconfig          

      - name: Make download
        run: |
          make download -j8 || make download -j1 V=s
          rm -rf $(find ./dl/ -size -1024c)
          df -h          

      - name: Compile firmware
        run: |
          make -j$(nproc) || make -j1 V=s
          echo "======================="
          echo "Space usage:"
          echo "======================="
          df -h
          echo "======================="
          du -h ./ --max-depth=1
          du -h /mnt/openwrt/ --max-depth=1 || true          

      - name: Prepare artifact
        run: |
          mkdir -p ./artifact/firmware
          mkdir -p ./artifact/package
          mkdir -p ./artifact/buildinfo
          rm -rf $(find ./bin/targets/ -type d -name "packages")
          cp -rf $(find ./bin/targets/ -type f) ./artifact/firmware/
          cp -rf $(find ./bin/packages/ -type f -name "*.ipk") ./artifact/package/
          cp -rf $(find ./bin/targets/ -type f -name "*.buildinfo" -o -name "*.manifest") ./artifact/buildinfo/          

      - name: Deliver buildinfo
        uses: actions/upload-artifact@v2
        with:
          name: OpenWrt_buildinfo
          path: ./artifact/buildinfo/

      - name: Deliver package
        uses: actions/upload-artifact@v2
        with:
          name: OpenWrt_package
          path: ./artifact/package/

      - name: Deliver firmware
        uses: actions/upload-artifact@v2
        with:
          name: OpenWrt_firmware
          path: ./bin/targets/

      - name: Upload release asset
        if: github.event == 'release'
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.YOURTOKEN }}
          file: ./artifact/firmware/*
          tag: ${{ github.ref }}
          file_glob: true

本文参考:https://github.com/P3TERX/Actions-OpenWrt

评论