From 8ad3376e2a8bf9b247fdaa42ca5dbac0cca67acc Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Tue, 12 Nov 2019 17:04:32 +0100 Subject: [PATCH] Add a jobset for doing SDK releases (#164) ci/release.nix is called by the sdk-release jobset on hydra. It calls release-jobset.nix which returns the dfx-release and install-sh-release derivations but only when the git revision has been tagged with a release tag (v0.1.2). In that case the version in those derivations is set to the version in the tag ensuring that they get rebuild. --- ci/release.nix | 5 +++++ jobset.nix | 1 + nix/default.nix | 5 +++-- nix/overlays/dfinity-sdk.nix | 8 ++----- release-jobset.nix | 41 ++++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 ci/release.nix create mode 100644 release-jobset.nix diff --git a/ci/release.nix b/ci/release.nix new file mode 100644 index 0000000000..45835394eb --- /dev/null +++ b/ci/release.nix @@ -0,0 +1,5 @@ +{ supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ] +, scrubJobs ? true +, src ? null +}: +(import ../nix {}).ci ../release-jobset.nix { inherit supportedSystems scrubJobs src; } diff --git a/jobset.nix b/jobset.nix index 6eefd0d5cd..7c1224c7fd 100644 --- a/jobset.nix +++ b/jobset.nix @@ -2,6 +2,7 @@ , crossSystem ? null , config ? {} , overlays ? [] +, src ? null }: { inherit (import ./nix { inherit system crossSystem config overlays; }) dfinity-sdk; } diff --git a/nix/default.nix b/nix/default.nix index d176f8e130..f5b7da0234 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -4,6 +4,7 @@ , crossSystem ? null , config ? {} , overlays ? [] +, releaseVersion ? "latest" }: let # The `common` repo provides code (mostly Nix) that is used in the @@ -20,9 +21,9 @@ let else builtins.fetchGit { name = "common-sources"; url = "ssh://git@github.com/dfinity-lab/common"; - rev = "d5af3fda55af07de25f06fc46a2bf5f83424f02b"; + rev = "bbf39c31e08b4ab7db82f799a3e3c693a0fdced6"; }; in import commonSrc { inherit system crossSystem config; - overlays = import ./overlays ++ overlays; + overlays = import ./overlays ++ [ (_self: _super: { inherit releaseVersion; }) ] ++ overlays; } diff --git a/nix/overlays/dfinity-sdk.nix b/nix/overlays/dfinity-sdk.nix index 82b5e27c56..2af387da4f 100644 --- a/nix/overlays/dfinity-sdk.nix +++ b/nix/overlays/dfinity-sdk.nix @@ -29,11 +29,7 @@ in { public-folder = super.callPackage ../public.nix {}; }; - dfx-release = mkRelease "dfx" - # This is not the tagged version, but something afterwards - "latest" # once INF-495 is in, we will use: packages.rust-workspace.version - packages.rust-workspace-standalone - "dfx"; + dfx-release = mkRelease "dfx" self.releaseVersion packages.rust-workspace-standalone "dfx"; # The following prepares a manifest for copying install.sh # The release part also checks if the install.sh script is well formatted and has no shellcheck issues. @@ -41,7 +37,7 @@ in { # TODO: streamline mkRelease and this install-sh-release = let - version = "latest"; + version = self.releaseVersion; shfmtOpts = "-p -i 4 -ci -bn -s"; shellcheckOpts = "-s sh -S warning"; # We want to include the last revision of the install script into diff --git a/release-jobset.nix b/release-jobset.nix new file mode 100644 index 0000000000..d3577829ba --- /dev/null +++ b/release-jobset.nix @@ -0,0 +1,41 @@ +{ system ? builtins.currentSystem +, crossSystem ? null +, config ? {} +, overlays ? [] + +# Hydra will pass an argument to this jobset expression for every +# input of the jobset. In our case we only have a single `src` input +# representing the git checkout of the SDK repo: +# +# https://hydra.dfinity.systems/jobset/dfinity-ci-build/sdk#tabs-configuration +# +# This `src` argument contains information about the input for example: +# +# { outPath = builtins.storePath /nix/store/ma2dfyfyxdi6idbza6dyp34zhxh12nmm-source; +# inputType = "git"; +# uri = "git@github.com:dfinity-lab/sdk.git"; +# rev = "8882d8c97decbb3c33923ca9e8ab785621a61207"; +# revCount = 2514; +# gitTag = "8882d8c9"; # This defaults to the rev when there's no git tag. +# shortRev = "8882d8c9"; +# } +# +# See: https://github.com/NixOS/hydra/blob/037f6488f633dbf15ca2d93a0c117f6738c707fe/src/lib/Hydra/Plugin/GitInput.pm#L241:L248 +# +# We're primarily interested in the `src.gitTag` since that should trigger a release. +, src ? null +}: +let + # doRelease is true when the git tag is of the right release format like `0.1.2`. + doRelease = src != null && versionMatches != null; + + # versionMatch is `null` if `src.gitTag` is not of the right format like "1.23.456" + # and it's a list of matches like [ "1.23.456" ] when it is. + versionMatches = builtins.match "([0-9]+\.[0-9]+\.[0-9]+)" src.gitTag; + releaseVersion = if versionMatches == null then "latest" else builtins.head versionMatches; + + pkgs = import ./nix { inherit system config overlays releaseVersion; }; + +in pkgs.lib.optionalAttrs doRelease { + inherit (pkgs.dfinity-sdk) dfx-release install-sh-release; +}