Defconfig #71
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Copyright (c) 2022-2026 SMALLPROGRAM <https://github.com/smallprogram/OpenWrtAction> | |
| # | |
| # This is free software, licensed under the MIT License. | |
| # See /LICENSE for more information. | |
| # | |
| # https://github.com/smallprogram/OpenWrtAction | |
| # Description: Defconfig OpenWrt using GitHub Actions | |
| # | |
| name: Defconfig | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| ssh: | |
| description: 'SSH connection to Actions' | |
| required: false | |
| default: 'false' | |
| is_copy_seeds: | |
| description: 'Do you want to copy the seed?' | |
| required: false | |
| default: 'false' | |
| # schedule: | |
| # - cron: 0 */8 * * * | |
| env: | |
| MAKE_DEFCONFIG_SH: compile_script/step01_make_defconfig.sh | |
| GENERATE_RELEASE_TAG_SH: compile_script/step02_generate_release_tag.sh | |
| GENERATE_GIT_LOG_SH: compile_script/step03_generate_git_log.sh | |
| UPDATE_GIT_LOG_SH: compile_script/step06_update_git_log.sh | |
| ORGANIZE_TAG_SH: compile_script/step07_organize_tag.sh | |
| PLATFORMS_SH: compile_script/platforms.sh | |
| UPLOAD_BIN_DIR: false | |
| UPLOAD_FIRMWARE: true | |
| UPLOAD_ARTIFACT: true | |
| UPLOAD_RELEASE: true | |
| TZ: Asia/Shanghai | |
| jobs: | |
| job_init: | |
| runs-on: ubuntu-latest | |
| name: Init | |
| outputs: | |
| output_release_tag: ${{ steps.gen_release_tag.outputs.release_tag }} | |
| platforms: ${{ steps.read-platforms.outputs.matrix }} | |
| platforms_source: ${{ steps.read-platforms.outputs.source_matrix_json }} | |
| steps: | |
| - name: Generate Tag Name | |
| id: gen_release_tag | |
| run: | | |
| echo "release_tag=multi-platform_$(date +"%Y.%m.%d_%H.%M.%S")" >> $GITHUB_OUTPUT | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Read Platforms From File | |
| id: read-platforms | |
| run: | | |
| bash $PLATFORMS_SH | |
| job_source_init: | |
| needs: job_init | |
| runs-on: ${{ matrix.value.OS }} | |
| name: Source-Init-${{ matrix.source_code_platform }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJson(needs.job_init.outputs.platforms_source) }} | |
| steps: | |
| - name: Init System | |
| id: init | |
| run: | | |
| sudo timedatectl set-timezone "$TZ" | |
| sudo mkdir -p /workdir | |
| sudo chown -R $USER:$GROUPS /workdir | |
| cd /workdir | |
| sudo mkdir -p output | |
| sudo chown -R $USER:$GROUPS /workdir/output | |
| ln -sf /workdir/output $GITHUB_WORKSPACE/output | |
| df -hT | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Clone Source Code | |
| working-directory: /workdir | |
| run: | | |
| git clone -b ${{matrix.value.REPO_BRANCH}} --single-branch ${{ matrix.value.REPO_URL }} openwrt | |
| ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt | |
| - name: Load Custom Feeds | |
| run: | | |
| # [ -e $FEEDS_CONF ] && cp -r ${{ matrix.value.FEEDS_CONF }} openwrt/feeds.conf.default | |
| chmod +x ${{ matrix.value.DIY_P1_SH }} | |
| cd openwrt | |
| $GITHUB_WORKSPACE/${{ matrix.value.DIY_P1_SH }} | |
| - name: Update Feeds | |
| run: | | |
| cd openwrt | |
| ./scripts/feeds update -a | |
| - name: Run DIY Part 2 Script | |
| run: | | |
| chmod +x ${{ matrix.value.DIY_P2_SH }} | |
| cd openwrt | |
| $GITHUB_WORKSPACE/${{ matrix.value.DIY_P2_SH }} | |
| - name: Install Feeds | |
| run: | | |
| cd openwrt | |
| ./scripts/feeds update -i | |
| ./scripts/feeds install -a | |
| - name: Pull the latest changes and Create temporary branch | |
| run: | | |
| git fetch origin | |
| git reset --hard origin/${{ github.ref_name }} | |
| git checkout -b temp-${{ matrix.source_code_platform }} | |
| - name: Make Defconfig Custom Configuration | |
| run: | | |
| chmod +x $MAKE_DEFCONFIG_SH | |
| cd openwrt | |
| $GITHUB_WORKSPACE/$MAKE_DEFCONFIG_SH "${{ matrix.source_code_platform }}" "${{ matrix.value.CONFIGS }}" "${{ github.event.inputs.is_copy_seeds }}" | |
| - name: Merge and push changes with "theirs" strategy | |
| run: | | |
| git checkout temp-${{ matrix.source_code_platform }} | |
| git add . | |
| if ! git diff --cached --quiet; then | |
| git config user.name "smallprogram" | |
| git config user.email "smallprogram@foxmail.com" | |
| git commit -m "Configuration: update code for ${{ matrix.source_code_platform }}" | |
| MAX_RETRIES=10 | |
| RETRY_COUNT=0 | |
| # 循环重试机制解决矩阵并发 Push 冲突 | |
| while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do | |
| git checkout ${{ github.ref_name }} | |
| git fetch origin ${{ github.ref_name }} | |
| git reset --hard origin/${{ github.ref_name }} | |
| # 合并当前的临时分支 | |
| git merge temp-${{ matrix.source_code_platform }} --strategy-option theirs --no-edit | |
| if git push origin ${{ github.ref_name }}; then | |
| echo "Push successful!" | |
| break | |
| else | |
| echo "Push failed due to concurrent update. Retrying in a few seconds..." | |
| git reset --hard HEAD~1 | |
| RETRY_COUNT=$((RETRY_COUNT+1)) | |
| sleep $((RANDOM % 5 + 3)) # 随机等待 3-7 秒错开并发 | |
| fi | |
| done | |
| if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then | |
| echo "Failed to push after $MAX_RETRIES attempts." | |
| exit 100 | |
| fi | |
| # 只删除本地临时分支 | |
| git branch -D temp-${{ matrix.source_code_platform }} || echo "Local temp branch not found" | |
| else | |
| echo "No changes to commit." | |
| fi |