mirror of
https://github.com/alexgo-io/stacks-subnets.git
synced 2026-01-12 08:34:47 +08:00
Update build metadata. don't trigger from pushed tags anymore (#2276)
* Update build metadata. don't trigger from pushed tags anymore * ignore git directory in docker context, change config vars for versioning * Update server_version at /v2/info * fix rustfmt Co-authored-by: Aaron Blankstein <aaron@blockstack.com>
This commit is contained in:
@@ -3,6 +3,7 @@ target
|
||||
integration_tests/blockstack-consensus-data/
|
||||
integration_tests/test-out/
|
||||
api/data
|
||||
.git
|
||||
.venv
|
||||
.dockerignore
|
||||
testnet/index.html
|
||||
|
||||
31
.github/workflows/stacks-blockchain.yml
vendored
31
.github/workflows/stacks-blockchain.yml
vendored
@@ -1,14 +1,10 @@
|
||||
name: stacks-blockchain
|
||||
|
||||
# Only run when:
|
||||
# - tags starting with "v" get pushed
|
||||
# - PRs are opened against the master branch
|
||||
# - the workflow is started from the UI (an optional tag can be passed in via parameter)
|
||||
# - If the optional tag parameter is passed in, a new tag will be generated based off the selected branch
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
@@ -58,7 +54,6 @@ jobs:
|
||||
# Run net-tests
|
||||
nettest:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Run network relay tests
|
||||
@@ -109,6 +104,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set Vars
|
||||
run: |
|
||||
echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
|
||||
echo "GITHUB_REF_SHORT=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build/Tag/Push Image
|
||||
uses: docker/build-push-action@v1
|
||||
with:
|
||||
@@ -118,8 +118,9 @@ jobs:
|
||||
tags: ${{ github.event.inputs.tag }}
|
||||
tag_with_ref: true
|
||||
add_git_labels: true
|
||||
# Only push if (a tag was passed in) or (we're building a tag) or (we're building a non-master branch which isn't a PR)
|
||||
push: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
|
||||
build_args: STACKS_NODE_VERSION=${{ github.event.inputs.tag || env.GITHUB_SHA_SHORT }},GIT_BRANCH=${{ env.GITHUB_REF_SHORT }},GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }}
|
||||
# Only push if (a tag was passed in) or (we're building a non-master branch which isn't a PR)
|
||||
push: ${{ github.event.inputs.tag != '' || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
|
||||
|
||||
# Build docker image, tag it with the git tag and `latest` if running on master branch, and publish under the following conditions
|
||||
# Will publish if:
|
||||
@@ -146,6 +147,11 @@ jobs:
|
||||
env:
|
||||
TAG: ${{ github.event.inputs.tag }}
|
||||
|
||||
- name: Set Vars
|
||||
run: |
|
||||
echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
|
||||
echo "GITHUB_REF_SHORT=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build/Tag/Push Image
|
||||
uses: docker/build-push-action@v1
|
||||
with:
|
||||
@@ -156,13 +162,14 @@ jobs:
|
||||
tags: ${{ env.STRETCH_TAG }}
|
||||
tag_with_ref: false
|
||||
add_git_labels: true
|
||||
# Only push if (a tag was passed in) or (we're building a tag) or (we're building a non-master branch which isn't a PR)
|
||||
push: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
|
||||
build_args: STACKS_NODE_VERSION=${{ github.event.inputs.tag || env.GITHUB_SHA_SHORT }},GIT_BRANCH=${{ env.GITHUB_REF_SHORT }},GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }}
|
||||
# Only push if (a tag was passed in) or (we're building a non-master branch which isn't a PR)
|
||||
push: ${{ github.event.inputs.tag != '' || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
|
||||
|
||||
# Create a new release if we're building a tag or a tag was passed in
|
||||
# Create a new release if we're building a tag
|
||||
create-release:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') }}
|
||||
if: ${{ github.event.inputs.tag != '' }}
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
needs:
|
||||
@@ -187,7 +194,7 @@ jobs:
|
||||
# Upload distributables to a new release if we're building a tag or a tag was passed in
|
||||
upload-dist:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') }}
|
||||
if: ${{ github.event.inputs.tag != '' }}
|
||||
needs:
|
||||
- create-release
|
||||
strategy:
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
FROM rust:alpine as build
|
||||
|
||||
ARG STACKS_NODE_VERSION="No Version Info"
|
||||
ARG GIT_BRANCH='No Branch Info'
|
||||
ARG GIT_COMMIT='No Commit Info'
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY . .
|
||||
@@ -18,4 +22,4 @@ FROM alpine
|
||||
|
||||
COPY --from=build /out/ /bin/
|
||||
|
||||
CMD ["stacks-node", "argon"]
|
||||
CMD ["stacks-node", "xenon"]
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
FROM rust:stretch as build
|
||||
|
||||
ARG STACKS_NODE_VERSION="No Version Info"
|
||||
ARG GIT_BRANCH='No Branch Info'
|
||||
ARG GIT_COMMIT='No Commit Info'
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY . .
|
||||
@@ -17,4 +21,4 @@ FROM debian:stretch-slim
|
||||
RUN apt update && apt install -y netcat
|
||||
COPY --from=build /out/ /bin/
|
||||
|
||||
CMD ["stacks-node", "argon"]
|
||||
CMD ["stacks-node", "xenon"]
|
||||
|
||||
44
build.rs
44
build.rs
@@ -1,32 +1,42 @@
|
||||
use std::process::Command;
|
||||
|
||||
fn current_git_hash() -> Option<String> {
|
||||
let commit = Command::new("git")
|
||||
.arg("log")
|
||||
.arg("-1")
|
||||
.arg("--pretty=format:%h") // Abbreviated commit hash
|
||||
.current_dir(env!("CARGO_MANIFEST_DIR"))
|
||||
.output();
|
||||
if option_env!("GIT_COMMIT") == None {
|
||||
let commit = Command::new("git")
|
||||
.arg("log")
|
||||
.arg("-1")
|
||||
.arg("--pretty=format:%h") // Abbreviated commit hash
|
||||
.current_dir(env!("CARGO_MANIFEST_DIR"))
|
||||
.output();
|
||||
|
||||
if let Ok(commit) = commit {
|
||||
if let Ok(commit) = String::from_utf8(commit.stdout) {
|
||||
return Some(commit);
|
||||
if let Ok(commit) = commit {
|
||||
if let Ok(commit) = String::from_utf8(commit.stdout) {
|
||||
return Some(commit);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return option_env!("GIT_COMMIT").map(String::from);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn current_git_branch() -> Option<String> {
|
||||
let commit = Command::new("git")
|
||||
.arg("rev-parse")
|
||||
.arg("--abbrev-ref")
|
||||
.arg("HEAD")
|
||||
.output();
|
||||
if let Ok(commit) = commit {
|
||||
if let Ok(commit) = String::from_utf8(commit.stdout) {
|
||||
return Some(commit);
|
||||
if option_env!("GIT_BRANCH") == None {
|
||||
let commit = Command::new("git")
|
||||
.arg("rev-parse")
|
||||
.arg("--abbrev-ref")
|
||||
.arg("HEAD")
|
||||
.output();
|
||||
if let Ok(commit) = commit {
|
||||
if let Ok(commit) = String::from_utf8(commit.stdout) {
|
||||
return Some(commit);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return option_env!("GIT_BRANCH").map(String::from);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
@@ -96,16 +96,15 @@ const BUILD_TYPE: &'static str = "release";
|
||||
|
||||
pub fn version_string(pkg_name: &str, pkg_version: &str) -> String {
|
||||
let git_branch = GIT_BRANCH
|
||||
.map(|x| format!("{}:", x))
|
||||
.map(|x| format!("{}", x))
|
||||
.unwrap_or("".to_string());
|
||||
let git_commit = GIT_COMMIT.unwrap_or("");
|
||||
let git_tree_clean = GIT_TREE_CLEAN.unwrap_or("");
|
||||
|
||||
format!(
|
||||
"{} {} => {} ({}{}{}, {} build, {} [{}])",
|
||||
"{} {} ({}:{}{}, {} build, {} [{}])",
|
||||
pkg_name,
|
||||
pkg_version,
|
||||
core::CHAINSTATE_VERSION,
|
||||
&git_branch,
|
||||
git_commit,
|
||||
git_tree_clean,
|
||||
|
||||
@@ -187,8 +187,10 @@ impl RPCPeerInfoData {
|
||||
};
|
||||
|
||||
let server_version = version_string(
|
||||
option_env!("CARGO_PKG_NAME").unwrap_or("stacks-node"),
|
||||
option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0"),
|
||||
"stacks-node",
|
||||
option_env!("STACKS_NODE_VERSION")
|
||||
.or(option_env!("CARGO_PKG_VERSION"))
|
||||
.unwrap_or("0.0.0.0"),
|
||||
);
|
||||
let stacks_tip_consensus_hash = burnchain_tip.canonical_stacks_tip_consensus_hash;
|
||||
let stacks_tip = burnchain_tip.canonical_stacks_tip_hash;
|
||||
|
||||
@@ -116,8 +116,10 @@ fn main() {
|
||||
println!(
|
||||
"{}",
|
||||
&stacks::version_string(
|
||||
option_env!("CARGO_PKG_NAME").unwrap_or("stacks-node"),
|
||||
option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0")
|
||||
"stacks-node",
|
||||
option_env!("STACKS_NODE_VERSION")
|
||||
.or(option_env!("CARGO_PKG_VERSION"))
|
||||
.unwrap_or("0.0.0.0")
|
||||
)
|
||||
);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user