From cb79db416ad5abc9277cce794ac3a8548686dd67 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 19 Jan 2022 21:03:05 +0800 Subject: [PATCH] Build deb and rpm packages --- .github/workflows/Release.yml | 62 +++++++++++++++++++++++++++++++---- Cargo.toml | 20 +++++++++++ systemd.service | 13 ++++++++ 3 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 systemd.service diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index c97e05644b..0a843ce1d0 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -142,13 +142,13 @@ jobs: strategy: matrix: platform: [ - { target: "x86_64-unknown-linux-musl", image_tag: "x86_64-musl", wheel: true }, - { target: "i686-unknown-linux-musl", image_tag: "i686-musl", wheel: true }, - { target: "aarch64-unknown-linux-musl", image_tag: "aarch64-musl", wheel: true }, - { target: "armv7-unknown-linux-musleabihf", image_tag: "armv7-musleabihf", wheel: true }, - { target: "armv7-unknown-linux-musleabi", image_tag: "armv7-musleabi", wheel: false }, - { target: "arm-unknown-linux-musleabihf", image_tag: "arm-musleabihf", wheel: false }, - { target: "arm-unknown-linux-musleabi", image_tag: "arm-musleabi", wheel: false }, + { target: "x86_64-unknown-linux-musl", image_tag: "x86_64-musl", wheel: true, deb: true }, + { target: "i686-unknown-linux-musl", image_tag: "i686-musl", wheel: true, deb: true }, + { target: "aarch64-unknown-linux-musl", image_tag: "aarch64-musl", wheel: true, deb: true }, + { target: "armv7-unknown-linux-musleabihf", image_tag: "armv7-musleabihf", wheel: true, deb: true }, + { target: "armv7-unknown-linux-musleabi", image_tag: "armv7-musleabi", wheel: false, deb: true }, + { target: "arm-unknown-linux-musleabihf", image_tag: "arm-musleabihf", wheel: false, deb: false }, + { target: "arm-unknown-linux-musleabi", image_tag: "arm-musleabi", wheel: false, deb: false }, ] container: image: docker://messense/rust-musl-cross:${{ matrix.platform.image_tag }} @@ -175,6 +175,17 @@ jobs: manylinux: musllinux_1_1 container: off args: --release --out dist --no-sdist --strip + - name: Install cargo packages + if: matrix.platform.deb + run: | + which cargo-deb > /dev/null || cargo install --target `rustc -vV | grep host: | awk '{print $2}'` cargo-deb + which cargo-generate-rpm > /dev/null || cargo install --target `rustc -vV | grep host: | awk '{print $2}'` cargo-generate-rpm + - name: Build Debian package + if: matrix.platform.deb + run: cargo deb --target=${{ matrix.platform.target }} --no-build --no-strip + - name: Build RPM package + if: matrix.platform.deb + run: cargo generate-rpm --target=${{ matrix.platform.target }} --payload-compress none - name: Upload wheels if: matrix.platform.wheel uses: actions/upload-artifact@v2 @@ -193,6 +204,20 @@ jobs: name: ${{ matrix.platform.target }}-bin path: target/${{ matrix.platform.target }}/release/aliyundrive-webdav if-no-files-found: error + - name: Upload deb artifacts + if: matrix.platform.deb + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.platform.target }}-deb + path: target/${{ matrix.platform.target }}/debian/aliyundrive-webdav_*.deb + if-no-files-found: error + - name: Upload RPM artifacts + if: matrix.platform.deb + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.platform.target }}-rpm + path: target/${{ matrix.platform.target }}/generate-rpm/aliyundrive-webdav*.rpm + if-no-files-found: error - name: Get tag if: "startsWith(github.ref, 'refs/tags/')" id: tag @@ -213,6 +238,29 @@ jobs: file_glob: true overwrite: true tag: ${{ github.ref }} + - name: Upload deb to GitHub Release + uses: svenstaro/upload-release-action@v2 + if: "startsWith(github.ref, 'refs/tags/') && matrix.platform.deb" + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/${{ matrix.platform.target }}/debian/aliyundrive-webdav_*.deb + file_glob: true + overwrite: true + tag: ${{ github.ref }} + - name: Upload RPM to GitHub Release + uses: svenstaro/upload-release-action@v2 + if: "startsWith(github.ref, 'refs/tags/') && matrix.platform.deb" + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/${{ matrix.platform.target }}/generate-rpm/aliyundrive-webdav*.rpm + file_glob: true + overwrite: true + tag: ${{ github.ref }} + - name: Remove cached deb and RPM packages + if: matrix.platform.deb + run: | + rm -rf target/${{ matrix.platform.target }}/debian + rm -rf target/${{ matrix.platform.target }}/generate-rpm linux-others: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 178d094d08..f20a28d838 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,3 +44,23 @@ atomic64 = ["moka/atomic64"] [profile.release] lto = true opt-level = "z" # Optimize for size + +[package.metadata.deb] +maintainer = "messense " +copyright = "2021-present, messense " +license-file = ["LICENSE", "4"] +extended-description = """\ +WebDAV server for AliyunDrive""" +section = "utility" +priority = "optional" +assets = [ + ["target/release/aliyundrive-webdav", "usr/bin/", "755"], + ["systemd.service", "etc/systemd/system/aliyundrive-webdav.service", "644"], +] + +[package.metadata.generate-rpm] +assets = [ + { source = "target/release/aliyundrive-webdav", dest = "/usr/bin/aliyundrive-webdav", mode = "0755" }, + { source = "LICENSE", dest = "/usr/share/doc/aliyundrive-webdav/LICENSE", doc = true, mode = "0644" }, + { source = "systemd.service", dest = "/etc/systemd/system/aliyundrive-webdav.service", config = true, mode = "0644" }, +] \ No newline at end of file diff --git a/systemd.service b/systemd.service new file mode 100644 index 0000000000..a9b8d73dd5 --- /dev/null +++ b/systemd.service @@ -0,0 +1,13 @@ +[Unit] +Description=AliyunDrive WebDAV +After=network.target + +[Service] +Type=simple +Environment="REFRESH_TOKEN=" +ExecStart=/usr/bin/aliyundrive-webdav --auto-index -w /etc/aliyundrive-webdav +KillMode=process +Restart=on-failure + +[Install] +WantedBy=multi-user.target