Skip to content

Commit

Permalink
Merge pull request #38 from NordSecurity/lazy-post-actions
Browse files Browse the repository at this point in the history
Run post actions lazily
  • Loading branch information
tomaszklak authored Feb 25, 2025
2 parents 401ecac + ede4d17 commit 06fcfc4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ jobs:
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
uses: docker/setup-qemu-action@4574d27a4764455b42196d70a065bc6853246a25 # v3.4.0
with:
image: tonistiigi/binfmt:qemu-v7.0.0-28 # See: https://github.com/docker/setup-qemu-action/issues/198#issuecomment-2653791775

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3.9.0

- name: Build and push Docker image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0
with:
context: .
file: builders/${{ inputs.name }}/Dockerfile
Expand Down Expand Up @@ -90,6 +92,8 @@ jobs:

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
image: tonistiigi/binfmt:qemu-v7.0.0-28 # See: https://github.com/docker/setup-qemu-action/issues/198#issuecomment-2653791775

- name: Set up Docker Buildx
id: buildx
Expand Down
37 changes: 32 additions & 5 deletions rust_build_utils/rust_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import hashlib
import subprocess
import os
import shutil
Expand Down Expand Up @@ -417,20 +418,46 @@ def _cargo(

_build_packages(config, list(packages.keys()), extra_args, subcommand)

any_changed = False
for _, bins in packages.items():
for _, bin in bins.items():
# copies executable permissions
shutil.copy2(
project.get_cargo_path(config.rust_target, bin, config.debug),
distribution_dir,
cargo_bin_path = project.get_cargo_path(
config.rust_target, bin, config.debug
)
cksum = compute_sha256(cargo_bin_path)
cksum_path = f"{cargo_bin_path}.sha256"
cksum_old = (
(path.read_text().strip() or None)
if (path := Path(cksum_path)).exists()
else None
)
if cksum_old != cksum:
print(
f"{cargo_bin_path} has changed, new checksum: {cksum} vs old: {cksum_old}"
)
any_changed = True
with open(cksum_path, "w") as f:
f.write(cksum)
# copies executable permissions
shutil.copy2(cargo_bin_path, distribution_dir)

post_build(project, config, packages)
if any_changed:
post_build(project, config, packages)
else:
print("Skipping post build steps since none of the built binaries have changed")

if msvc_context is not None:
deactivate_msvc(msvc_context)


def compute_sha256(file_path):
sha256 = hashlib.sha256()
with open(file_path, "rb") as f:
while chunk := f.read(8192):
sha256.update(chunk)
return sha256.hexdigest()


def str_to_func_call(func_string):
func_array = func_string.split(".")
func = func_array[-1]
Expand Down

0 comments on commit 06fcfc4

Please sign in to comment.