Skip to content

Commit df097cb

Browse files
WIP
1 parent f9a5d58 commit df097cb

File tree

6 files changed

+204
-168
lines changed

6 files changed

+204
-168
lines changed

.github/workflows/build.yml

+36-83
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
name: Tpi tool CI
1+
name: Tpi Validation Pipeline
22
on: [push]
33
jobs:
4-
clippy_check:
4+
5+
cargo-clippy:
56
runs-on: ubuntu-latest
67
steps:
78
- uses: actions/checkout@v3
@@ -10,99 +11,51 @@ jobs:
1011
with:
1112
token: '${{ secrets.GITHUB_TOKEN }}'
1213
args: '--all-features'
13-
cargo-test:
14-
runs-on: ubuntu-latest
15-
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions-rs/toolchain@v1
18-
with:
19-
toolchain: stable
20-
default: true
21-
profile: minimal
22-
- uses: actions-rs/cargo@v1
23-
with:
24-
command: test
14+
2515
cargo-deny:
2616
runs-on: ubuntu-latest
2717
steps:
2818
- uses: actions/checkout@v3
2919
- uses: EmbarkStudios/cargo-deny-action@v1
3020
with:
3121
command: check bans licenses sources
32-
target-pipeline:
33-
name: "${{ matrix.target }}"
34-
strategy:
35-
matrix:
36-
target:
37-
- aarch64-unknown-linux-gnu
38-
- aarch64-apple-darwin
39-
- x86_64-apple-darwin
40-
- x86_64-pc-windows-msvc
41-
- x86_64-unknown-linux-gnu
42-
include:
43-
- target: x86_64-unknown-linux-gnu
44-
os: ubuntu-22.04
45-
- target: aarch64-unknown-linux-gnu
46-
os: ubuntu-22.04
47-
cross: true
48-
- target: aarch64-apple-darwin
49-
os: macos-13
50-
- target: x86_64-apple-darwin
51-
os: macos-13
52-
- target: x86_64-pc-windows-msvc
53-
os: windows-2022
54-
runs-on: '${{ matrix.os }}'
22+
23+
cargo-test:
24+
runs-on: ubuntu-latest
25+
needs: cargo-deny
5526
steps:
5627
- uses: actions/checkout@v3
57-
- name: install toolchain
58-
uses: actions-rs/toolchain@v1
28+
with:
29+
fetch-depth: 0
30+
- uses: actions-rs/toolchain@v1
5931
with:
6032
toolchain: stable
6133
default: true
6234
profile: minimal
63-
target: '${{ matrix.target }}'
64-
- name: build
65-
uses: actions-rs/cargo@v1
66-
with:
67-
command: build
68-
args: '--release --locked --target=${{ matrix.target }}'
69-
use-cross: ${{ matrix.cross }}
70-
- name: archive
71-
uses: actions/upload-artifact@v3
35+
- uses: actions-rs/cargo@v1
7236
with:
73-
name: 'build output'
74-
path: |
75-
# workaround to prevent a common ancestor in the files,
76-
# this way we can perserve the folder structure.
77-
.github/workflows/build.yml
78-
target/${{ matrix.target }}/release/tpi
79-
target/${{ matrix.target }}/release/tpi.exe
80-
target/${{ matrix.target }}/release/build/*/out/PKGBUILD
37+
command: test
38+
- name: Extract version from Cargo.toml
39+
id: extract_version
40+
run: |
41+
VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
42+
echo "VERSION=$VERSION" >> $GITHUB_ENV
8143
82-
archive:
83-
name: ${{ matrix.name }} packager
84-
runs-on: ubuntu-latest
85-
needs: target-pipeline
86-
strategy:
87-
matrix:
88-
name:
89-
- debian
90-
- arch
91-
- windows
92-
- macos
93-
steps:
94-
- uses: actions/checkout@v3
95-
- uses: actions/download-artifact@v3
96-
with:
97-
name: 'build output'
98-
- name: running archiver
99-
run: scripts/ci/package.sh ${{ matrix.name }}
100-
- name: archive packages
101-
uses: actions/upload-artifact@v3
102-
with:
103-
name: '${{ matrix.name }} packages'
104-
path: |
105-
target/debian/*
106-
target/arch/*
107-
target/win/*
108-
target/apple/*
44+
- name: Check if tag exists
45+
id: check_tag
46+
run: |
47+
if git rev-parse --verify v${VERSION} >/dev/null 2>&1; then
48+
echo "TAG_EXISTS=true" >> $GITHUB_ENV
49+
else
50+
echo "TAG_EXISTS=false" >> $GITHUB_ENV
51+
fi
52+
53+
- name: Create new tag
54+
if: ${{ env.TAG_EXISTS == 'false' }}
55+
run: |
56+
git config --global user.name "${{ github.actor }}"
57+
git config --global user.email "noreply@turingpi.com"
58+
git tag -a "v${{ env.VERSION }}" -m "Release version ${{ env.VERSION }}"
59+
git push origin "v${{ env.VERSION }}"
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Release Pipeline
2+
on:
3+
push:
4+
branches:
5+
- 'feature/ci'
6+
tags:
7+
- 'v[0-9]+.[0-9]+.[0-9]+'
8+
jobs:
9+
10+
build-pipeline:
11+
name: "Build ${{ matrix.target }}"
12+
strategy:
13+
matrix:
14+
target:
15+
- aarch64-unknown-linux-gnu
16+
- aarch64-apple-darwin
17+
- x86_64-apple-darwin
18+
- x86_64-pc-windows-msvc
19+
- x86_64-unknown-linux-gnu
20+
include:
21+
- target: x86_64-unknown-linux-gnu
22+
os: ubuntu-22.04
23+
- target: aarch64-unknown-linux-gnu
24+
os: ubuntu-22.04
25+
cross: true
26+
- target: aarch64-apple-darwin
27+
os: macos-13
28+
- target: x86_64-apple-darwin
29+
os: macos-13
30+
- target: x86_64-pc-windows-msvc
31+
os: windows-2022
32+
33+
runs-on: ${{ matrix.os }}
34+
steps:
35+
- name: Checkout Code
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 1
39+
40+
- name: Install Toolchain
41+
uses: actions-rs/toolchain@v1
42+
with:
43+
toolchain: stable
44+
default: true
45+
profile: minimal
46+
target: ${{ matrix.target }}
47+
48+
- name: Build
49+
uses: actions-rs/cargo@v1
50+
with:
51+
command: build
52+
args: --release --locked --target=${{ matrix.target }}
53+
use-cross: ${{ matrix.cross }}
54+
55+
- name: Create Unix Archive
56+
if: ${{ !contains(matrix.target, 'windows') }}
57+
env:
58+
TARGET: ${{ matrix.target }}
59+
srcdir: .
60+
pkgdir: /tmp/pkg
61+
run: |
62+
mkdir -p ${pkgdir}
63+
source scripts/ci/install
64+
cd ${pkgdir} && tar -czf tpi-${{ matrix.target }}.tar.gz .
65+
66+
- name: Upload Archive
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: ${{ matrix.target }}
70+
path: |
71+
tpi-${{ matrix.target }}.tar.gz
72+
target/${{ matrix.target }}/release/tpi.exe
73+
74+
debian-packages:
75+
runs-on: ubuntu-latest
76+
needs: build-pipeline
77+
strategy:
78+
matrix:
79+
target:
80+
- aarch64
81+
- x86_64
82+
include:
83+
- target: x86_64
84+
arch: amd64
85+
- target: aarch64
86+
arch: arm64
87+
steps:
88+
- name: Checkout Code
89+
uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 0
92+
- uses: actions/download-artifact@v4
93+
with:
94+
name: ${{ matrix.target }}-unknown-linux-gnu
95+
- name: Extract version from Cargo.toml
96+
id: extract_version
97+
run: |
98+
VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
99+
echo "VERSION=$VERSION" >> $GITHUB_ENV
100+
echo "PKG_NAME=tpi-${{ matrix.target }}-linux-$VERSION" >> $GITHUB_ENV
101+
- name: Extract tar.gz file
102+
run: |
103+
mkdir ${{ env.PKG_NAME }}
104+
tar -xf tpi-${{ matrix.target }}-unknown-linux-gnu.tar.gz -C ${{ env.PKG_NAME }}
105+
- name: Create DEBIAN package
106+
run: scripts/ci/create_debian_control.sh Cargo.toml ${{ matrix.arch }} ${{ env.PKG_NAME }}
107+
- run: dpkg-deb --build ${{ env.PKG_NAME }}
108+
- name: Upload Archive
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: ${{ env.PKG_NAME }}-deb
112+
path: ${{ env.PKG_NAME }}.deb

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "tpi"
33
version = "1.0.6"
44
edition = "2021"
55
license = "Apache-2.0"
6-
authors = ["Sven Rademakers <sven@turingpi.com>", "Ruslan Akbashev <ra@turingpi.com>"]
6+
authors = ["Sven Rademakers <sven@turingpi.com>"]
77
description = "Official Turing-Pi2 CLI tool"
88
homepage = "https://turingpi.com/"
99
repository = "https://github.com/turing-machines/tpi"
@@ -35,3 +35,7 @@ url = "2.5.2"
3535
default = ["reqwest/rustls-tls"]
3636
native-tls = ["reqwest/native-tls"]
3737
localhost = []
38+
39+
[profile.release]
40+
lto = true
41+
strip = true

scripts/ci/create_debian_control.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2023 Turing Machines
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
toml_file=${1}
17+
arch=${2}
18+
output_dir=${3:-$(pwd)}
19+
20+
if [ -z "$2" ]; then
21+
echo "missing architecture argument" >&2
22+
exit -1
23+
fi
24+
25+
if [ ! -f "${toml_file}" ]; then
26+
echo "provided toml file: ${toml_file}, does not exist" >&2
27+
exit -1
28+
fi
29+
30+
PACKAGE_NAME=$(grep '^name =' ${toml_file} | sed 's/name = "\(.*\)"/\1/')
31+
VERSION=$(grep '^version =' ${toml_file} | sed 's/version = "\(.*\)"/\1/')
32+
MAINTAINER=$(grep '^authors =' ${toml_file} | sed 's/authors = \[\s*"\(.*\)\s*"\]/\1/')
33+
DESCRIPTION=$(grep '^description =' ${toml_file} | sed 's/description = "\(.*\)"/\1/')
34+
35+
mkdir -p ${output_dir}/DEBIAN/
36+
cat <<EOL > "${output_dir}/DEBIAN/control"
37+
Package: $PACKAGE_NAME
38+
Version: $VERSION
39+
Section: base
40+
Priority: optional
41+
Architecture: ${arch}
42+
Maintainer: $MAINTAINER
43+
Description: $DESCRIPTION
44+
EOL
45+

scripts/ci/install

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mkdir -p ${pkgdir}/usr/bin
2+
mkdir -p ${pkgdir}/usr/share/doc/tpi
3+
install -m 755 ${srcdir}/target/${TARGET}/release/tpi ${pkgdir}/usr/bin/tpi
4+
install -m 644 ${srcdir}/LICENSE ${pkgdir}/usr/share/doc/tpi/copyright
5+
install -m 644 ${srcdir}/README.md ${pkgdir}/usr/share/doc/tpi/README.md
6+

0 commit comments

Comments
 (0)