Skip to content

Commit

Permalink
fix(npm_plugin): move pull logic into build to temporarily fix a
Browse files Browse the repository at this point in the history
regression that caused builds to fail on Launchpad builders
  • Loading branch information
liushuyu committed Sep 12, 2024
1 parent eda4bf7 commit 60f03f8
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions craft_parts/plugins/npm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ def get_build_environment(self) -> Dict[str, str]:
@override
def get_pull_commands(self) -> List[str]:
"""Return a list of commands to run during the pull step."""
return []

@override
def get_build_commands(self) -> List[str]:
"""Return a list of commands to run during the build step."""
cmd = []
options = cast(NpmPluginProperties, self._options)
if options.npm_include_node:
arch = self._get_architecture()
Expand All @@ -291,25 +297,30 @@ def get_pull_commands(self) -> List[str]:
self._node_binary_path = os.path.join(
self._part_info.part_cache_dir, file_name
)
return [
cmd += [
dedent(
f"""\
if [ ! -f "{self._node_binary_path}" ]; then
mkdir -p "{self._part_info.part_cache_dir}"
curl --retry 5 -s "{checksum_uri}" -o "{self._part_info.part_cache_dir}"/SHASUMS256.txt
curl --retry 5 -s "{node_uri}" -o "{self._node_binary_path}"
fi
cd "{self._part_info.part_cache_dir}"
pushd "{self._part_info.part_cache_dir}"
sha256sum --ignore-missing --strict -c SHASUMS256.txt
popd
"""
)
]
return []

@override
def get_build_commands(self) -> List[str]:
"""Return a list of commands to run during the build step."""
cmd = [
if self._node_binary_path is not None:
cmd += [
dedent(
f"""\
tar -xzf "{self._node_binary_path}" -C "${{CRAFT_PART_INSTALL}}/" \
--no-same-owner --strip-components=1
"""
),
]
cmd += [
dedent(
"""\
NPM_VERSION="$(npm --version)"
Expand All @@ -322,14 +333,4 @@ def get_build_commands(self) -> List[str]:
"""
)
]
if self._node_binary_path is not None:
cmd.insert(
0,
dedent(
f"""\
tar -xzf "{self._node_binary_path}" -C "${{CRAFT_PART_INSTALL}}/" \
--no-same-owner --strip-components=1
"""
),
)
return cmd

0 comments on commit 60f03f8

Please sign in to comment.