Skip to content
Snippets Groups Projects
Commit bdd8aac9 authored by poka's avatar poka Committed by Hugo Trentesaux
Browse files

Add publish command (clients/rust/gcli-v2s!19)

* {version}

* fix hugo review again

* fix license in toml

* more readable

* fix hugo review

* a bit more compact

* add latest git commits in description

* add vit proposition to publish artefact without gitlab API

But I wanna keep my bunty for sure, it's mine.

* add merges in release descriptions since MR are squashed ny default

* add publish command to push git tag with actual version

* add latest commit to the release description
parent 76a19ff9
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# stop script if any command fails
set -e
# Vérifiez si le token d'accès privé GitLab est défini
if [ -z "$GITLAB_PRIVATE_TOKEN" ]; then
echo "Token d'accès privé GitLab non défini. Arrêt du script."
exit 1
fi
if [ -z "$CI_COMMIT_TAG" ]; then
echo "This script should only be run on a tag."
exit 1
fi
# Variables
PROJECT_ID="604"
RELEASE_NAME="v$CI_COMMIT_TAG"
RELEASE_DESCRIPTION="Release v$CI_COMMIT_TAG is awesome !"
ARTIFACT_PATH="target/release/gcli"
GITLAB_API_URL="https://git.duniter.org/api/v4"
# Création de la release
echo "Création de la release $RELEASE_NAME..."
curl --header "PRIVATE-TOKEN: $GITLAB_PRIVATE_TOKEN" \
--data "name=$RELEASE_NAME&tag_name=$CI_COMMIT_TAG&description=$RELEASE_DESCRIPTION" \
"$GITLAB_API_URL/projects/$PROJECT_ID/releases"
# Construction de l'URL de l'artéfact
ARTIFACT_URL="$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/$ARTIFACT_PATH?job=build"
# Ajout de l'artéfact à la release
echo "Ajout de l'artéfact à la release..."
curl --header "PRIVATE-TOKEN: $GITLAB_PRIVATE_TOKEN" \
--data-urlencode "url=$ARTIFACT_URL" \
--data-urlencode "name=$(basename $ARTIFACT_PATH)" \
"$GITLAB_API_URL/projects/$PROJECT_ID/releases/$CI_COMMIT_TAG/assets/links"
echo "Script terminé."
# Official language image. Look for the different tagged releases at: # Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/rust/tags/ # https://hub.docker.com/r/library/rust/tags/
image: "rust:latest" image: "rust:latest"
stages: stages:
...@@ -19,22 +20,39 @@ build: ...@@ -19,22 +20,39 @@ build:
- target/release/gcli - target/release/gcli
# use cache to avoid re-downloading and re-building all dependencies # use cache to avoid re-downloading and re-building all dependencies
cache: cache:
- key: key:
files: files:
- Cargo.lock - Cargo.lock
paths: paths:
- target/release - target/release
# only build gcli when adding a tag # only build gcli when adding a tag
only: only:
- tags - tags
release: release:
stage: release stage: release
image: rust image: registry.gitlab.com/gitlab-org/release-cli:latest
script: script:
- chmod +x .ci/release_script.sh - echo "Creating a release..."
- .ci/release_script.sh - apk update && apk add git
- git fetch --tags
- LAST_VERSION=$(git tag --sort=-v:refname | sed -n '2p')
- git log --pretty="format:- %s ([%h]($CI_PROJECT_URL/-/commit/%h)) " HEAD...$LAST_VERSION --reverse > release_description.txt
# Define release parameters
release:
# Release name and description using the tag name
name: "v$CI_COMMIT_TAG"
description: "Latest changes:\n$(cat release_description.txt)"
# Set the tag for the release
tag_name: "$CI_COMMIT_TAG"
# Attach the artifact to the release
assets:
links:
- name: "gcli v$CI_COMMIT_TAG for Linux"
url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/target/release/gcli?job=build"
# Trigger release creation only for tagged commits
only: only:
- tags - tags
# Not necessary but clearly shows the dependency
dependencies: dependencies:
- build - build
...@@ -1173,6 +1173,31 @@ version = "0.8.19" ...@@ -1173,6 +1173,31 @@ version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]]
name = "crossterm"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67"
dependencies = [
"bitflags 1.3.2",
"crossterm_winapi",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "crunchy" name = "crunchy"
version = "0.2.2" version = "0.2.2"
...@@ -1467,7 +1492,7 @@ dependencies = [ ...@@ -1467,7 +1492,7 @@ dependencies = [
"regex", "regex",
"syn 2.0.48", "syn 2.0.48",
"termcolor", "termcolor",
"toml 0.8.8", "toml 0.8.9",
"walkdir", "walkdir",
] ]
...@@ -1875,7 +1900,7 @@ dependencies = [ ...@@ -1875,7 +1900,7 @@ dependencies = [
[[package]] [[package]]
name = "gcli" name = "gcli"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bs58", "bs58",
...@@ -1885,6 +1910,7 @@ dependencies = [ ...@@ -1885,6 +1910,7 @@ dependencies = [
"futures", "futures",
"graphql_client", "graphql_client",
"hex", "hex",
"inquire",
"log", "log",
"nacl", "nacl",
"parity-scale-codec", "parity-scale-codec",
...@@ -2333,6 +2359,22 @@ dependencies = [ ...@@ -2333,6 +2359,22 @@ dependencies = [
"generic-array 0.14.7", "generic-array 0.14.7",
] ]
[[package]]
name = "inquire"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c33e7c1ddeb15c9abcbfef6029d8e29f69b52b6d6c891031b88ed91b5065803b"
dependencies = [
"bitflags 1.3.2",
"crossterm",
"dyn-clone",
"lazy_static",
"newline-converter",
"thiserror",
"unicode-segmentation",
"unicode-width",
]
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.12" version = "0.1.12"
...@@ -2728,6 +2770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -2728,6 +2770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09"
dependencies = [ dependencies = [
"libc", "libc",
"log",
"wasi", "wasi",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
...@@ -2756,6 +2799,15 @@ dependencies = [ ...@@ -2756,6 +2799,15 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "newline-converter"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f"
dependencies = [
"unicode-segmentation",
]
[[package]] [[package]]
name = "no-std-net" name = "no-std-net"
version = "0.6.0" version = "0.6.0"
...@@ -3150,7 +3202,7 @@ version = "3.1.0" ...@@ -3150,7 +3202,7 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
dependencies = [ dependencies = [
"toml_edit 0.21.0", "toml_edit 0.21.1",
] ]
[[package]] [[package]]
...@@ -4024,6 +4076,27 @@ dependencies = [ ...@@ -4024,6 +4076,27 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "signal-hook"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801"
dependencies = [
"libc",
"signal-hook-registry",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [
"libc",
"mio",
"signal-hook",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.1" version = "1.4.1"
...@@ -5031,14 +5104,14 @@ dependencies = [ ...@@ -5031,14 +5104,14 @@ dependencies = [
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.8" version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325"
dependencies = [ dependencies = [
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"toml_edit 0.21.0", "toml_edit 0.21.1",
] ]
[[package]] [[package]]
...@@ -5074,9 +5147,9 @@ dependencies = [ ...@@ -5074,9 +5147,9 @@ dependencies = [
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.21.0" version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [ dependencies = [
"indexmap 2.2.1", "indexmap 2.2.1",
"serde", "serde",
...@@ -5267,6 +5340,18 @@ dependencies = [ ...@@ -5267,6 +5340,18 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-segmentation"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.4" version = "0.2.4"
......
[package] [package]
authors = ["librelois <c@elo.tf>", "tuxmain <tuxmain@zettascript.org>", "h30x <hugo@trentesaux.fr>"] authors = [
"librelois <c@elo.tf>",
"tuxmain <tuxmain@zettascript.org>",
"h30x <hugo@trentesaux.fr>",
]
edition = "2021" edition = "2021"
license = "AGPL-3.0" license = "AGPL-3.0-only"
name = "gcli" name = "gcli"
repository = "https://git.duniter.org/clients/rust/gcli-v2s" repository = "https://git.duniter.org/clients/rust/gcli-v2s"
version = "0.2.1" version = "0.2.2"
[dependencies] [dependencies]
# subxt is main dependency # subxt is main dependency
subxt = { git = 'https://github.com/duniter/subxt', branch = 'subxt-v0.34.0-duniter-substrate-v1.6.0', default-features = false, features = ["substrate-compat", "native", "jsonrpsee"] } subxt = { git = 'https://github.com/duniter/subxt', branch = 'subxt-v0.34.0-duniter-substrate-v1.6.0', default-features = false, features = [
"substrate-compat",
"native",
"jsonrpsee",
] }
# substrate primitives dependencies # substrate primitives dependencies
sp-core = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.6.0" } sp-core = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.6.0" }
sp-runtime = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.6.0" } sp-runtime = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.6.0" }
...@@ -27,9 +35,10 @@ serde = { version = "^1.0", features = ["derive"] } ...@@ -27,9 +35,10 @@ serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0.113" serde_json = "^1.0.113"
tokio = { version = "^1.35.1", features = ["macros"] } tokio = { version = "^1.35.1", features = ["macros"] }
confy = "^0.5.1" confy = "^0.5.1"
scrypt = { version = "^0.11", default-features = false } # for old-style key generation scrypt = { version = "^0.11", default-features = false } # for old-style key generation
nacl = { version = "^0.5.3" } # for old-style key generation nacl = { version = "^0.5.3" } # for old-style key generation
bs58 = "^0.5.0" bs58 = "^0.5.0"
inquire = "0.6.2"
# allows to build gcli for different runtimes and with different predefined networks # allows to build gcli for different runtimes and with different predefined networks
[features] [features]
...@@ -37,5 +46,3 @@ default = ["gdev"] # default runtime is "gdev", gdev network is available ...@@ -37,5 +46,3 @@ default = ["gdev"] # default runtime is "gdev", gdev network is available
gdev = [] gdev = []
gtest = [] gtest = []
g1 = [] g1 = []
...@@ -8,6 +8,7 @@ pub mod expire; ...@@ -8,6 +8,7 @@ pub mod expire;
pub mod identity; pub mod identity;
pub mod net_test; pub mod net_test;
pub mod oneshot; pub mod oneshot;
pub mod publish;
pub mod revocation; pub mod revocation;
pub mod runtime; pub mod runtime;
pub mod smith; pub mod smith;
......
// commands/publish.rs
// This module handles the 'publish' command of the CLI.
use crate::GcliError;
use anyhow::anyhow;
use inquire::Confirm;
use std::process::Command;
/// Executes the 'publish' operation.
pub async fn handle_command() -> Result<(), GcliError> {
// Step 1: Get actual version of gcli
const VERSION: &str = env!("CARGO_PKG_VERSION");
// Step 2: Check if the git tag already exists
let tag_check_output = Command::new("git").args(["tag", "-l", VERSION]).output()?;
if !tag_check_output.stdout.is_empty() {
return Err(GcliError::Logic(format!("Tag {VERSION} already exists")));
}
// Display a confirmation prompt with the version number.
match Confirm::new(&format!(
"Are you sure you want to publish version {VERSION} ?"
))
.with_default(false)
.prompt()
{
Ok(true) => {
// User confirmed, proceed publishing
// Step 3: Create and push the git tag
Command::new("git")
.args(["tag", "-a", VERSION, "-m", &format!("Release v{VERSION}")])
.status()
.map_err(|e| anyhow!(e))?;
Command::new("git")
.args(["push", "origin", &format!("refs/tags/{VERSION}")])
.status()
.map_err(|e| anyhow!(e))?;
println!("Publication of version {VERSION} completed successfully.");
Ok(())
}
Ok(false) => {
// User did not confirm, cancel the operation
println!("Publication cancelled.");
Ok(())
}
Err(_) => {
// There was an error with the prompt, return an error
Err(GcliError::Input(
"Failed to display confirmation prompt".to_string(),
))
}
}
}
...@@ -100,6 +100,9 @@ pub enum Subcommand { ...@@ -100,6 +100,9 @@ pub enum Subcommand {
/// Cesium /// Cesium
#[clap(subcommand, hide = true)] #[clap(subcommand, hide = true)]
Cesium(commands::cesium::Subcommand), Cesium(commands::cesium::Subcommand),
/// Publish a new git tag with actual version
#[clap(hide = true)]
Publish,
} }
/// main function /// main function
...@@ -135,6 +138,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -135,6 +138,7 @@ async fn main() -> Result<(), GcliError> {
Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await, Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await,
Subcommand::Config(subcommand) => conf::handle_command(data, subcommand), Subcommand::Config(subcommand) => conf::handle_command(data, subcommand),
Subcommand::Cesium(subcommand) => commands::cesium::handle_command(data, subcommand).await, Subcommand::Cesium(subcommand) => commands::cesium::handle_command(data, subcommand).await,
Subcommand::Publish => commands::publish::handle_command().await,
}; };
if let Err(ref e) = result { if let Err(ref e) = result {
println!("{}", e) println!("{}", e)
......
...@@ -103,6 +103,8 @@ pub enum GcliError { ...@@ -103,6 +103,8 @@ pub enum GcliError {
Input(String), Input(String),
/// error coming from anyhow (to be removed) /// error coming from anyhow (to be removed)
Anyhow(anyhow::Error), Anyhow(anyhow::Error),
/// error coming from io
IoError(std::io::Error),
} }
impl std::fmt::Display for GcliError { impl std::fmt::Display for GcliError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
...@@ -132,3 +134,8 @@ impl From<confy::ConfyError> for GcliError { ...@@ -132,3 +134,8 @@ impl From<confy::ConfyError> for GcliError {
GcliError::Anyhow(e.into()) GcliError::Anyhow(e.into())
} }
} }
impl From<std::io::Error> for GcliError {
fn from(error: std::io::Error) -> Self {
GcliError::IoError(error)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment