From db73ac48db9a47da9fb3643ad197c086f2bd3c7e Mon Sep 17 00:00:00 2001 From: amtoaer Date: Fri, 12 Apr 2024 19:35:09 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E5=8A=A0=E5=85=A5=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E3=80=81=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E3=80=81=E5=8F=91=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/check.yaml | 43 +++++ .github/workflows/release.yaml | 129 +++++++++++++++ Cargo.lock | 281 ++++++++++++++------------------- Cargo.toml | 9 +- Dockerfile | 40 +++++ migration/Cargo.toml | 4 +- 6 files changed, 342 insertions(+), 164 deletions(-) create mode 100644 .github/workflows/check.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..e007f46 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,43 @@ +name: Check + +on: + push: + branches: + - main + pull_request: + branches: + - "**" + +concurrency: + # Allow only one workflow per any non-`main` branch. + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: 0 + RUST_BACKTRACE: 1 + +jobs: + tests: + name: Run Clippy and tests + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - run: rustup toolchain install nightly --profile minimal + + - name: Cache dependencies + uses: swatinem/rust-cache@v2 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} + + - name: cargo fmt check + run: cargo fmt --check + + - name: cargo clippy + run: cargo clippy + + - name: cargo test + run: cargo test diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..617850b --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,129 @@ +name: Build Binary And Release + +on: + push: + tags: + - v* + +jobs: + build: + name: Release for ${{ matrix.platform.release_for }} + runs-on: ${{ matrix.platform.os }} + strategy: + matrix: + platform: + - release_for: Linux-x86_64 + os: ubuntu-20.04 + target: x86_64-unknown-linux-musl + bin: bili-sync-rs + name: bili-sync-rs-Linux-x86_64-musl.tar.gz + - release_for: Linux-aarch64 + os: ubuntu-20.04 + target: aarch64-unknown-linux-musl + bin: bili-sync-rs + name: bili-sync-rs-Linux-aarch64-musl.tar.gz + - release_for: macOS-x86_64 + os: macOS-latest + target: x86_64-apple-darwin + bin: bili-sync-rs + name: bili-sync-rs-Darwin-x86_64.tar.gz + - release_for: macOS-aarch64 + os: macOS-latest + target: aarch64-apple-darwin + bin: bili-sync-rs + name: bili-sync-rs-Darwin-aarch64.tar.gz + - release_for: Windows-x86_64 + os: windows-latest + target: x86_64-pc-windows-msvc + bin: bili-sync-rs.exe + name: bili-sync-rs-Windows-x86_64.zip + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + - name: Install musl-tools + run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools + if: contains(matrix.platform.target, 'musl') + - name: Build binary + uses: houseabsolute/actions-rust-cross@v0 + with: + command: build + target: ${{ matrix.platform.target }} + toolchain: stable + args: "--locked --release" + strip: true + - name: Package as archive + shell: bash + run: | + cp target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} ${{ matrix.platform.release_for }}-${{ matrix.platform.bin }} + cd target/${{ matrix.platform.target }}/release + if [[ "${{ matrix.platform.target }}" == "x86_64-pc-windows-msvc" ]]; then + 7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} + else + tar czvf ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} + fi + - name: Upload release artifact + uses: actions/upload-artifact@v4 + with: + name: bili-sync-rs-${{ matrix.platform.release_for }} + # contains raw binary and compressed archive + path: | + ${{ github.workspace }}/${{ matrix.platform.release_for }}-${{ matrix.platform.bin }} + ${{ github.workspace }}/${{ matrix.platform.name }} + release: + name: Create GitHub Release & Docker Image + needs: build + runs-on: ubuntu-20.04 + permissions: + contents: write + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Download release artifact + uses: actions/download-artifact@v4 + with: + merge-multiple: true + - name: Publish GitHub release + uses: softprops/action-gh-release@v2 + with: + files: bili-sync-rs* + tag_name: ${{ github.ref_name }} + draft: true + - name: Docker Meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/bili-sync-rs + tags: | + type=raw,value=latest + type=raw,value=${{ github.ref_name }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + platforms: | + linux/amd64 + linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} + - name: Update DockerHub description + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ secrets.DOCKERHUB_USERNAME }}/bili-sync-rs diff --git a/Cargo.lock b/Cargo.lock index fc41130..8966ccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -411,7 +411,7 @@ dependencies = [ ] [[package]] -name = "bili-sync" +name = "bili-sync-rs" version = "2.0.0" dependencies = [ "anyhow", @@ -694,16 +694,6 @@ dependencies = [ "url", ] -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -850,9 +840,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if", ] @@ -1027,21 +1017,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1412,18 +1387,19 @@ dependencies = [ ] [[package]] -name = "hyper-tls" -version = "0.6.0" +name = "hyper-rustls" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" dependencies = [ - "bytes", - "http-body-util", + "futures-util", + "http", "hyper", "hyper-util", - "native-tls", + "rustls 0.22.3", + "rustls-pki-types", "tokio", - "tokio-native-tls", + "tokio-rustls", "tower-service", ] @@ -1717,24 +1693,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nom" version = "7.1.3" @@ -1834,50 +1792,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" -dependencies = [ - "bitflags 2.5.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -2373,24 +2287,24 @@ dependencies = [ "http-body", "http-body-util", "hyper", - "hyper-tls", + "hyper-rustls", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "rustls 0.22.3", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls", "tokio-util", "tower-service", "url", @@ -2398,9 +2312,25 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", + "webpki-roots 0.26.1", "winreg", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rkyv" version = "0.7.44" @@ -2500,6 +2430,31 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.21.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +dependencies = [ + "ring", + "rustls-webpki 0.101.7", + "sct", +] + +[[package]] +name = "rustls" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99008d7ad0bbbea527ec27bddbc0e432c5b87d8175178cee68d2eec9c4a1813c" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki 0.102.2", + "subtle", + "zeroize", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -2509,6 +2464,33 @@ dependencies = [ "base64", ] +[[package]] +name = "rustls-pki-types" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustls-webpki" +version = "0.102.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -2521,21 +2503,22 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "sea-bae" version = "0.2.0" @@ -2701,29 +2684,6 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" -[[package]] -name = "security-framework" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.197" @@ -2942,11 +2902,12 @@ dependencies = [ "indexmap", "log", "memchr", - "native-tls", "once_cell", "paste", "percent-encoding", "rust_decimal", + "rustls 0.21.10", + "rustls-pemfile", "serde", "serde_json", "sha2", @@ -2959,6 +2920,7 @@ dependencies = [ "tracing", "url", "uuid", + "webpki-roots 0.25.4", ] [[package]] @@ -3214,27 +3176,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "tap" version = "1.0.1" @@ -3360,12 +3301,13 @@ dependencies = [ ] [[package]] -name = "tokio-native-tls" -version = "0.3.1" +name = "tokio-rustls" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ - "native-tls", + "rustls 0.22.3", + "rustls-pki-types", "tokio", ] @@ -3565,6 +3507,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" @@ -3731,6 +3679,21 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "webpki-roots" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "whoami" version = "1.5.1" diff --git a/Cargo.toml b/Cargo.toml index 0cc8a46..d22c70f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "bili-sync" +name = "bili-sync-rs" version = "2.0.0" edition = "2021" @@ -30,11 +30,14 @@ reqwest = { version = "0.12.0", features = [ "stream", "cookies", "gzip", -] } + "charset", + "http2", + "rustls-tls", +], default-features = false } rsa = { version = "0.9.6", features = ["sha2"] } sea-orm = { version = "0.12", features = [ "sqlx-sqlite", - "runtime-tokio-native-tls", + "runtime-tokio-rustls", "macros", ] } serde = { version = "1.0.197", features = ["derive"] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b314c0a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM alpine as base + +ARG TARGETPLATFORM + +WORKDIR /app + +COPY ./*-bili-sync-rs ./targets/ + +RUN apk update && apk add --no-cache \ + ca-certificates \ + tzdata \ + ffmpeg \ + && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone \ + && apk del tzdata + +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + mv ./targets/Linux-x86_64-bili-sync-rs ./bili-sync-rs; \ + else \ + mv ./targets/Linux-aarch64-bili-sync-rs ./bili-sync-rs; \ + fi + +RUN rm -rf ./targets && chmod +x ./bili-sync-rs + +FROM scratch + +WORKDIR /app + +ENV LANG=zh_CN.UTF-8 \ + TZ=Asia/Shanghai \ + HOME=/app \ + RUST_BACKTRACE=1 \ + RUST_LOG=None,bili_sync=info + +COPY --from=base / / + +ENTRYPOINT [ "/app/bili-sync-rs" ] + +VOLUME [ "/app/.config/bili-sync" ] + diff --git a/migration/Cargo.toml b/migration/Cargo.toml index a885684..f7455b7 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -17,6 +17,6 @@ features = [ # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime. # e.g. - "runtime-tokio-native-tls", # `ASYNC_RUNTIME` feature - "sqlx-sqlite", # `DATABASE_DRIVER` feature + # "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature + # "sqlx-sqlite", # `DATABASE_DRIVER` feature ]