Skip to content

Commit bc6be22

Browse files
committed
Combine source builds
Combine the builds for WP.org and GitHub. The only input difference is which constants.php file is included. Then rector can run dead code elimination, which results in different code being included in each build.
1 parent 7d441cb commit bc6be22

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

flake.nix

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,36 @@
5353
in type == "directory" && base == "wp-org"
5454
|| pkgs.lib.hasInfix "/wp-org/" path;
5555
};
56-
staticDeployWpOrgSrc = runCommand "static-deploy-wp-org-src" {
57-
nativeBuildInputs = [ php phpPackages.composer ];
58-
} ''
59-
export PLUGIN_DIR="$TMPDIR/${name}"
60-
mkdir -p "$PLUGIN_DIR"
61-
cp -r --no-preserve=mode "${composerVendorDev}/vendor" .
62-
cp -r --no-preserve=mode "${staticDeploySrc}"/* .
56+
buildStaticDeploySrc = constantsFile:
57+
runCommand "static-deploy-source" {
58+
nativeBuildInputs = [ php phpPackages.composer ];
59+
} ''
60+
export PLUGIN_DIR="$TMPDIR/${name}"
61+
mkdir -p "$PLUGIN_DIR"
62+
cp -r --no-preserve=mode "${composerVendorDev}/vendor" .
63+
cp -r --no-preserve=mode "${staticDeploySrc}"/* .
6364
64-
# Lock certain constants and run rector to remove dead code
65-
cp ${wpOrgExtras}/wp-org/constants.php constants.php
66-
composer rector
65+
# Lock certain constants and run rector to remove dead code
66+
cp ${constantsFile} constants.php
67+
composer rector
6768
68-
mkdir -p "$out"
69-
cp -r src static-deploy.php uninstall.php views "$out"
70-
# Add release deps
71-
cp -r "${composerVendor}/vendor" "$out"
72-
'';
69+
rm -rf vendor
70+
cp -r --no-preserve=mode "${composerVendor}/vendor" .
71+
composer dump-autoload --no-dev --optimize
72+
73+
mkdir -p "$out"
74+
cp -r src static-deploy.php uninstall.php vendor views "$out"
75+
'';
76+
staticDeployWpOrgSrc =
77+
buildStaticDeploySrc "${wpOrgExtras}/wp-org/constants.php";
78+
staticDeployGitHubSrc =
79+
buildStaticDeploySrc "${staticDeploySrc}/constants.php";
7380
staticDeploy = runCommand "static-deploy" { } ''
74-
export PLUGIN_DIR="$TMPDIR/${name}"
75-
mkdir -p "$PLUGIN_DIR"
76-
cd "$PLUGIN_DIR"
77-
cp -r --no-preserve=mode "${composerVendor}"/* .
78-
cp -r --no-preserve=mode "${staticDeploySrc}"/* .
79-
${phpPackages.composer}/bin/composer dump-autoload --no-dev --optimize
80-
rm composer.json composer.lock
81+
mkdir "$TMPDIR/${name}"
82+
cd "$TMPDIR/${name}"
83+
ln -s "${staticDeployGitHubSrc}" "${name}"
8184
mkdir -p $out
82-
cd "$PLUGIN_DIR"/..
83-
${zip}/bin/zip -r -9 $out/static-deploy.zip "$(basename "$PLUGIN_DIR")"
85+
${zip}/bin/zip -r -9 $out/static-deploy.zip "${name}"
8486
'';
8587
staticDeployCheck = stdenv.mkDerivation {
8688
pname = "static-deploy-check";
@@ -115,6 +117,7 @@
115117
packages = {
116118
inherit composerVendorDev composerVendor staticDeploy;
117119
plugin = staticDeploy;
120+
pluginGitHubSrc = staticDeployGitHubSrc;
118121
pluginWpOrgSrc = staticDeployWpOrgSrc;
119122
};
120123
});

0 commit comments

Comments
 (0)