diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..94de53a8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,251 @@ +name: build + +on: + workflow_dispatch: + # release: + # types: [ published ] + # workflow_run: + # workflows: ["build"] + # types: + # - completed +jobs: + get-release: + runs-on: ubuntu-latest + outputs: + tag_name: ${{ steps.get-release.outputs.tag_name }} + upload_url: ${{ steps.get-release.outputs.upload_url }} + + steps: + - uses: actions/checkout@v3 + - uses: thebritican/fetch-latest-release@v2.0.0 + id: get-release + build-windows: + runs-on: windows-latest + needs: [ get-release ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "^1.20" + - uses: subosito/flutter-action@v2 + with: + flutter-version: '3.10.2' + channel: 'stable' + - name: Build + env: + VERSION: ${{ needs.get-release.outputs.tag_name }} + run: | + cd core + go build -ldflags="-w -s" -buildmode=c-shared -o ./dist/libclash.dll mapleafgo.cn/clash_for_flutter/core + cd ../ + + dart pub global activate flutter_distributor + flutter_distributor package --platform=windows --targets=exe + + - uses: actions/upload-artifact@v3 + with: + name: android + path: dist/*/* + retention-days: 2 + - name: Upload + uses: shogo82148/actions-upload-release-asset@v1 + with: + upload_url: ${{ needs.get-release.outputs.upload_url }} + asset_path: dist/*/* + overwrite: true + + + build-android: + runs-on: ubuntu-latest + needs: [ get-release ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4.0.1 + with: + go-version: "^1.20" + - name: Set up MinGW + uses: egor-tensin/setup-mingw@v2 + with: + platform: x64 + + - name: Setup Java + + uses: actions/setup-java@v3 + with: + distribution: "zulu" + java-version: 11 + + - name: Setup Android SDK + if: matrix.platform == 'android' + uses: android-actions/setup-android@v2 + + - name: Get Dependencies + run: | + flutter pub get + + - name: Generate + run: | + dart run build_runner build --delete-conflicting-outputs + dart run slang + + + - name: Generate Libs Android + run: | + make android-libs + + - name: Release Android + run: | + flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi + + - name: Copy to out + run: | + mkdir out + IFS=',' read -r -a EXT_ARRAY <<< "${{ matrix.targets }}" + + # Loop over extensions + for EXT in "${EXT_ARRAY[@]}"; do + # Find all files with this extension in SRC_DIR, and copy them to DST_DIR + find "." -type f -name "*.$EXT" -exec cp {} "out" \; + done + + - uses: actions/upload-artifact@v3 + with: + name: android + path: ./out + retention-days: 2 + + - name: Upload + uses: shogo82148/actions-upload-release-asset@v1 + with: + upload_url: ${{ needs.get-release.outputs.upload_url }} + asset_path: out/* + overwrite: true + + build-linux: + runs-on: ubuntu-20.04 + needs: [ get-release ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "^1.20" + - uses: subosito/flutter-action@v2 + with: + flutter-version: '3.10.2' + channel: 'stable' + - run: | + sudo apt-get update -y + sudo apt-get install -y locate ninja-build libgtk-3-dev libayatana-appindicator3-dev libnotify-dev \ + binutils coreutils desktop-file-utils fakeroot fuse libgdk-pixbuf2.0-dev patchelf python3-pip python3-setuptools squashfs-tools strace util-linux zsync + - name: Build + env: + VERSION: ${{ needs.get-release.outputs.tag_name }} + run: | + curl -L https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -o /usr/local/bin/appimagetool + chmod +x /usr/local/bin/appimagetool + + cd core + go build -ldflags="-w -s" -buildmode=c-shared -o ./dist/libclash.so mapleafgo.cn/clash_for_flutter/core + cd ../ + + dart pub global activate flutter_distributor + flutter_distributor package --platform=linux --targets=appimage,zip + + - uses: actions/upload-artifact@v3 + with: + name: linux + path: dist/*/* + retention-days: 2 + + - name: Upload + uses: shogo82148/actions-upload-release-asset@v1 + with: + upload_url: ${{ needs.get-release.outputs.upload_url }} + asset_path: dist/*/* + overwrite: true + + + build-macos-arm64-lib: + runs-on: ubuntu-latest + needs: [ get-release ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "^1.20" + - run: mkdir -p ~/image-cache + - id: image-cache + uses: actions/cache@v3 + with: + path: ~/image-cache + key: image-cache-xgo-v1.20 + - if: steps.image-cache.outputs.cache-hit != 'true' + run: | + docker pull techknowlogick/xgo:go-1.20.x + docker save -o ~/image-cache/xgo.tar techknowlogick/xgo:go-1.20.x + - if: steps.image-cache.outputs.cache-hit == 'true' + run: docker load -i ~/image-cache/xgo.tar + - name: Build + run: | + cd core + go install src.techknowlogick.com/xgo@latest + xgo --targets=darwin/arm64 -ldflags="-w -s" -buildmode=c-shared -out=libclash . + mv libclash-*.dylib libclash.dylib + - uses: actions/upload-artifact@v3 + with: + name: macos-arm64-lib + path: core/libclash.dylib + retention-days: 2 + build-macos: + runs-on: macos-latest + needs: [ get-release, build-macos-arm64-lib ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "^1.20" + - uses: actions/setup-node@v3 + with: + node-version: 16 + - uses: subosito/flutter-action@v2 + with: + flutter-version: '3.10.2' + channel: 'stable' + - name: Install appdmg + run: npm install -g appdmg + - name: Mkdir Frameworks + run: mkdir -p macos/Frameworks + - uses: actions/download-artifact@v3 + with: + name: macos-arm64-lib + path: macos/Frameworks + - name: Build + env: + VERSION: ${{ needs.get-release.outputs.tag_name }} + run: | + PROJECT_DIR=$(pwd) + + dart pub global activate flutter_distributor + + flutter_distributor package --platform=macos --targets=dmg + mv dist/$VERSION/*-macos.dmg dist/$VERSION/macos-arm64.dmg + + cd $PROJECT_DIR/core + go build -ldflags="-w -s" -buildmode=c-shared -o ./dist/libclash.dylib mapleafgo.cn/clash_for_flutter/core + cp -f ./dist/libclash.dylib $PROJECT_DIR/macos/Frameworks/libclash.dylib + cd $PROJECT_DIR + + flutter_distributor package --platform=macos --targets=dmg + mv dist/$VERSION/*-macos.dmg dist/$VERSION/macos-amd64.dmg + + - uses: actions/upload-artifact@v3 + with: + name: macos + path: dist/*/* + retention-days: 2 + - name: Upload + uses: shogo82148/actions-upload-release-asset@v1 + with: + upload_url: ${{ needs.get-release.outputs.upload_url }} + asset_path: dist/*/* + overwrite: true \ No newline at end of file