Skip to content
Snippets Groups Projects
Unverified Commit 0ff80139 authored by Éloïs's avatar Éloïs
Browse files

try to refactor the whole CI

parent 4d3b9b7e
Branches
Tags
No related merge requests found
Pipeline #41111 failed
......@@ -2,22 +2,42 @@
# https://hub.docker.com/r/library/rust/tags/
stages:
- quality
- tests
- build
- release
tests_linux:
fmt_and_clippy:
variables:
CHECK_RUNTIME: gtest
rules:
- if: $CI_COMMIT_REF_NAME =~ /^wip*$/
when: manual
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH == "master"'
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: always
- when: manual
stage: quality
script:
- cargo fmt -- --version
- cargo fmt -- --check
- cargo clippy -- -V
- cargo clippy --features $CHECK_RUNTIME --no-default-features --all --tests -- -D warnings
tests_gtest_linux:
stage: tests
image: rust:buster
image: rust:1.85.1
script:
- cargo test
- cargo test --features gtest --no-default-features
build_linux:
stage: build
image: rust:buster
image: rust:1.85.1
script:
- export RUNTIME=$(echo $CI_COMMIT_TAG | grep -o "gdev\|gtest\|g1" || echo "gdev")
# Build the project for Linux
- cargo build --release
- cargo build --release --features $RUNTIME --no-default-features
# Create completion scripts for different shells
- ./target/release/gcli completion --shell bash > gcli-completion.bash
- ./target/release/gcli completion --shell zsh > gcli-completion.zsh
......@@ -48,12 +68,13 @@ build_linux:
build_linux_arm64:
stage: build
image: rust:buster
image: rust:1.85.1
# Needs the completion scripts built with build_linux
needs:
- job: build_linux
artifacts: true
script:
- export RUNTIME=$(echo $CI_COMMIT_TAG | grep -o "gdev\|gtest\|g1" || echo "gdev")
# Add the arm64 architecture
- dpkg --add-architecture arm64
# Also include libssl-dev necessary for openssl-sys
......@@ -70,7 +91,7 @@ build_linux_arm64:
# Rust toolchain should includes support for the aarch64-unknown-linux-gnu target
- rustup target add aarch64-unknown-linux-gnu
# Build the project for Linux ARM64
- cargo build --release --target aarch64-unknown-linux-gnu
- cargo build --release --target aarch64-unknown-linux-gnu --features $RUNTIME --no-default-features
# Dependency to create Debian package
- cargo install cargo-deb
# Create Debian package
......@@ -93,32 +114,20 @@ build_linux_arm64:
build_macos:
stage: build
image: poka/rust-osxcross:latest
image: joseluisq/rust-linux-darwin-builder:1.85.1
script:
# Install the required dependencies
- export RUNTIME=$(echo $CI_COMMIT_TAG | grep -o "gdev\|gtest\|g1" || echo "gdev")
- rustup target add x86_64-apple-darwin
# Build the project for macOS
- cargo build --release --target x86_64-apple-darwin
# Create the macOS bundle
- rm -rf target/macos
- cargo build --release --target x86_64-apple-darwin --features $RUNTIME --no-default-features
- mkdir -p target/macos
- cargo bundle --release --target x86_64-apple-darwin
# Add Info.plist and install_gcli.scpt
- cd target/x86_64-apple-darwin/release/bundle/osx
- mkdir -p gcli.app/Contents/Resources/Scripts
- cp /opt/Info.plist gcli.app/Contents/Info.plist
- cp /opt/install_gcli.scpt gcli.app/Contents/Resources/Scripts/install_gcli.scpt
- echo -e "Just unzip gcli.app and open it.\nenjoy" > instructions.txt
# Zip the gcli.app before moving it
- zip -r gcli.zip gcli.app instructions.txt
- mv gcli.zip ../../../../macos/ # target/macos/
- tar -czf gcli.tar.gz -C target/x86_64-apple-darwin/release gcli
artifacts:
paths:
- target/macos
- gcli.tar.gz
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- target/macos
- target/
only:
- tags
......@@ -150,7 +159,7 @@ release:
url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/$(cat debian_package_arm64.txt)?job=build_linux_arm64"
link_type: "package"
- name: "gcli v$CI_COMMIT_TAG for macOS"
url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/target/macos/gcli.zip?job=build_macos"
url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/gcli.tar.gz?job=build_macos"
link_type: "package"
# Make the completions scripts available for download
- name: "gcli v$CI_COMMIT_TAG Bash completion"
......@@ -175,3 +184,67 @@ release:
paths:
- debian_package.txt
- debian_package_arm64.txt
generate_homebrew_formula:
stage: release
image: alpine:latest
dependencies:
- build_macos
- release
before_script:
- mkdir -p ~/.ssh
- echo "$HOMEBREW_DEPLOY_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan git.duniter.org >> ~/.ssh/known_hosts
- apk add --no-cache curl git bash
script:
- FORMULA_REPO="https://git.duniter.org/clients/rust/homebrew-duniter-gcli.git"
- FORMULA_BRANCH="main"
- FORMULA_DIR="homebrew-duniter-gcli"
- FORMULA_NAME="duniter-gcli"
- FORMULA_FILE="${FORMULA_NAME}.rb"
- ARTIFACT_URL="https://git.duniter.org/clients/rust/gcli-v2s/-/jobs/artifacts/${CI_COMMIT_TAG}/raw/gcli.tar.gz?job=build_macos"
# Download binary to calculate SHA256
- curl -L "$ARTIFACT_URL" -o gcli.tar.gz
- SHA256=$(shasum -a 256 gcli.tar.gz | awk '{ print $1 }')
# Clone the tap repo (you'll need to set up deploy keys or CI job token access)
- git config --global user.email "ci@gitlab"
- git config --global user.name "GitLab CI"
- git clone "$FORMULA_REPO" "$FORMULA_DIR"
- cd "$FORMULA_DIR"
# Write the formula file
- mkdir -p Formula
- |
cat > formula.rb << 'TEMPLATE'
class GcliV2s < Formula
desc "Duniter command-line interface"
homepage "https://git.duniter.org/clients/rust/homebrew-duniter-gcli"
url "ARTIFACT_URL_PLACEHOLDER"
sha256 "SHA256_PLACEHOLDER"
version "VERSION_PLACEHOLDER"
def install
bin.install "gcli"
end
test do
assert_match "Usage", shell_output("#{bin}/gcli --help")
end
end
TEMPLATE
- sed -i "s|ARTIFACT_URL_PLACEHOLDER|$ARTIFACT_URL|" formula.rb
- sed -i "s|SHA256_PLACEHOLDER|$SHA256|" formula.rb
- sed -i "s|VERSION_PLACEHOLDER|${CI_COMMIT_TAG#v}|" formula.rb
- mv formula.rb Formula/$FORMULA_FILE
# Commit and push the formula
- git checkout -B $FORMULA_BRANCH
- git add Formula/$FORMULA_FILE
- git commit -m "Update formula for version $CI_COMMIT_TAG"
- git push origin $FORMULA_BRANCH
only:
- tags
[toolchain]
channel = "1.88.0"
channel = "1.85.1"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment