Skip to content

Commit c2d466c

Browse files
authored
Merge pull request #572 from input-output-hk/djo/543/fix-artifacts-collision
Package artifacts in a archive for each environment
2 parents 416d9bf + 6c5b4e3 commit c2d466c

File tree

13 files changed

+212
-60
lines changed

13 files changed

+212
-60
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,34 +296,68 @@ jobs:
296296
- run-test-lab
297297
- check
298298
steps:
299-
- name: Download built artifacts (${{ runner.os }}-${{ runner.arch }})
299+
- name: Checkout sources
300+
uses: actions/checkout@v3
301+
302+
- name: Prepare packaging
303+
run: mkdir package
304+
305+
- name: Get short SHA
306+
id: slug
307+
run: echo "sha8=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
308+
309+
- name: Download built artifacts (Linux-X64)
300310
uses: actions/download-artifact@v3
301311
with:
302-
name: mithril-distribution-${{ runner.os }}-${{ runner.arch }}
303-
path: ./build
312+
name: mithril-distribution-Linux-X64
313+
path: ./package-Linux-X64
304314

305315
- name: Download built artifacts (macOS-X64)
306316
uses: actions/download-artifact@v3
307317
with:
308318
name: mithril-distribution-macOS-X64
309-
path: ./build
319+
path: ./package-macOS-X64
310320

311321
- name: Download built artifacts (Windows-X64)
312322
uses: actions/download-artifact@v3
313323
with:
314324
name: mithril-distribution-Windows-X64
315-
path: ./build
325+
path: ./package-Windows-X64
316326

