diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index df3859f..4587ea3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,8 @@ -name: Tpi tool CI +name: Tpi Validation Pipeline on: [push] jobs: - clippy_check: + + cargo-clippy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -10,18 +11,7 @@ jobs: with: token: '${{ secrets.GITHUB_TOKEN }}' args: '--all-features' - cargo-test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - default: true - profile: minimal - - uses: actions-rs/cargo@v1 - with: - command: test + cargo-deny: runs-on: ubuntu-latest steps: @@ -29,80 +19,43 @@ jobs: - uses: EmbarkStudios/cargo-deny-action@v1 with: command: check bans licenses sources - target-pipeline: - name: "${{ matrix.target }}" - strategy: - matrix: - target: - - aarch64-unknown-linux-gnu - - aarch64-apple-darwin - - x86_64-apple-darwin - - x86_64-pc-windows-msvc - - x86_64-unknown-linux-gnu - include: - - target: x86_64-unknown-linux-gnu - os: ubuntu-22.04 - - target: aarch64-unknown-linux-gnu - os: ubuntu-22.04 - cross: true - - target: aarch64-apple-darwin - os: macos-13 - - target: x86_64-apple-darwin - os: macos-13 - - target: x86_64-pc-windows-msvc - os: windows-2022 - runs-on: '${{ matrix.os }}' + + cargo-test: + runs-on: ubuntu-latest + needs: cargo-deny steps: - uses: actions/checkout@v3 - - name: install toolchain - uses: actions-rs/toolchain@v1 + with: + fetch-depth: 0 + - uses: actions-rs/toolchain@v1 with: toolchain: stable default: true profile: minimal - target: '${{ matrix.target }}' - - name: build - uses: actions-rs/cargo@v1 - with: - command: build - args: '--release --locked --target=${{ matrix.target }}' - use-cross: ${{ matrix.cross }} - - name: archive - uses: actions/upload-artifact@v3 + - uses: actions-rs/cargo@v1 with: - name: 'build output' - path: | - # workaround to prevent a common ancestor in the files, - # this way we can perserve the folder structure. - .github/workflows/build.yml - target/${{ matrix.target }}/release/tpi - target/${{ matrix.target }}/release/tpi.exe - target/${{ matrix.target }}/release/build/*/out/PKGBUILD + command: test + - name: Extract version from Cargo.toml + id: extract_version + run: | + VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/') + echo "VERSION=$VERSION" >> $GITHUB_ENV - archive: - name: ${{ matrix.name }} packager - runs-on: ubuntu-latest - needs: target-pipeline - strategy: - matrix: - name: - - debian - - arch - - windows - - macos - steps: - - uses: actions/checkout@v3 - - uses: actions/download-artifact@v3 - with: - name: 'build output' - - name: running archiver - run: scripts/ci/package.sh ${{ matrix.name }} - - name: archive packages - uses: actions/upload-artifact@v3 - with: - name: '${{ matrix.name }} packages' - path: | - target/debian/* - target/arch/* - target/win/* - target/apple/* + - name: Check if tag exists + id: check_tag + run: | + if git rev-parse --verify v${VERSION} >/dev/null 2>&1; then + echo "TAG_EXISTS=true" >> $GITHUB_ENV + else + echo "TAG_EXISTS=false" >> $GITHUB_ENV + fi + + - name: Create new tag + if: ${{ env.TAG_EXISTS == 'false' }} + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "noreply@turingpi.com" + git tag -a "v${{ env.VERSION }}" -m "Release version ${{ env.VERSION }}" + git push origin "v${{ env.VERSION }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f6cc274 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,98 @@ +name: Release Pipeline +on: + push: + branches: + - 'feature/ci' + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' +jobs: + + build-pipeline: + name: "Build ${{ matrix.target }}" + strategy: + matrix: + target: + - aarch64-unknown-linux-gnu + - aarch64-apple-darwin + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + - x86_64-unknown-linux-gnu + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-22.04 + - target: aarch64-unknown-linux-gnu + os: ubuntu-22.04 + cross: true + - target: aarch64-apple-darwin + os: macos-13 + - target: x86_64-apple-darwin + os: macos-13 + - target: x86_64-pc-windows-msvc + os: windows-2022 + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Install Toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + default: true + profile: minimal + target: ${{ matrix.target }} + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --locked --target=${{ matrix.target }} + use-cross: ${{ matrix.cross }} + + - name: Create Unix Archive + if: ${{ !contains(matrix.target, 'windows') }} + env: + TARGET: ${{ matrix.target }} + srcdir: . + pkgdir: /tmp/pkg + run: | + mkdir -p $pkgdir + . scripts/ci/install + tar -czf tpi-${{ matrix.target }}.tar.gz $pkgdir + + - name: Upload Archive + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }} + path: | + tpi-${{ matrix.target }}.tar.gz + target/${{ matrix.target }}/release/tpi.exe + + debian-packages: + runs-on: ubuntu-latest + needs: build-pipeline + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/download-artifact@v4 + with: + name: x86_64-unknown-linux-gnu + - name: Extract tar.gz file + run: | + mkdir tpi-x86_64-unknown-linux-gnu + tar -xf tpi-x86_64-unknown-linux-gnu.tar.gz -C tpi-x86_64-unknown-linux-gnu + rm -rf tpi-x86_64-unknown-linux-gnu.tar.gz + - name: Create DEBIAN package + run: scripts/ci/create_debian_control.sh Cargo.toml amd64 tpi-x86_64-unknown-linux-gnu + - run: dpkg-deb --build tpi-x86_64-unknown-linux-gnu + - name: Upload Archive + uses: actions/upload-artifact@v4 + with: + name: x86_64-unknown-linux-gnu-deb + path: | + tpi-x86_64-unknown-linux-gnu.deb diff --git a/Cargo.toml b/Cargo.toml index 8683a19..d1b6902 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "tpi" version = "1.0.6" edition = "2021" license = "Apache-2.0" -authors = ["Sven Rademakers ", "Ruslan Akbashev "] +authors = ["Sven Rademakers "] description = "Official Turing-Pi2 CLI tool" homepage = "https://turingpi.com/" repository = "https://github.com/turing-machines/tpi" diff --git a/scripts/ci/create_debian_control.sh b/scripts/ci/create_debian_control.sh new file mode 100755 index 0000000..f38221b --- /dev/null +++ b/scripts/ci/create_debian_control.sh @@ -0,0 +1,45 @@ +# Copyright 2023 Turing Machines +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/bin/bash +toml_file=${1} +arch=${2} +output_dir=${3:-$(pwd)} + +if [ -z "$2" ]; then + echo "missing architecture argument" >&2 + exit -1 +fi + +if [ ! -f "${toml_file}" ]; then + echo "provided toml file: ${toml_file}, does not exist" >&2 + exit -1 +fi + +PACKAGE_NAME=$(grep '^name =' ${toml_file} | sed 's/name = "\(.*\)"/\1/') +VERSION=$(grep '^version =' ${toml_file} | sed 's/version = "\(.*\)"/\1/') +MAINTAINER=$(grep '^authors =' ${toml_file} | sed 's/authors = \[\s*"\(.*\)\s*"\]/\1/') +DESCRIPTION=$(grep '^description =' ${toml_file} | sed 's/description = "\(.*\)"/\1/') + +mkdir -p ${output_dir}/DEBIAN/ +cat < "${output_dir}/DEBIAN/control" +Package: $PACKAGE_NAME +Version: $VERSION +Section: base +Priority: optional +Architecture: ${arch} +Maintainer: $MAINTAINER +Description: $DESCRIPTION +EOL + diff --git a/scripts/ci/install b/scripts/ci/install new file mode 100644 index 0000000..0ea8837 --- /dev/null +++ b/scripts/ci/install @@ -0,0 +1,4 @@ +install -Dm 755 ${srcdir}/target/${TARGET}/release/tpi ${pkgdir}/usr/bin/tpi +install -Dm 644 ${srcdir}/LICENSE ${pkgdir}/usr/share/doc/tpi/copyright +install -Dm 644 ${srcdir}/README.md ${pkgdir}/usr/share/doc/tpi/README.md + diff --git a/scripts/ci/package.sh b/scripts/ci/package.sh deleted file mode 100755 index 1ade8cb..0000000 --- a/scripts/ci/package.sh +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2023 Turing Machines -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#!/bin/bash -set -x - -packager=$1 - -package_win() { - # no packager yet - arch=echo $1|cut -d "-" -f 1 - mkdir -p target/win/$arch - mv target/$1/release/tpi.exe target/win/$arch/ -} - -package_macos() { - # no packager yet - arch=echo $1|cut -d "-" -f 1 - mkdir -p target/apple/$arch - mv target/$1/release/tpi target/apple/$arch/ -} - -package_deb() { - sudo apt-get install -y dpkg-dev - cargo install cargo-deb - cargo-deb --target $1 --no-build --no-strip - - mkdir -p target/debian - mv target/$1/debian/*.deb target/debian/ - pushd target/debian - dpkg-scanpackages -m . > Packages - popd -} - -package_arch() { - mkdir -p target/arch - # PKGBUILD is build using build-script of the tpi crate - cp target/$1/release/build/*/out/PKGBUILD target/arch/ -} - -for target in $(ls target| grep linux) -do - target_name=$(echo $target | cut -d "/" -f 2) - case $packager in - "debian") - package_deb $target_name - ;; - "arch") - package_arch $target_name - ;; - esac -done - -for target in $(ls target| grep windows) -do - target_name=$(echo $target | cut -d "/" -f 2) - case $packager in - "windows") - package_win $target_name - ;; - esac -done - -for target in $(ls target| grep apple) -do - target_name=$(echo $target | cut -d "/" -f 2) - case $packager in - "macos") - package_macos $target_name - ;; - esac -done -