Skip to content

Commit

Permalink
feat: Add an artifact auto-assignment example
Browse files Browse the repository at this point in the history
The example comes with a minimal test pipeline. It will be extended to
the other modules in another contribution.
  • Loading branch information
LeSuisse authored and Gashmob committed Feb 12, 2024
1 parent 1010f3e commit 3e3f021
Show file tree
Hide file tree
Showing 13 changed files with 1,840 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/CI.yml
@@ -0,0 +1,30 @@
name: Tests

permissions: read-all

on:
push:
branches:
- main
pull_request:

jobs:
tests:
strategy:
matrix:
tuleap_functions:
- "artifact-post-action/auto-assign"
runs-on: ubuntu-22.04
name: Tests (${{ matrix.tuleap_functions }})
defaults:
run:
working-directory: ${{ matrix.tuleap_functions }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: cachix/install-nix-action@6004951b182f8860210c8d6f0d808ec5b1a33d28 # v25
- name: Prepare
run: nix-shell --run "make prepare"
- name: Tests
run: nix-shell --pure --run "make tests"
- name: Build
run: nix-shell --pure --run "make build"
2 changes: 2 additions & 0 deletions artifact-post-action/auto-assign/.gitignore
@@ -0,0 +1,2 @@
dist/
node_modules/
14 changes: 14 additions & 0 deletions artifact-post-action/auto-assign/Makefile
@@ -0,0 +1,14 @@
SHELL=/usr/bin/env bash -euo pipefail -c

.PHONY: prepare
prepare:
pnpm install --frozen-lockfile

.PHONY: tests
tests:
pnpm run typecheck
pnpm run test

.PHONY: build
build:
pnpm run build
45 changes: 45 additions & 0 deletions artifact-post-action/auto-assign/README.md
@@ -0,0 +1,45 @@
# Artifact post action: automatically assign a contributor

This Function automatically assigns the creator of an artifact as the contributor/assignee.
The contributor/assignee is only set when the artifact is created if no other contributors
have been designed.

The code expects the tracker to have the [contributor/assignee semantic](https://docs.tuleap.org/user-guide/trackers/administration/configuration/semantics.html#contributor-assignee) set.

## How to test

First you need to run `nix-shell` to have all needed tools.

Then build the Tuleap Function with:
```shell
make prepare
make build
```

You can then run it with:

```shell
wasmtime run ./dist/function.wasm < sample.json
```

You can run the typechecking and unit tests with:

```shell
make tests
```

## How to use

Create a tracker and define the [contributor/assignee semantic](https://docs.tuleap.org/user-guide/trackers/administration/configuration/semantics.html#contributor-assignee).

Then build the function:

```shell
make prepare
make build
```

Then upload the binary result file (`dist/function.wasm`) to your Tracker
administration (Administration > Workflow > Tuleap Functions).

And finally, create an artifact, shortly after the creation, the contributor field will automatically be set to yourself.
46 changes: 46 additions & 0 deletions artifact-post-action/auto-assign/javy.nix
@@ -0,0 +1,46 @@
# TODO:
# * build from sources
# * upstream to nixpkgs
{ stdenv
, lib
, fetchurl
, autoPatchelfHook
, gzip
}:

stdenv.mkDerivation rec {
pname = "javy";
version = "1.4.0";

src = fetchurl {
url = "https://github.com/bytecodealliance/javy/releases/download/v${version}/javy-x86_64-linux-v${version}.gz";
hash = "sha256-NZIzT8BdtgKiE3RbePWEY1E5TWe9mr2LSRhhmxzWzd8=";
};

nativeBuildInputs = [
autoPatchelfHook
gzip
];

buildInputs = [
stdenv.cc.cc.lib
];

unpackPhase = ''
runHook preUnpack
gzip -cd "${src}" > javy
runHook postUnpack
'';

installPhase = ''
runHook preInstall
install -m755 -D javy $out/bin/javy
runHook postInstall
'';

meta = with lib; {
homepage = "https://github.com/bytecodealliance/javy";
description = "JS to WebAssembly toolchain";
license = licenses.asl20;
};
}
24 changes: 24 additions & 0 deletions artifact-post-action/auto-assign/package.json
@@ -0,0 +1,24 @@
{
"name": "@tuleap/functions-post-action-auto-assign",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "pnpm run build:bundle && pnpm run build:js2wasm && pnpm run build:wasmopt",
"build:bundle": "esbuild src/main.ts --platform=node --bundle --target=es2022 --minify --outfile=dist/function.js",
"build:js2wasm": "javy compile ./dist/function.js -o ./dist/function-unoptimized.wasm",
"build:wasmopt": "wasm-opt -O2 ./dist/function-unoptimized.wasm -o ./dist/function.wasm",
"typecheck": "tsc --noEmit",
"test": "vitest run"
},
"keywords": [],
"author": "Enalean Team",
"license": "MIT",
"devDependencies": {
"esbuild": "^0.20.0",
"typescript": "^5.3.3",
"vitest": "^1.2.2"
},
"dependencies": {
"javy": "^0.1.2"
}
}

0 comments on commit 3e3f021

Please sign in to comment.