327+
- name: Package distribution (Linux-X64)
328+
run: |
329+
python3 ./.github/workflows/scripts/package-distribution.py \
330+
--input package-Linux-X64/ \
331+
--dest package/ \
332+
--version "unstable-${{ steps.slug.outputs.sha8 }}" \
333+
--target "linux-x64"
334+
335+
- name: Package distribution (macOS-X64)
336+
run: |
337+
python3 ./.github/workflows/scripts/package-distribution.py \
338+
--input package-macOS-X64/ \
339+
--dest package/ \
340+
--version "unstable-${{ steps.slug.outputs.sha8 }}" \
341+
--target "macos-x64"
342+
343+
- name: Package distribution (Windows-X64)
344+
run: |
345+
python3 ./.github/workflows/scripts/package-distribution.py \
346+
--input package-Windows-X64/ \
347+
--dest package/ \
348+
--version "unstable-${{ steps.slug.outputs.sha8 }}" \
349+
--target "windows-x64"
350+
317351
- name: Update unstable release
318352
uses: marvinpinto/action-automatic-releases@latest
319353
with:
320354
repo_token: ${{ secrets.GITHUB_TOKEN }}
321355
automatic_release_tag: unstable
322356
prerelease: true
323357
title: Unstable Development Builds
324-
files: build/*
358+
files: package/*
325359

326-
terraform:
360+
deploy-testing:
327361
runs-on: ubuntu-22.04
328362
needs:
329363
- docker-mithril

.github/workflows/pre-release.yml

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,66 @@ jobs:
1010
create-pre-release:
1111
runs-on: ubuntu-22.04
1212
steps:
13+
- name: Checkout sources
14+
uses: actions/checkout@v3
15+
16+
- name: Prepare packaging
17+
run: mkdir package
18+
1319
- name: Download built artifacts (Linux-x64)
1420
uses: dawidd6/action-download-artifact@v2
1521
with:
1622
name: mithril-distribution-Linux-x64
17-
path: ./build
23+
path: ./package-Linux-X64
1824
commit: ${{ github.sha }}
1925
workflow: ci.yml
2026
workflow_conclusion: success
21-
22-
- name: Download built artifacts (Windows-x64)
27+
28+
- name: Download built artifacts (macOS-x64)
2329
uses: dawidd6/action-download-artifact@v2
2430
with:
25-
name: mithril-distribution-Windows-x64
26-
path: ./build
31+
name: mithril-distribution-macOS-x64
32+
path: ./package-macOS-X64
2733
commit: ${{ github.sha }}
2834
workflow: ci.yml
2935
workflow_conclusion: success
3036

31-
- name: Download built artifacts (macOS-x64)
37+
- name: Download built artifacts (Windows-x64)
3238
uses: dawidd6/action-download-artifact@v2
3339
with:
34-
name: mithril-distribution-macOS-x64
35-
path: ./build
40+
name: mithril-distribution-Windows-x64
41+
path: ./package-Windows-X64
3642
commit: ${{ github.sha }}
3743
workflow: ci.yml
3844
workflow_conclusion: success
45+
46+
- name: Package distribution (Linux-X64)
47+
run: |
48+
python3 ./.github/workflows/scripts/package-distribution.py \
49+
--input package-Linux-X64/ \
50+
--dest package/ \
51+
--version "${{ github.ref_name }}" \
52+
--target "linux-x64"
53+
54+
- name: Package distribution (macOS-X64)
55+
run: |
56+
python3 ./.github/workflows/scripts/package-distribution.py \
57+
--input package-macOS-X64/ \
58+
--dest package/ \
59+
--version "${{ github.ref_name }}" \
60+
--target "macos-x64"
61+
62+
- name: Package distribution (Windows-X64)
63+
run: |
64+
python3 ./.github/workflows/scripts/package-distribution.py \
65+
--input package-Windows-X64/ \
66+
--dest package/ \
67+
--version "${{ github.ref_name }}" \
68+
--target "windows-x64"
3969
4070
- name: Append VERSION file
4171
run: |
42-
echo ${{ github.ref_name }} >> ./build/VERSION
72+
echo ${{ github.ref_name }} >> ./package/VERSION
4373
4474
- name: Create pre-release ${{ github.ref_name }}
4575
uses: marvinpinto/action-automatic-releases@latest
@@ -48,7 +78,7 @@ jobs:
4878
automatic_release_tag: ${{ github.ref_name }}
4979
prerelease: true
5080
title: Mithril v${{ github.ref_name }}
51-
files: build/**/*
81+
files: package/*
5282

5383
build-push-docker:
5484
runs-on: ubuntu-22.04
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import hashlib
2+
import argparse
3+
import os
4+
import platform
5+
import shutil
6+
7+
8+
def sha256sum(path: str):
9+
h = hashlib.sha256()
10+
paths = []
11+
12+
# Note: this won't works if the given path is a directory with a subdirectory
13+
if os.path.isdir(path):
14+
for file in os.listdir(path):
15+
paths.append(os.path.join(path, file))
16+
else:
17+
paths.append(path)
18+
19+
for path in paths:
20+
with open(path, "rb") as f:
21+
data = f.read()
22+
h.update(data)
23+
return h.hexdigest()
24+
25+
26+
def dir_path(path):
27+
if os.path.isdir(path):
28+
return path
29+
else:
30+
raise NotADirectoryError(path)
31+
32+
33+
def build_archive(input_dir, destination_dir, archive_basename):
34+
input_files = os.listdir(args.input)
35+
print(f"packing mithril distribution {args.version}-{args.target} with files: {input_files}")
36+
37+
if platform.system() == "Windows":
38+
import zipfile
39+
40+
archive_name = os.path.join(destination_dir, f"{archive_basename}.zip")
41+
with zipfile.ZipFile(archive_name, mode="x") as archive:
42+
for filename in input_files:
43+
archive.write(os.path.join(input_dir, filename), arcname=filename)
44+
else:
45+
import tarfile
46+
47+
archive_name = os.path.join(destination_dir, f"{archive_basename}.tar.gz")
48+
with tarfile.open(archive_name, "x:gz") as archive:
49+
for filename in input_files:
50+
archive.add(os.path.join(input_dir, filename), arcname=filename)
51+
52+
print(f"successfully packed mithril distribution into: {archive_name}")
53+
return archive_name
54+
55+
56+
def check_archive(archive, original_input_dir):
57+
print(f"checking archive ...")
58+
test_dir = "./unpack-test"
59+
shutil.unpack_archive(archive, test_dir)
60+
original_checksum = sha256sum(original_input_dir)
61+
archive_content_checksum = sha256sum(test_dir)
62+
if original_checksum != archive_content_checksum:
63+
print(
64+
f"mithril distribution checksum mismatch: before {original_checksum} != after {archive_content_checksum}"
65+
)
66+
exit(1)
67+
print("OK ! Checksum of the archive files matches original files")
68+
69+
shutil.rmtree(test_dir)
70+
71+
72+
def compute_sha256_checksum(archive):
73+
print(f"computing archive checksum...")
74+
archive_checksum = sha256sum(archive)
75+
checksum_filename = f"{archive}.sha256"
76+
with open(checksum_filename, "x") as f:
77+
f.write(archive_checksum)
78+
79+
80+
if __name__ == '__main__':
81+
parser = argparse.ArgumentParser()
82+
parser.add_argument("--input", type=dir_path, help="input folder which content will be archived", required=True)
83+
parser.add_argument("--dest", type=dir_path, help="destination folder for the archive, default to current folder",
84+
default="./")
85+
parser.add_argument("--version", help="version of the distribution to package", required=True)
86+
parser.add_argument("--target", help="target os & architecture of the package", required=True)
87+
args = parser.parse_args()
88+
89+
archive_path = build_archive(args.input, args.dest, archive_basename=f"mithril-{args.version}-{args.target}")
90+
check_archive(archive_path, args.input)
91+
compute_sha256_checksum(archive_path)

mithril-client/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#![warn(missing_docs)]
22

33
//! Define everything necessary to list, download, and validate snapshots from a
4-
//! [Mithril Aggregator](https://mithril.network/mithril-aggregator/doc/mithril_aggregator/index.html).
4+
//! [Mithril Aggregator](https://mithril.network/rust-doc/mithril_aggregator/index.html).
55
//!
66
//! To query an aggregator for snapshots & certificate use the [AggregatorHTTPClient] that implement
77
//! the [AggregatorHandler] trait.
88
//!
99
//! To list, download, and validate snapshots use the [Runtime].
1010
//! You must initialize it by giving it a CertificateVerifier, a ProtocolGenesisVerifier and a [AggregatorHandler], and a
11-
//! [Digester](https://mithril.network/mithril-common/doc/mithril_common/digesters/trait.Digester.html)
11+
//! [Digester](mithril_common::digesters::ImmutableDigester)
1212
//! implementations using the `with_xxx` methods.
1313
1414
mod aggregator;

mithril-client/src/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum RuntimeError {
3030
AggregatorHandler(#[from] AggregatorHandlerError),
3131

3232
/// Error raised when a CertificateRetrieverError tries to retrieve a
33-
/// [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
33+
/// [certificate](mithril_common::entities::Certificate)
3434
#[error("certificate retriever error: '{0}'")]
3535
CertificateRetriever(#[from] CertificateRetrieverError),
3636

@@ -39,7 +39,7 @@ pub enum RuntimeError {
3939
ImmutableDigester(#[from] ImmutableDigesterError),
4040

4141
/// Error raised when the digest stored in the signed message doesn't match the
42-
/// [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
42+
/// [certificate](mithril_common::entities::Certificate)
4343
/// hash.
4444
#[error("digest doesn't match error: '{0}'")]
4545
DigestDoesntMatch(String),

mithril-common/src/certificate_chain/certificate_retriever.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use mockall::automock;
1010
/// [CertificateRetriever] related errors.
1111
#[derive(Error, Debug)]
1212
pub enum CertificateRetrieverError {
13-
/// Error raised when a [CertificateRetriever] tries to retrieve a [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
13+
/// Error raised when a [CertificateRetriever] tries to retrieve a [Certificate]
1414
#[error("general error: '{0}'")]
1515
General(String),
1616
}
1717

18-
/// CertificateRetriever is in charge of retrieving a Certificate given its hash
18+
/// CertificateRetriever is in charge of retrieving a [Certificate] given its hash
1919
#[cfg_attr(test, automock)]
2020
#[async_trait]
2121
pub trait CertificateRetriever: Sync + Send {
22-
/// Get certificate details
22+
/// Get [Certificate] details
2323
async fn get_certificate_details(
2424
&self,
2525
certificate_hash: &str,

mithril-common/src/certificate_chain/certificate_verifier.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,24 @@ pub enum CertificateVerifierError {
3131
#[error("codec genesis error: '{0}'")]
3232
CodecGenesis(String),
3333

34-
/// Error raised when a CertificateRetriever tries to retrieve
35-
/// a [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
34+
/// Error raised when a CertificateRetriever tries to retrieve a [Certificate].
3635
#[error("certificate retriever error: '{0}'")]
3736
CertificateRetriever(#[from] CertificateRetrieverError),
3837

39-
/// Error raised when the Genesis Signature stored in a
40-
/// [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
41-
/// is invalid.
38+
/// Error raised when the Genesis Signature stored in a [Certificate] is invalid.
4239
#[error("certificate genesis error: '{0}'")]
4340
CertificateGenesis(#[from] ProtocolGenesisError),
4441

45-
/// Error raised when the hash stored in a
46-
/// [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
47-
/// doesn't match a recomputed hash.
42+
/// Error raised when the hash stored in a [Certificate] doesn't match a recomputed hash.
4843
#[error("certificate hash unmatch error")]
4944
CertificateHashUnmatch,
5045

51-
/// Error raised when validating the certificate chain if a previous
52-
/// [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
53-
/// hash isn't equal to the current certificate `previous_hash`.
46+
/// Error raised when validating the certificate chain if a previous [Certificate] hash isn't
47+
/// equal to the current certificate `previous_hash`.
5448
#[error("certificate chain previous hash unmatch error")]
5549
CertificateChainPreviousHashUnmatch,
5650

57-
/// Error raised when validating the certificate chain if the current
58-
/// [certificate](https://mithril.network/mithril-common/doc/mithril_common/entities/struct.Certificate.html)
51+
/// Error raised when validating the certificate chain if the current [Certificate]
5952
/// `aggregate_verification_key` doesn't match the previous `aggregate_verification_key` (if
6053
/// the certificates are on the same epoch) or the previous `next_aggregate_verification_key`
6154
/// (if the certificates are on different epoch).
@@ -67,7 +60,8 @@ pub enum CertificateVerifierError {
6760
CertificateChainInfiniteLoop,
6861
}
6962

70-
/// CertificateVerifier is the cryptographic engine in charge of verifying multi signatures and certificates
63+
/// CertificateVerifier is the cryptographic engine in charge of verifying multi signatures and
64+
/// [certificates](Certificate)
7165
#[cfg_attr(test, automock)]
7266
#[async_trait]
7367
pub trait CertificateVerifier: Send + Sync {

mithril-common/src/crypto_helper/cardano/key_certification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub enum ProtocolInitializerErrorWrapper {
7676
#[error("KES key cannot be updated for period {0}")]
7777
KesUpdate(KESPeriod),
7878
}
79-
/// Wrapper structure for [MithrilCore:StmInitializer](https://mithril.network/mithril-core/doc/mithril/stm/struct.StmInitializer.html).
79+
/// Wrapper structure for [MithrilCore:StmInitializer](mithril::stm::StmInitializer).
8080
/// It now obtains a KES signature over the Mithril key. This allows the signers prove
8181
/// their correct identity with respect to a Cardano PoolID.
8282
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -85,7 +85,7 @@ pub struct StmInitializerWrapper {
8585
kes_signature: Option<ProtocolSignerVerificationKeySignature>, // todo: The option is ONLY for a smooth transition. We have to remove this.
8686
}
8787

88-
/// Wrapper structure for [MithrilCore:KeyReg](https://mithril.network/mithril-core/doc/mithril/key_reg/struct.KeyReg.html).
88+
/// Wrapper structure for [MithrilCore:KeyReg](mithril::key_reg::KeyReg).
8989
/// The wrapper not only contains a map between `Mithril vkey <-> Stake`, but also
9090
/// a map `PoolID <-> Stake`. This information is recovered from the node state, and
9191
/// is used to verify the identity of a Mithril signer. Furthermore, the `register` function

mithril-common/src/crypto_helper/genesis.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub enum ProtocolGenesisError {
1414
SignatureVerification(#[from] SignatureError),
1515
}
1616

17-
/// A protocol Genesis Signer that is responsible for signing the [Genesis Certificate](https://mithril.network/doc/mithril/mithril-protocol/certificates#the-certificate-chain-design)
17+
/// A protocol Genesis Signer that is responsible for signing the
18+
/// [Genesis Certificate](https://mithril.network/doc/mithril/mithril-protocol/certificates#the-certificate-chain-design)
1819
#[derive(Debug, Serialize, Deserialize)]
1920
pub struct ProtocolGenesisSigner {
2021
pub(crate) secret_key: ProtocolGenesisSecretKey,
@@ -76,7 +77,8 @@ impl ProtocolGenesisSigner {
7677
}
7778
}
7879

79-
/// A protocol Genesis Verifier that is responsible for verifying the [Genesis Certificate](https://mithril.network/doc/mithril/mithril-protocol/certificates#the-certificate-chain-design)
80+
/// A protocol Genesis Verifier that is responsible for verifying the
81+
/// [Genesis Certificate](https://mithril.network/doc/mithril/mithril-protocol/certificates#the-certificate-chain-design)
8082
#[derive(Debug, Serialize, Deserialize, Clone)]
8183
pub struct ProtocolGenesisVerifier {
8284
pub(crate) verification_key: ProtocolGenesisVerificationKey,

mithril-common/src/crypto_helper/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Tools and types to abstract the use of the [Mithril Core library](https://mithril.network/mithril-core/doc/mithril/index.html)
1+
//! Tools and types to abstract the use of the [Mithril Core library](https://mithril.network/rust-doc/mithril/index.html)
22
33
mod cardano;
44
mod codec;

0 commit comments

Comments
 (0)