From fec064a1ef0517b7107730581c47dd132f09de45 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Sun, 2 May 2021 03:19:22 +0530 Subject: [PATCH] Rework release script (#199) --- .github/workflows/build.yml | 100 +++++++++++++++++++++++ .github/workflows/ci.yml | 2 - .github/workflows/release.yml | 148 ---------------------------------- 3 files changed, 100 insertions(+), 150 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..fabc89d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,100 @@ +name: build +on: + push: + branches: + - main + pull_request: +jobs: + build: + name: build + runs-on: ${{ matrix.os }} + strategy: + matrix: + target: + - aarch64-pc-windows-msvc + - aarch64-unknown-linux-musl + - armv7-unknown-linux-musleabihf + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + - x86_64-unknown-linux-musl + include: + - target: aarch64-pc-windows-msvc + os: windows-latest + use-cross: false + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + use-cross: true + - target: armv7-unknown-linux-musleabihf + os: ubuntu-latest + use-cross: true + - target: x86_64-apple-darwin + os: macos-latest + use-cross: false + - target: x86_64-pc-windows-msvc + os: windows-latest + use-cross: false + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + use-cross: true + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + target: ${{ matrix.target }} + - name: Build binary + uses: actions-rs/cargo@v1 + with: + command: build + args: --color=always --release --target=${{ matrix.target }} + use-cross: ${{ matrix.use-cross }} + - name: Build archive + shell: bash + run: | + # Build archive + tmpdir="zoxide-${{ matrix.target }}" + mkdir "$tmpdir/" + cp -r {man,CHANGELOG.md,LICENSE,README.md} "$tmpdir/" + if [ "${{ matrix.target }}" = *"windows"* ]; then + asset="$tmpdir.zip" + cp "target/${{ matrix.target }}/release/zoxide.exe" "$tmpdir/" + 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$asset" "$tmpdir/" + else + asset="$tmpdir.tar.gz" + cp "target/${{ matrix.target }}/release/zoxide" "$tmpdir/" + tar -cv "$tmpdir/" | gzip --best > "$asset" + fi + echo "ASSET=$asset" >> $GITHUB_ENV + - name: Upload archive + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ASSET }} + path: ${{ env.ASSET }} + release: + if: ${{ startsWith(github.ref, 'refs/tags/') }} + runs-on: ubuntu-latest + needs: [build] + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Download archives + uses: actions/download-artifact@v2 + with: + path: artifact + - name: Show downloaded files + run: ls -lRh artifact/ + - name: Create release + uses: softprops/action-gh-release@v1 + with: + draft: true + files: artifact/*/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dc755a..b3598fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,9 @@ name: ci - on: push: branches: - main pull_request: - jobs: ci: runs-on: ${{ matrix.os }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index d774741..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,148 +0,0 @@ -on: - push: - tags: - - "v*" - -jobs: - build-linux: - runs-on: ubuntu-latest - strategy: - matrix: - target: - - "aarch64-unknown-linux-gnu" - - "aarch64-unknown-linux-musl" - - "armv7-unknown-linux-gnueabihf" - - "armv7-unknown-linux-musleabihf" - - "x86_64-unknown-linux-gnu" - - "x86_64-unknown-linux-musl" - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --release --target ${{ matrix.target }} - - uses: actions/upload-artifact@v2 - with: - name: "zoxide-${{ matrix.target }}" - path: "target/${{ matrix.target }}/release/zoxide" - - build-darwin: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --target x86_64-apple-darwin - - uses: actions/upload-artifact@v2 - with: - name: "zoxide-x86_64-apple-darwin" - path: "target/x86_64-apple-darwin/release/zoxide" - - build-windows: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --target x86_64-pc-windows-msvc - - uses: actions/upload-artifact@v2 - with: - name: "zoxide-x86_64-pc-windows-msvc" - path: "target/x86_64-pc-windows-msvc/release/zoxide.exe" - - release-upload: - needs: - - build-linux - - build-darwin - - build-windows - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - - - uses: actions/download-artifact@v2 - - - name: Display structure of downloaded files - run: ls -lR - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-aarch64-unknown-linux-gnu/zoxide" - asset_name: "zoxide-aarch64-unknown-linux-gnu" - asset_content_type: application/octet-stream - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-aarch64-unknown-linux-musl/zoxide" - asset_name: "zoxide-aarch64-unknown-linux-musl" - asset_content_type: application/octet-stream - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-armv7-unknown-linux-gnueabihf/zoxide" - asset_name: "zoxide-armv7-unknown-linux-gnueabihf" - asset_content_type: application/octet-stream - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-armv7-unknown-linux-musleabihf/zoxide" - asset_name: "zoxide-armv7-unknown-linux-musleabihf" - asset_content_type: application/octet-stream - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-x86_64-unknown-linux-gnu/zoxide" - asset_name: "zoxide-x86_64-unknown-linux-gnu" - asset_content_type: application/octet-stream - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-x86_64-unknown-linux-musl/zoxide" - asset_name: "zoxide-x86_64-unknown-linux-musl" - asset_content_type: application/octet-stream - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-x86_64-apple-darwin/zoxide" - asset_name: "zoxide-x86_64-apple-darwin" - asset_content_type: application/octet-stream - - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: "zoxide-x86_64-pc-windows-msvc/zoxide.exe" - asset_name: "zoxide-x86_64-pc-windows-msvc.exe" - asset_content_type: application/octet-stream