From 7026f8484a6b2b93be29535940b0e8ed4911ad8f Mon Sep 17 00:00:00 2001 From: wiesche <120273695+wiesche89@users.noreply.github.com> Date: Thu, 7 May 2026 18:16:33 +0200 Subject: [PATCH 1/3] Test staging PR permissions (#3831) --- staging-test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 staging-test.txt diff --git a/staging-test.txt b/staging-test.txt new file mode 100644 index 00000000..bfc5aa8e --- /dev/null +++ b/staging-test.txt @@ -0,0 +1 @@ +staging test From e172f490ba623f9cd5f42b9a343ba054c796d21e Mon Sep 17 00:00:00 2001 From: ardocrat Date: Tue, 12 May 2026 16:26:42 +0300 Subject: [PATCH 2/3] ci: staging docker build (#3832) --- .github/workflows/publish-ghcr.yaml.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-ghcr.yaml.yml b/.github/workflows/publish-ghcr.yaml.yml index 8e671098..5c1e3f07 100644 --- a/.github/workflows/publish-ghcr.yaml.yml +++ b/.github/workflows/publish-ghcr.yaml.yml @@ -2,7 +2,7 @@ name: Build and Push to GHCR on: push: - branches: [master] + branches: [master, staging] env: GHCR_IMAGE: ghcr.io/${{ secrets.GHCR_USERNAME }}/${{ github.event.repository.name }} @@ -98,7 +98,15 @@ jobs: - name: Generate image tag id: vars - run: echo "tag=$(awk -F'"' '/^version/{ print $2; exit; }' Cargo.toml)" >> $GITHUB_OUTPUT + run: | + version=$(awk -F'"' '/^version/{ print $2; exit; }' Cargo.toml) + if ${{ github.ref_name == 'master' }}; then + echo "version=$version" >> $GITHUB_OUTPUT + echo "tag=latest" >> $GITHUB_OUTPUT + else + echo "version=${version}-staging" >> $GITHUB_OUTPUT + echo "tag=staging" >> $GITHUB_OUTPUT + fi - name: Docker meta id: meta @@ -106,8 +114,8 @@ jobs: with: images: ${{ env.GHCR_IMAGE }} tags: | + type=raw,value=${{ steps.vars.outputs.version }},enable=true type=raw,value=${{ steps.vars.outputs.tag }},enable=true - type=raw,value=latest,enable=true - name: Create manifest list and push working-directory: ${{ runner.temp }}/digests From 894d9e555168bc6a292fa1cf35027b153b5e2ca0 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Wed, 13 May 2026 21:17:26 +0300 Subject: [PATCH 3/3] Include git info into docker build, show git ref at version (#3829) * ci: include .git directory into build * p2p: include git ref into version for user agent, show git commit hash instead of last tag into log * p2p: do not show anything after version if git commit hash is empty * fix: user agent typo --- .github/workflows/publish-ghcr.yaml.yml | 5 ++--- Cargo.lock | 1 + api/src/types.rs | 5 +++-- p2p/Cargo.toml | 4 ++++ p2p/src/build/build.rs | 28 +++++++++++++++++++++++++ p2p/src/handshake.rs | 6 +++--- p2p/src/msg.rs | 13 +++++++++++- p2p/tests/peer_handshake.rs | 8 ++++++- src/bin/grin.rs | 2 +- 9 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 p2p/src/build/build.rs diff --git a/.github/workflows/publish-ghcr.yaml.yml b/.github/workflows/publish-ghcr.yaml.yml index 5c1e3f07..687f09eb 100644 --- a/.github/workflows/publish-ghcr.yaml.yml +++ b/.github/workflows/publish-ghcr.yaml.yml @@ -41,13 +41,12 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Checkout code - uses: actions/checkout@v6 - - name: Build and push by digest id: build uses: docker/build-push-action@v6 with: + build-args: | + BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 provenance: false # Disable provenance to avoid unknown/unknown sbom: false # Disable sbom to avoid unknown/unknown platforms: ${{ matrix.platform }} diff --git a/Cargo.lock b/Cargo.lock index 429a99f9..cc2d73f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1085,6 +1085,7 @@ name = "grin_p2p" version = "5.4.0" dependencies = [ "bitflags 1.3.2", + "built", "bytes 0.5.6", "chrono", "enum_primitive", diff --git a/api/src/types.rs b/api/src/types.rs index 4d319405..06918262 100644 --- a/api/src/types.rs +++ b/api/src/types.rs @@ -95,7 +95,7 @@ impl Status { Status { chain: global::get_chain_type().shortname(), protocol_version: ser::ProtocolVersion::local().into(), - user_agent: p2p::msg::USER_AGENT.to_string(), + user_agent: p2p::msg::user_agent().to_string(), connections: connections, tip: Tip::from_tip(current_tip), sync_status, @@ -465,7 +465,8 @@ impl<'de> serde::de::Deserialize<'de> for OutputPrintable { } if output_type.is_none() - || commit.is_none() || spent.is_none() + || commit.is_none() + || spent.is_none() || proof_hash.is_none() || mmr_index.is_none() { diff --git a/p2p/Cargo.toml b/p2p/Cargo.toml index 274a07d4..539feb39 100644 --- a/p2p/Cargo.toml +++ b/p2p/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/mimblewimble/grin" keywords = [ "crypto", "grin", "mimblewimble" ] workspace = ".." edition = "2018" +build = "src/build/build.rs" [dependencies] bitflags = "1" @@ -29,3 +30,6 @@ grin_chain = { path = "../chain", version = "5.4.0" } [dev-dependencies] grin_pool = { path = "../pool", version = "5.4.0" } + +[build-dependencies] +built = { version = "0.8.0", features = ["git2"]} \ No newline at end of file diff --git a/p2p/src/build/build.rs b/p2p/src/build/build.rs new file mode 100644 index 00000000..cd3cb975 --- /dev/null +++ b/p2p/src/build/build.rs @@ -0,0 +1,28 @@ +// Copyright 2026 The Grin Developers +// +// 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. + +//! Build hooks to spit out version info + +use std::env; +use std::path::Path; + +fn main() { + // build and versioning information + let out_dir_path = format!("{}{}", env::var("OUT_DIR").unwrap(), "/built.rs"); + // don't fail the build if something's missing, may just be cargo release + let _ = built::write_built_file_with_opts( + Some(Path::new(env!("CARGO_MANIFEST_DIR"))), + Path::new(&out_dir_path), + ); +} diff --git a/p2p/src/handshake.rs b/p2p/src/handshake.rs index 25855eff..c5feb345 100644 --- a/p2p/src/handshake.rs +++ b/p2p/src/handshake.rs @@ -16,7 +16,7 @@ use crate::conn::Tracker; use crate::core::core::hash::Hash; use crate::core::pow::Difficulty; use crate::core::ser::ProtocolVersion; -use crate::msg::{read_message, write_message, Hand, Msg, Shake, Type, USER_AGENT}; +use crate::msg::{read_message, user_agent, write_message, Hand, Msg, Shake, Type}; use crate::peer::Peer; use crate::types::{Capabilities, Direction, Error, P2PConfig, PeerAddr, PeerInfo, PeerLiveInfo}; use crate::util::RwLock; @@ -120,7 +120,7 @@ impl Handshake { total_difficulty, sender_addr: self_addr, receiver_addr: peer_addr, - user_agent: USER_AGENT.to_string(), + user_agent: user_agent().to_string(), }; // write and read the handshake response @@ -225,7 +225,7 @@ impl Handshake { capabilities: capab, genesis: self.genesis, total_difficulty: total_difficulty, - user_agent: USER_AGENT.to_string(), + user_agent: user_agent().to_string(), }; let msg = Msg::new(Type::Shake, shake, negotiated_version)?; diff --git a/p2p/src/msg.rs b/p2p/src/msg.rs index 3103db09..69c448e9 100644 --- a/p2p/src/msg.rs +++ b/p2p/src/msg.rs @@ -40,8 +40,19 @@ use std::io::{Read, Write}; use std::sync::Arc; use std::{fmt, thread, time::Duration}; +// include build information +pub mod built_info { + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + /// Grin's user agent with current version -pub const USER_AGENT: &str = concat!("MW/Grin ", env!("CARGO_PKG_VERSION")); +pub fn user_agent() -> String { + format!( + "MW/Grin {}{}", + env!("CARGO_PKG_VERSION"), + built_info::GIT_COMMIT_HASH_SHORT.map_or_else(|| "".to_owned(), |v| ".".to_owned() + v) + ) +} /// Magic numbers expected in the header of every message const OTHER_MAGIC: [u8; 2] = [73, 43]; diff --git a/p2p/tests/peer_handshake.rs b/p2p/tests/peer_handshake.rs index c4f16c55..e79d2e37 100644 --- a/p2p/tests/peer_handshake.rs +++ b/p2p/tests/peer_handshake.rs @@ -25,6 +25,7 @@ use std::{thread, time}; use crate::core::core::hash::Hash; use crate::core::global; use crate::core::pow::Difficulty; +use crate::p2p::msg::built_info; use crate::p2p::types::PeerAddr; use crate::p2p::Peer; @@ -88,7 +89,12 @@ fn peer_handshake() { ) .unwrap(); - assert!(peer.info.user_agent.ends_with(env!("CARGO_PKG_VERSION"))); + let git_hash = + built_info::GIT_COMMIT_HASH_SHORT.map_or_else(|| "".to_owned(), |v| ".".to_owned() + v); + assert!(peer + .info + .user_agent + .ends_with(format!("{}{}", env!("CARGO_PKG_VERSION"), git_hash).as_str())); thread::sleep(time::Duration::from_secs(1)); diff --git a/src/bin/grin.rs b/src/bin/grin.rs index 8d847fec..168e5e6e 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -55,7 +55,7 @@ pub fn info_strings() -> (String, String) { format!( "This is Grin version {}{}, built for {} by {}.", built_info::PKG_VERSION, - built_info::GIT_VERSION.map_or_else(|| "".to_owned(), |v| format!(" (git {})", v)), + built_info::GIT_COMMIT_HASH.map_or_else(|| "".to_owned(), |v| format!(" (git {})", v)), built_info::TARGET, built_info::RUSTC_VERSION, ),