134 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			YAML
		
	
	
	
			
		
		
	
	
			134 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			YAML
		
	
	
	
| #=======================================================
 | |
| # Description: Build OpenWrt using GitHub Actions
 | |
| # https://github.com/Hyy2001X/AutoBuild-Actions
 | |
| # Lisence: MIT
 | |
| # Author: P3TERX
 | |
| # Modify: Hyy2001X
 | |
| #=======================================================
 | |
| 
 | |
| name: AutoBuild OpenWrt
 | |
| 
 | |
| on: 
 | |
| #  release:
 | |
| #    types: [published]
 | |
| 
 | |
| #  push:
 | |
| #    branches:
 | |
| #      - main
 | |
| #    paths:
 | |
| #      - '.config'
 | |
| 
 | |
| #  schedule:
 | |
| #    - cron: 0 8 * * 5
 | |
|   
 | |
|   watch:
 | |
|     types: [started]
 | |
| 
 | |
| env:
 | |
|   REPO_URL: https://github.com/coolsnowwolf/lede
 | |
|   REPO_BRANCH: master
 | |
|   CONFIG_FILE: .config
 | |
|   CUSTOM_SCRIPT: ./Scripts/diy-script.sh
 | |
|   TZ: Asia/Shanghai
 | |
|   UPLOAD_RELEASE: true
 | |
|   UPLOAD_FIRMWARE: true
 | |
|   UPLOAD_BIN_DIR: false
 | |
| 
 | |
| jobs:
 | |
|   build:
 | |
|     runs-on: ubuntu-18.04
 | |
| 
 | |
|     steps:
 | |
|     - name: Checkout
 | |
|       uses: actions/checkout@main
 | |
| 
 | |
|     - name: Initialization Environment
 | |
|       env:
 | |
|         DEBIAN_FRONTEND: noninteractive
 | |
|       run: |
 | |
|         sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
 | |
|         sudo -E apt-get -qq update
 | |
|         sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-1804)
 | |
|         sudo -E apt-get -qq clean
 | |
|         sudo timedatectl set-timezone "$TZ"
 | |
|         sudo mkdir -p /workdir
 | |
|         sudo chown $USER:$GROUPS /workdir        
 | |
| 
 | |
|     - name: Clone Openwrt source code
 | |
|       run: |
 | |
|         git clone -b $REPO_BRANCH $REPO_URL openwrt
 | |
|         ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt        
 | |
| 
 | |
|     - name: Run Diy-Part1 Scripts
 | |
|       run: |
 | |
|         chmod +x $CUSTOM_SCRIPT
 | |
|         cd openwrt
 | |
|         source $GITHUB_WORKSPACE/$CUSTOM_SCRIPT && Diy-Part1        
 | |
| 
 | |
|     - name: Update & Install Feeds
 | |
|       run: |
 | |
|         cd openwrt
 | |
|         ./scripts/feeds update -a
 | |
|         ./scripts/feeds install -a        
 | |
| 
 | |
|     - name: Run Diy-Part2 Scripts
 | |
|       run: |
 | |
|         [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config
 | |
|         cd openwrt
 | |
|         source $GITHUB_WORKSPACE/$CUSTOM_SCRIPT && Diy-Part2        
 | |
| 
 | |
|     - name: Download Packages
 | |
|       run: |
 | |
|         cd openwrt
 | |
|         make defconfig
 | |
|         make download -j8
 | |
|         find dl -size -1024c -exec rm -f {} \;        
 | |
| 
 | |
|     - name: Compile the Openwrt
 | |
|       run: |
 | |
|         cd openwrt
 | |
|         make -j$(nproc) || make -j1 || make -j1 V=s        
 | |
| 
 | |
|     - name: Run Diy-Part3 Scripts
 | |
|       run: |
 | |
|         cd openwrt
 | |
|         source $GITHUB_WORKSPACE/$CUSTOM_SCRIPT && Diy-Part3        
 | |
| 
 | |
|     - name: Upload Firmware to Artifacts
 | |
|       uses: actions/upload-artifact@main
 | |
|       if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
 | |
|       with:
 | |
|         name: OpenWrt_Firmware
 | |
|         path: openwrt/bin/Firmware
 | |
|         
 | |
|     - name: Upload Firmware directory to Artifacts
 | |
|       uses: actions/upload-artifact@main
 | |
|       if: env.UPLOAD_BIN_DIR == 'true' && !cancelled()
 | |
|       with:
 | |
|         name: OpenWrt_bin
 | |
|         path: openwrt/bin
 | |
| 
 | |
|     - name: Generate Tag
 | |
|       id: tag
 | |
|       if: env.UPLOAD_RELEASE == 'true' && !cancelled()
 | |
|       run: |
 | |
|         echo "$(date +"%Y%m%d")-AutoUpdate" > update_log.txt
 | |
|         echo "::set-env name=FIRMWARE::openwrt/bin/Firmware"
 | |
|         echo "::set-output name=status::success"        
 | |
| 
 | |
|     - name: Upload Firmware to Releases
 | |
|       uses: softprops/action-gh-release@v1
 | |
|       if: steps.tag.outputs.status == 'success' && !cancelled()
 | |
|       env:
 | |
|         GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
 | |
|       with:
 | |
|         tag_name: AutoUpdate
 | |
|         body_path: update_log.txt
 | |
|         files: ${{ env.FIRMWARE }}/*
 | |
| 
 | |
|     - name: Remove old Artifacts
 | |
|       uses: c-hive/gha-remove-artifacts@v1
 | |
|       with:
 | |
|         age: '1 month'
 | |
|         skip-recent: 3
 |