Skip to content

Commit 00284ee

Browse files
CharlieC3Aaron Blankstein
andauthored
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 <[email protected]>
1 parent 31bc907 commit 00284ee

File tree

8 files changed

+67
-38
lines changed

8 files changed

+67
-38
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ target
33
integration_tests/blockstack-consensus-data/
44
integration_tests/test-out/
55
api/data
6+
.git
67
.venv
78
.dockerignore
89
testnet/index.html

.github/workflows/stacks-blockchain.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
name: stacks-blockchain
22

33
# Only run when:
4-
# - tags starting with "v" get pushed
54
# - PRs are opened against the master branch
65
# - the workflow is started from the UI (an optional tag can be passed in via parameter)
76
# - If the optional tag parameter is passed in, a new tag will be generated based off the selected branch
87
on:
9-
push:
10-
tags:
11-
- 'v*'
128
pull_request:
139
workflow_dispatch:
1410
inputs:
@@ -58,7 +54,6 @@ jobs:
5854
# Run net-tests
5955
nettest:
6056
runs-on: ubuntu-latest
61-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
6257
steps:
6358
- uses: actions/checkout@v2
6459
- name: Run network relay tests
@@ -109,6 +104,11 @@ jobs:
109104
runs-on: ubuntu-latest
110105
steps:
111106
- uses: actions/checkout@v2
107+
- name: Set Vars
108+
run: |
109+
echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
110+
echo "GITHUB_REF_SHORT=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
111+
112112
- name: Build/Tag/Push Image
113113
uses: docker/build-push-action@v1
114114
with:
@@ -118,8 +118,9 @@ jobs:
118118
tags: ${{ github.event.inputs.tag }}
119119
tag_with_ref: true
120120
add_git_labels: true
121-
# 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)
122-
push: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
121+
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 }}
122+
# Only push if (a tag was passed in) or (we're building a non-master branch which isn't a PR)
123+
push: ${{ github.event.inputs.tag != '' || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
123124

124125
# Build docker image, tag it with the git tag and `latest` if running on master branch, and publish under the following conditions
125126
# Will publish if:
@@ -146,6 +147,11 @@ jobs:
146147
env:
147148
TAG: ${{ github.event.inputs.tag }}
148149

150+
- name: Set Vars
151+
run: |
152+
echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
153+
echo "GITHUB_REF_SHORT=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
154+
149155
- name: Build/Tag/Push Image
150156
uses: docker/build-push-action@v1
151157
with:
@@ -156,13 +162,14 @@ jobs:
156162
tags: ${{ env.STRETCH_TAG }}
157163
tag_with_ref: false
158164
add_git_labels: true
159-
# 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)
160-
push: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
165+
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 }}
166+
# Only push if (a tag was passed in) or (we're building a non-master branch which isn't a PR)
167+
push: ${{ github.event.inputs.tag != '' || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }}
161168

162-
# Create a new release if we're building a tag or a tag was passed in
169+
# Create a new release if we're building a tag
163170
create-release:
164171
runs-on: ubuntu-latest
165-
if: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') }}
172+
if: ${{ github.event.inputs.tag != '' }}
166173
outputs:
167174
upload_url: ${{ steps.create_release.outputs.upload_url }}
168175
needs:
@@ -187,7 +194,7 @@ jobs:
187194
# Upload distributables to a new release if we're building a tag or a tag was passed in
188195
upload-dist:
189196
runs-on: ubuntu-latest
190-
if: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') }}
197+
if: ${{ github.event.inputs.tag != '' }}
191198
needs:
192199
- create-release
193200
strategy:

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM rust:alpine as build
22

3+
ARG STACKS_NODE_VERSION="No Version Info"
4+
ARG GIT_BRANCH='No Branch Info'
5+
ARG GIT_COMMIT='No Commit Info'
6+
37
WORKDIR /src
48

59
COPY . .
@@ -18,4 +22,4 @@ FROM alpine
1822

1923
COPY --from=build /out/ /bin/
2024

21-
CMD ["stacks-node", "argon"]
25+
CMD ["stacks-node", "xenon"]

Dockerfile.stretch

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM rust:stretch as build
22

3+
ARG STACKS_NODE_VERSION="No Version Info"
4+
ARG GIT_BRANCH='No Branch Info'
5+
ARG GIT_COMMIT='No Commit Info'
6+
37
WORKDIR /src
48

