Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release pipeline rework #32

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .github/workflows/auto_tagger.yml

This file was deleted.

119 changes: 36 additions & 83 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,99 +11,51 @@ 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:
- uses: actions/checkout@v3
- 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 "[email protected]"
git tag -a "v${{ env.VERSION }}" -m "Release version ${{ env.VERSION }}"
git push origin "v${{ env.VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148 changes: 148 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Release Pipeline
on:
push:
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}
source scripts/ci/install
tar -czf tpi-${{ matrix.target }}.tar.gz -C ${pkgdir} .

- name: Upload Archive
uses: actions/upload-artifact@v4
if: ${{ !contains(matrix.target, 'windows') }}
with:
name: ${{ matrix.target }}
path: |
tpi-${{ matrix.target }}.tar.gz

- name: Upload Archive (Win)
uses: actions/upload-artifact@v4
if: ${{ contains(matrix.target, 'windows') }}
with:
name: ${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/tpi.exe

debian-packages:
runs-on: ubuntu-latest
needs: build-pipeline
strategy:
matrix:
target:
- aarch64
- x86_64
include:
- target: x86_64
arch: amd64
- target: aarch64
arch: arm64
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/download-artifact@v4
with:
name: ${{ matrix.target }}-unknown-linux-gnu

- name: Extract version from Cargo.toml
run: |
VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "PKG_NAME=tpi-$VERSION-${{ matrix.target }}-linux" >> $GITHUB_ENV

- name: Extract tar.gz file
run: |
mkdir ${{ env.PKG_NAME }}
tar -xf tpi-${{ matrix.target }}-unknown-linux-gnu.tar.gz -C ${{ env.PKG_NAME }}

- name: Create DEBIAN package
run: scripts/ci/create_debian_control.sh Cargo.toml ${{ matrix.arch }} ${{ env.PKG_NAME }}

- run: dpkg-deb --build ${{ env.PKG_NAME }}

- name: Upload Archive
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG_NAME }}.deb
path: ${{ env.PKG_NAME }}.deb

create_release:
needs: debian-packages
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Extract version from Cargo.toml
run: |
VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true

- name: Release
uses: ncipollo/release-action@v1
with:
name: tpi v${{ env.VERSION }}
tag: ${{ env.VERSION }}
artifacts: artifacts/*
generateReleaseNotes: true
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tpi"
version = "1.0.6"
edition = "2021"
license = "Apache-2.0"
authors = ["Sven Rademakers <[email protected]>", "Ruslan Akbashev <[email protected]>"]
authors = ["Sven Rademakers <[email protected]>"]
description = "Official Turing-Pi2 CLI tool"
homepage = "https://turingpi.com/"
repository = "https://github.com/turing-machines/tpi"
Expand Down Expand Up @@ -35,3 +35,7 @@ url = "2.5.2"
default = ["reqwest/rustls-tls"]
native-tls = ["reqwest/native-tls"]
localhost = []

[profile.release]
lto = true
strip = true
45 changes: 45 additions & 0 deletions scripts/ci/create_debian_control.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOL > "${output_dir}/DEBIAN/control"
Package: $PACKAGE_NAME
Version: $VERSION
Section: base
Priority: optional
Architecture: ${arch}
Maintainer: $MAINTAINER
Description: $DESCRIPTION
EOL

Loading
Loading