name: build-x86-64-Release on: workflow_dispatch: inputs: profile: description: '手动输入的多个 profile,并按逗号分隔' required: true default: 'generic' jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Set executable permissions run: chmod +x build.sh - name: Get current version from version.txt id: get_version run: | # 如果版本文件不存在,设置默认版本 if [ ! -f version.txt ]; then echo "v1.0.0" > version.txt fi # 获取当前版本号并输出 version=$(cat version.txt) echo "Current version: $version" echo "::set-output name=version::$version" - name: Increment version id: increment_version run: | # 解析当前版本号并自增 version=${{ steps.get_version.outputs.version }} version_parts=(${version//./ }) patch=${version_parts[2]} new_patch=$((patch + 1)) new_version="v${version_parts[0]}.${version_parts[1]}.$new_patch" # 更新 version.txt echo $new_version > version.txt echo "New version: $new_version" echo "::set-output name=new_version::$new_version" - name: Setup Docker and Build run: | profiles="${{ github.event.inputs.profile }}" IFS=',' read -r -a profile_array <<< "$profiles" for profile in "${profile_array[@]}"; do echo "Building for profile: $profile" docker run --rm -i \ --user root \ -v "${{ github.workspace }}/bin:/home/build/immortalwrt/bin" \ -v "${{ github.workspace }}/files:/home/build/immortalwrt/files" \ -v "${{ github.workspace }}/x86-64/imm.config:/home/build/immortalwrt/.config" \ -v "${{ github.workspace }}/x86-64/build.sh:/home/build/immortalwrt/build.sh" \ -e PROFILE=$profile \ immortalwrt/imagebuilder:x86-64-openwrt-23.05.4 /bin/bash /home/build/immortalwrt/build.sh done - name: Locate squashfs firmware files id: locate_files run: | # 查找符合条件的固件文件 firmware_files=$(find "${{ github.workspace }}/bin" -type f -name '*squashfs-combined*.img.gz') # 格式化路径,以避免多余的换行或空格 firmware_files=$(echo "$firmware_files" | tr '\n' ' ') echo "Squashfs firmware files located: $firmware_files" echo "firmware_paths=$firmware_files" >> $GITHUB_ENV # 提取文件名并设置为环境变量 firmware_name=$(basename "$firmware_files") echo "firmware_name=$firmware_name" >> $GITHUB_ENV - name: Upload firmware to GitHub Artifact uses: actions/upload-artifact@v4 with: name: firmware path: ${{ env.firmware_paths }} compression-level: 0 - name: Create GitHub Release id: create_release uses: actions/create-release@v1 with: tag_name: ${{ steps.increment_version.outputs.new_version }} # 使用自增版本号 release_name: "${{ github.event.inputs.profile }} Build $(date +'%Y-%m-%d %H:%M')" # 使用时间戳作为 release 名称 draft: false prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Upload firmware to GitHub Release uses: actions/upload-release-asset@v1 with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ${{ env.firmware_paths }} # 传递固件文件路径 asset_name: ${{ env.firmware_name }} # 使用提取的文件名 asset_content_type: application/gzip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}