59
COPY . .
@@ -17,4 +21,4 @@ FROM debian:stretch-slim
1721
RUN apt update && apt install -y netcat
1822
COPY --from=build /out/ /bin/
1923

20-
CMD ["stacks-node", "argon"]
24+
CMD ["stacks-node", "xenon"]

build.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
use std::process::Command;
22

33
fn current_git_hash() -> Option<String> {
4-
let commit = Command::new("git")
5-
.arg("log")
6-
.arg("-1")
7-
.arg("--pretty=format:%h") // Abbreviated commit hash
8-
.current_dir(env!("CARGO_MANIFEST_DIR"))
9-
.output();
4+
if option_env!("GIT_COMMIT") == None {
5+
let commit = Command::new("git")
6+
.arg("log")
7+
.arg("-1")
8+
.arg("--pretty=format:%h") // Abbreviated commit hash
9+
.current_dir(env!("CARGO_MANIFEST_DIR"))
10+
.output();
1011

11-
if let Ok(commit) = commit {
12-
if let Ok(commit) = String::from_utf8(commit.stdout) {
13-
return Some(commit);
12+
if let Ok(commit) = commit {
13+
if let Ok(commit) = String::from_utf8(commit.stdout) {
14+
return Some(commit);
15+
}
1416
}
17+
} else {
18+
return option_env!("GIT_COMMIT").map(String::from);
1519
}
20+
1621
None
1722
}
1823

1924
fn current_git_branch() -> Option<String> {
20-
let commit = Command::new("git")
21-
.arg("rev-parse")
22-
.arg("--abbrev-ref")
23-
.arg("HEAD")
24-
.output();
25-
if let Ok(commit) = commit {
26-
if let Ok(commit) = String::from_utf8(commit.stdout) {
27-
return Some(commit);
25+
if option_env!("GIT_BRANCH") == None {
26+
let commit = Command::new("git")
27+
.arg("rev-parse")
28+
.arg("--abbrev-ref")
29+
.arg("HEAD")
30+
.output();
31+
if let Ok(commit) = commit {
32+
if let Ok(commit) = String::from_utf8(commit.stdout) {
33+
return Some(commit);
34+
}
2835
}
36+
} else {
37+
return option_env!("GIT_BRANCH").map(String::from);
2938
}
39+
3040
None
3141
}
3242

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,15 @@ const BUILD_TYPE: &'static str = "release";
9696

9797
pub fn version_string(pkg_name: &str, pkg_version: &str) -> String {
9898
let git_branch = GIT_BRANCH
99-
.map(|x| format!("{}:", x))
99+
.map(|x| format!("{}", x))
100100
.unwrap_or("".to_string());
101101
let git_commit = GIT_COMMIT.unwrap_or("");
102102
let git_tree_clean = GIT_TREE_CLEAN.unwrap_or("");
103103

104104
format!(
105-
"{} {} => {} ({}{}{}, {} build, {} [{}])",
105+
"{} {} ({}:{}{}, {} build, {} [{}])",
106106
pkg_name,
107107
pkg_version,
108-
core::CHAINSTATE_VERSION,
109108
&git_branch,
110109
git_commit,
111110
git_tree_clean,

src/net/rpc.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ impl RPCPeerInfoData {
187187
};
188188

189189
let server_version = version_string(
190-
option_env!("CARGO_PKG_NAME").unwrap_or("stacks-node"),
191-
option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0"),
190+
"stacks-node",
191+
option_env!("STACKS_NODE_VERSION")
192+
.or(option_env!("CARGO_PKG_VERSION"))
193+
.unwrap_or("0.0.0.0"),
192194
);
193195
let stacks_tip_consensus_hash = burnchain_tip.canonical_stacks_tip_consensus_hash;
194196
let stacks_tip = burnchain_tip.canonical_stacks_tip_hash;

testnet/stacks-node/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ fn main() {
116116
println!(
117117
"{}",
118118
&stacks::version_string(
119-
option_env!("CARGO_PKG_NAME").unwrap_or("stacks-node"),
120-
option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0")
119+
"stacks-node",
120+
option_env!("STACKS_NODE_VERSION")
121+
.or(option_env!("CARGO_PKG_VERSION"))
122+
.unwrap_or("0.0.0.0")
121123
)
122124
);
123125
return;

0 commit comments

Comments
 (0)