利用github的actions 编译openwrt

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

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

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

其中需要修改的

启动

on:
  push:
    branches: 
      - master

改为手动执行

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

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#
# This is free software, lisence use MIT.
# 
# Copyright (C) 2019 P3TERX <https://p3terx.com>
# Copyright (C) 2020 KFERMercer <KFER.Mercer@gmail.com>
# 
# <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

一个例子

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#
# This is free software, lisence use MIT.
# 
# Copyright (C) 2019 P3TERX <https://p3terx.com>
# Copyright (C) 2020 KFERMercer <KFER.Mercer@gmail.com>
# 
# <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

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计