diff --git a/pkgs/development/tools/continuous-integration/woodpecker/agent.nix b/pkgs/development/tools/continuous-integration/woodpecker/agent.nix new file mode 100644 index 000000000000..2865711d507c --- /dev/null +++ b/pkgs/development/tools/continuous-integration/woodpecker/agent.nix @@ -0,0 +1,17 @@ +{ lib, buildGoModule, callPackage, fetchFromGitHub }: +let + common = callPackage ./common.nix { }; +in +buildGoModule { + pname = "woodpecker-agent"; + inherit (common) version src ldflags postBuild; + vendorSha256 = null; + + subPackages = "cmd/agent"; + + CGO_ENABLED = 0; + + meta = common.meta // { + description = "Woodpecker Continuous Integration agent"; + }; +} diff --git a/pkgs/development/tools/continuous-integration/woodpecker/cli.nix b/pkgs/development/tools/continuous-integration/woodpecker/cli.nix new file mode 100644 index 000000000000..b5eda9efb917 --- /dev/null +++ b/pkgs/development/tools/continuous-integration/woodpecker/cli.nix @@ -0,0 +1,17 @@ +{ lib, buildGoModule, callPackage, fetchFromGitHub }: +let + common = callPackage ./common.nix { }; +in +buildGoModule { + pname = "woodpecker-cli"; + inherit (common) version src ldflags postBuild; + vendorSha256 = null; + + subPackages = "cmd/cli"; + + CGO_ENABLED = 0; + + meta = common.meta // { + description = "Command line client for the Woodpecker Continuous Integration server"; + }; +} diff --git a/pkgs/development/tools/continuous-integration/woodpecker/common.nix b/pkgs/development/tools/continuous-integration/woodpecker/common.nix new file mode 100644 index 000000000000..932fa934b1bc --- /dev/null +++ b/pkgs/development/tools/continuous-integration/woodpecker/common.nix @@ -0,0 +1,36 @@ +{ lib, fetchFromGitHub }: +let + version = "0.15.3"; + srcSha256 = "sha256-HOOH3H2SXLcT2oW/xL80TO+ZSI+Haulnznpb4hlCQow="; + yarnSha256 = "sha256-x9g0vSoexfknqLejgcNIigmkFnqYsmhcQNTOStcj68o="; +in +{ + inherit version yarnSha256; + + src = fetchFromGitHub { + owner = "woodpecker-ci"; + repo = "woodpecker"; + rev = "v${version}"; + sha256 = srcSha256; + }; + + postBuild = '' + cd $GOPATH/bin + for f in *; do + mv -- "$f" "woodpecker-$f" + done + cd - + ''; + + ldflags = [ + "-s" + "-w" + "-X github.com/woodpecker-ci/woodpecker/version.Version=${version}" + ]; + + meta = with lib; { + homepage = "https://woodpecker-ci.org/"; + license = licenses.asl20; + maintainers = with maintainers; [ ambroisie ]; + }; +} diff --git a/pkgs/development/tools/continuous-integration/woodpecker/frontend.nix b/pkgs/development/tools/continuous-integration/woodpecker/frontend.nix new file mode 100644 index 000000000000..267fdc13985a --- /dev/null +++ b/pkgs/development/tools/continuous-integration/woodpecker/frontend.nix @@ -0,0 +1,40 @@ +{ lib, callPackage, fetchFromGitHub, fetchYarnDeps, mkYarnPackage }: +let + common = callPackage ./common.nix { }; +in +mkYarnPackage { + pname = "woodpecker-frontend"; + inherit (common) version; + + src = "${common.src}/web"; + + packageJSON = ./woodpecker-package.json; + offlineCache = fetchYarnDeps { + yarnLock = "${common.src}/web/yarn.lock"; + sha256 = common.yarnSha256; + }; + + buildPhase = '' + runHook preBuild + + yarn build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + cp -R deps/woodpecker-ci/dist $out + echo "${common.version}" > "$out/version" + + runHook postInstall + ''; + + # Do not attempt generating a tarball for woodpecker-frontend again. + doDist = false; + + meta = common.meta // { + description = "Woodpecker Continuous Integration server frontend"; + }; +} diff --git a/pkgs/development/tools/continuous-integration/woodpecker/server.nix b/pkgs/development/tools/continuous-integration/woodpecker/server.nix new file mode 100644 index 000000000000..d97412649b5d --- /dev/null +++ b/pkgs/development/tools/continuous-integration/woodpecker/server.nix @@ -0,0 +1,27 @@ +{ lib, buildGoModule, callPackage, fetchFromGitHub, woodpecker-frontend }: +let + common = callPackage ./common.nix { }; +in +buildGoModule { + pname = "woodpecker-server"; + inherit (common) version src ldflags postBuild; + vendorSha256 = null; + + postPatch = '' + cp -r ${woodpecker-frontend} web/dist + ''; + + subPackages = "cmd/server"; + + CGO_ENABLED = 1; + + passthru = { + inherit woodpecker-frontend; + + updateScript = ./update.sh; + }; + + meta = common.meta // { + description = "Woodpecker Continuous Integration server"; + }; +} diff --git a/pkgs/development/tools/continuous-integration/woodpecker/update.sh b/pkgs/development/tools/continuous-integration/woodpecker/update.sh new file mode 100755 index 000000000000..3530ea6c46c6 --- /dev/null +++ b/pkgs/development/tools/continuous-integration/woodpecker/update.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p nix wget prefetch-yarn-deps nix-prefetch-github jq + +# shellcheck shell=bash + +if [ -n "$GITHUB_TOKEN" ]; then + TOKEN_ARGS=(--header "Authorization: token $GITHUB_TOKEN") +fi + +if [[ $# -gt 1 || $1 == -* ]]; then + echo "Regenerates packaging data for the woodpecker packages." + echo "Usage: $0 [git release tag]" + exit 1 +fi + +set -x + +cd "$(dirname "$0")" +version="$1" + +set -euo pipefail + +if [ -z "$version" ]; then + version="$(wget -O- "${TOKEN_ARGS[@]}" "https://api.github.com/repos/woodpecker-ci/woodpecker/releases?per_page=1" | jq -r '.[0].tag_name')" +fi + +# strip leading "v" +version="${version#v}" + +# Woodpecker repository +src_hash=$(nix-prefetch-github woodpecker-ci woodpecker --rev "v${version}" | jq -r .sha256) + +# Front-end dependencies +woodpecker_src="https://raw.githubusercontent.com/woodpecker-ci/woodpecker/v$version" +wget "${TOKEN_ARGS[@]}" "$woodpecker_src/web/package.json" -O woodpecker-package.json + +web_tmpdir=$(mktemp -d) +trap 'rm -rf "$web_tmpdir"' EXIT +pushd "$web_tmpdir" +wget "${TOKEN_ARGS[@]}" "$woodpecker_src/web/yarn.lock" +yarn_hash=$(prefetch-yarn-deps yarn.lock) +popd + +# Use friendlier hashes +src_hash=$(nix hash to-sri --type sha256 "$src_hash") +yarn_hash=$(nix hash to-sri --type sha256 "$yarn_hash") + +sed -i -E -e "s#version = \".*\"#version = \"$version\"#" common.nix +sed -i -E -e "s#srcSha256 = \".*\"#srcSha256 = \"$src_hash\"#" common.nix +sed -i -E -e "s#yarnSha256 = \".*\"#yarnSha256 = \"$yarn_hash\"#" common.nix diff --git a/pkgs/development/tools/continuous-integration/woodpecker/woodpecker-package.json b/pkgs/development/tools/continuous-integration/woodpecker/woodpecker-package.json new file mode 100644 index 000000000000..eb29431a0566 --- /dev/null +++ b/pkgs/development/tools/continuous-integration/woodpecker/woodpecker-package.json @@ -0,0 +1,63 @@ +{ + "name": "woodpecker-ci", + "author": "Woodpecker CI", + "version": "0.0.0", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + }, + "scripts": { + "start": "vite", + "build": "vite build", + "serve": "vite preview", + "lint": "eslint --max-warnings 0 --ext .js,.ts,.vue,.json .", + "formatcheck": "prettier -c .", + "format:fix": "prettier --write .", + "typecheck": "vue-tsc --noEmit", + "test": "echo 'No tests configured' && exit 0" + }, + "dependencies": { + "@kyvg/vue3-notification": "2.3.4", + "@meforma/vue-toaster": "1.2.2", + "ansi-to-html": "0.7.2", + "dayjs": "1.10.7", + "floating-vue": "2.0.0-beta.5", + "fuse.js": "6.4.6", + "humanize-duration": "3.27.0", + "javascript-time-ago": "2.3.10", + "node-emoji": "1.11.0", + "pinia": "2.0.0", + "vue": "v3.2.20", + "vue-router": "4.0.10" + }, + "devDependencies": { + "@iconify/json": "1.1.421", + "@types/humanize-duration": "3.27.0", + "@types/javascript-time-ago": "2.0.3", + "@types/node": "16.11.6", + "@types/node-emoji": "1.8.1", + "@typescript-eslint/eslint-plugin": "5.6.0", + "@typescript-eslint/parser": "5.6.0", + "@vitejs/plugin-vue": "1.9.4", + "@vue/compiler-sfc": "3.2.20", + "eslint": "7.32.0", + "eslint-config-airbnb-base": "15.0.0", + "eslint-config-airbnb-typescript": "16.1.0", + "eslint-config-prettier": "8.3.0", + "eslint-plugin-import": "2.25.3", + "eslint-plugin-prettier": "4.0.0", + "eslint-plugin-promise": "5.1.1", + "eslint-plugin-simple-import-sort": "7.0.0", + "eslint-plugin-vue": "7.18.0", + "eslint-plugin-vue-scoped-css": "1.3.0", + "prettier": "2.4.1", + "typescript": "4.4.4", + "unplugin-icons": "0.12.17", + "unplugin-vue-components": "0.17.0", + "vite": "2.6.13", + "vite-plugin-windicss": "1.4.12", + "vite-svg-loader": "3.0.0", + "vue-tsc": "0.28.10", + "windicss": "3.2.0" + } +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 04377cb57dc5..dcf088595606 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11546,6 +11546,14 @@ with pkgs; woff2 = callPackage ../development/web/woff2 { }; + woodpecker-agent = callPackage ../development/tools/continuous-integration/woodpecker/agent.nix { }; + + woodpecker-cli = callPackage ../development/tools/continuous-integration/woodpecker/cli.nix { }; + + woodpecker-server = callPackage ../development/tools/continuous-integration/woodpecker/server.nix { + woodpecker-frontend = callPackage ../development/tools/continuous-integration/woodpecker/frontend.nix { }; + }; + woof = callPackage ../tools/misc/woof { }; wootility = callPackage ../tools/misc/wootility {