Skip to content

Commit 86327e3

Browse files
Merge branch 'next' into feature/FOUR-8522
2 parents 4154943 + 5a1a049 commit 86327e3

85 files changed

Lines changed: 4605 additions & 573 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/deploy-pm4.yml‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env:
2727
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
2828
BUILD_BASE: ${{ (contains(github.event.pull_request.body, 'ci:build-base') || github.event_name == 'schedule') && '1' || '0' }}
2929
BASE_IMAGE: ${{ secrets.REGISTRY_HOST }}/processmaker/processmaker:base
30-
K8S_BRANCH: ${{ contains(github.event.pull_request.body, 'ci:next') && 'next' || 'develop' }}
30+
K8S_BRANCH: ${{ contains(github.event.pull_request.body, 'ci:next') && 'next' || 'develop' }}
3131
concurrency:
3232
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
3333
cancel-in-progress: true
@@ -145,6 +145,76 @@ jobs:
145145
run: |
146146
echo "Instance URL: '${INSTANCE_URL}'"
147147
bash argocd/gh_comment.sh "$CI_PROJECT" "$pull_req_id"
148+
runAPITest:
149+
name: Run API Tests
150+
needs: [deployEKS]
151+
if: contains(github.event.pull_request.body, 'ci:api-test')
152+
runs-on: self-hosted
153+
steps:
154+
- name: Clone private repository
155+
run: |
156+
git clone --depth 1 -b eng "https://$GITHUB_TOKEN@github.com/ProcessMaker/argocd.git" argocd
157+
- name: Install pm4-tools
158+
run: |
159+
git clone --depth 1 -b "$K8S_BRANCH" "https://$GITHUB_TOKEN@github.com/ProcessMaker/pm4-k8s-distribution.git" pm4-k8s-distribution
160+
echo "versionHelm=$(grep "version:" "pm4-k8s-distribution/charts/enterprise/Chart.yaml" | awk '{print $2}' | sed 's/\"//g')" >> $GITHUB_ENV
161+
cd pm4-k8s-distribution/images/pm4-tools
162+
composer install --no-interaction
163+
cd ..
164+
- name: Configure AWS credentials
165+
uses: aws-actions/configure-aws-credentials@v1
166+
with:
167+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID1 }}
168+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY1 }}
169+
aws-region: ${{ secrets.AWS_REGION }}
170+
- name: Set up kubectl
171+
run: |
172+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
173+
chmod +x kubectl
174+
sudo mv kubectl /usr/local/bin/
175+
- name: Authenticate with Amazon EKS
176+
run: aws eks update-kubeconfig --region us-east-1 --name pm4-eng
177+
- name: Run the API tests
178+
run: |
179+
cd argocd
180+
deploy=$(echo -n ${{env.IMAGE_TAG}} | md5sum | head -c 10)
181+
namespace="ci-$deploy-ns-pm4"
182+
pr_body=$(jq -r .pull_request.body < "$GITHUB_EVENT_PATH" | base64)
183+
kubectl get pods --namespace=$namespace
184+
pod_names=$(kubectl get pods --namespace=$namespace --field-selector=status.phase=Running -o jsonpath="{.items[*].metadata.name}" | tr ' ' '\n' | grep -E '(-processmaker-scheduler-)')
185+
for pod in $pod_names; do
186+
code='
187+
has_processmaker=$(ls /opt | grep processmaker)
188+
has_sudo=$(ls /usr/bin | grep sudo)
189+
has_php=$(ls /usr/bin | grep php)
190+
if [ ! -z "$has_processmaker" ] && [ ! -z "$has_sudo" ] && [ ! -z "$has_php" ]; then
191+
echo $pr_body | base64 -d > /tmp/pr_body
192+
cd /opt/processmaker
193+
sudo -u nginx php artisan pm4-api-testing:run --body="$pr_body"
194+
else
195+
exit 1
196+
fi'
197+
kubectl exec -n $namespace $pod -- /bin/sh -c "pr_body='${pr_body}';${code}" | tee /tmp/comment.md && break || true
198+
done
199+
# Send the content of /tmp/comment.md as a PR comment
200+
MESSAGE=$(cat /tmp/comment.md)
201+
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
202+
GITHUB_REPOSITORY=${{ github.repository }}
203+
PR_NUMBER=$(jq -r .number < "$GITHUB_EVENT_PATH")
204+
205+
if [ -z "$PR_NUMBER" ]; then
206+
echo "The PR number is not available. Make sure this script is executed in a context of Pull Request."
207+
exit 1
208+
fi
209+
210+
URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments"
211+
json_payload=$(jq -n --arg message "$MESSAGE" '{"body": $message}')
212+
213+
curl -s \
214+
-H "Authorization: token ${GITHUB_TOKEN}" \
215+
-H "Accept: application/vnd.github.v3+json" \
216+
-d "$json_payload" \
217+
"${URL}"
148218
deleteEKS:
149219
name: Delete Instance
150220
if: github.event.action == 'closed'

‎ProcessMaker/Console/Commands/BuildScriptExecutors.php‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use ProcessMaker\Exception\InvalidDockerImageException;
99
use ProcessMaker\Facades\Docker;
1010
use ProcessMaker\Models\ScriptExecutor;
11+
use ProcessMaker\ScriptRunners\Base;
1112

1213
class BuildScriptExecutors extends Command
1314
{
@@ -157,6 +158,16 @@ public function buildExecutor()
157158
$command = Docker::command() .
158159
" build --build-arg SDK_DIR=./sdk -t {$image} -f {$packagePath}/Dockerfile.custom {$packagePath}";
159160

161+
$this->execCommand($command);
162+
163+
$isNayra = $scriptExecutor->language === Base::NAYRA_LANG;
164+
if ($isNayra) {
165+
Base::bringUpNayraExecutor($this, $image);
166+
}
167+
}
168+
169+
public function execCommand(string $command)
170+
{
160171
if ($this->userId) {
161172
$this->runProc(
162173
$command,
@@ -185,7 +196,7 @@ public function info($text, $verbosity = null)
185196
parent::info($text, $verbosity);
186197
}
187198

188-
private function sendEvent($output, $status)
199+
public function sendEvent($output, $status)
189200
{
190201
if ($this->userId) {
191202
event(new BuildScriptExecutor($output, $this->userId, $status));
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace ProcessMaker\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Artisan;
7+
use ProcessMaker\Models\ScriptExecutor;
8+
use ProcessMaker\ScriptRunners\Base;
9+
10+
class DockerExecutorPhpNayra extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'docker-executor-php-nayra:install';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Install and configure Docker Executor PHP Nayra';
25+
26+
/**
27+
* Execute the console command.
28+
*
29+
* @return mixed
30+
*/
31+
public function handle()
32+
{
33+
$exists = ScriptExecutor::where('language', Base::NAYRA_LANG)->exists();
34+
if (!$exists) {
35+
ScriptExecutor::install([
36+
'language' => Base::NAYRA_LANG,
37+
'title' => 'Nayra (µService)',
38+
'description' => 'Nayra (µService) Executor',
39+
'config' => '',
40+
]);
41+
}
42+
43+
// Build the instance image. This is the same as if you were to build it from the admin UI
44+
Artisan::call('processmaker:build-script-executor ' . Base::NAYRA_LANG . ' --rebuild');
45+
}
46+
}

‎ProcessMaker/Events/ActivityAssigned.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,15 @@ public function getProcessRequestToken()
6060
{
6161
return $this->processRequestToken;
6262
}
63+
64+
/**
65+
* Get data
66+
*/
67+
public function getData(): array
68+
{
69+
return [
70+
'payloadUrl' => $this->payloadUrl,
71+
'element_type' => $this->processRequestToken->element_type,
72+
];
73+
}
6374
}

‎ProcessMaker/Events/ProcessUpdated.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Foundation\Events\Dispatchable;
99
use Illuminate\Queue\SerializesModels;
1010
use ProcessMaker\Models\ProcessRequest;
11+
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
1112

1213
class ProcessUpdated implements ShouldBroadcastNow
1314
{
@@ -17,19 +18,28 @@ class ProcessUpdated implements ShouldBroadcastNow
1718

1819
public $event;
1920

21+
public $tokenId;
22+
23+
public $elementType;
24+
2025
private $processRequest;
2126

2227
/**
2328
* Create a new event instance.
2429
*
2530
* @return void
2631
*/
27-
public function __construct(ProcessRequest $processRequest, $event)
32+
public function __construct(ProcessRequest $processRequest, $event, TokenInterface $token = null)
2833
{
2934
$this->payloadUrl = route('api.requests.show', ['request' => $processRequest->getKey()]);
3035
$this->event = $event;
3136

3237
$this->processRequest = $processRequest;
38+
39+
if ($token) {
40+
$this->tokenId = $token->getId();
41+
$this->elementType = $token->element_type;
42+
}
3343
}
3444

3545
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace ProcessMaker\Helpers;
4+
5+
use Illuminate\Support\Facades\Auth;
6+
use ProcessMaker\Package\SavedSearch\Http\Controllers\SavedSearchController;
7+
use ProcessMaker\Package\SavedSearch\Models\SavedSearch;
8+
9+
class DefaultColumns
10+
{
11+
public static function get(string $key)
12+
{
13+
$defaultColumns = null;
14+
15+
// Get default Saved search config
16+
if (class_exists(SavedSearch::class)) {
17+
if ($key === SavedSearch::KEY_TASKS) {
18+
$type = SavedSearch::TYPE_TASK;
19+
} elseif ($key === SavedSearch::KEY_REQUESTS) {
20+
$type = SavedSearch::TYPE_REQUEST;
21+
} else {
22+
throw new \InvalidArgumentException('Invalid key: ' . $key);
23+
}
24+
25+
$defaultSavedSearch = SavedSearch::firstSystemSearchFor(
26+
Auth::user(),
27+
$key
28+
);
29+
if ($defaultSavedSearch) {
30+
$defaultColumns = SavedSearchController::adjustColumnsOf(
31+
$defaultSavedSearch->columns,
32+
$type
33+
);
34+
} else {
35+
$defaultColumns = null;
36+
}
37+
} else {
38+
$defaultColumns = null;
39+
}
40+
41+
return $defaultColumns;
42+
}
43+
}

‎ProcessMaker/Http/Controllers/Api/InboxRulesController.php‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Http\Request;
66
use Illuminate\Validation\Rule;
7+
use ProcessMaker\Helpers\DefaultColumns;
78
use ProcessMaker\Http\Controllers\Controller;
89
use ProcessMaker\Http\Resources\ApiCollection;
910
use ProcessMaker\Http\Resources\ApiResource;
@@ -23,7 +24,7 @@ public function index(Request $request)
2324
$order_direction = $request->input('order_direction', 'desc');
2425
$per_page = $request->input('per_page', 10);
2526
$filter = $request->input('filter', '');
26-
27+
2728
$query = InboxRule::query()->where('user_id', $request->user()->id);
2829

2930
if (!empty($filter)) {
@@ -50,6 +51,7 @@ public function show(InboxRule $inboxRule)
5051
if (empty($inboxRule->data)) {
5152
$inboxRuleArray['data'] = (object) [];
5253
}
54+
5355
return new ApiResource($inboxRuleArray);
5456
}
5557

@@ -67,13 +69,18 @@ public function store(Request $request)
6769
Rule::unique('inbox_rules')->where(function ($query) use ($request) {
6870
return $query->where('user_id', $request->user()->id);
6971
}),
70-
'alpha_spaces'
71-
]
72-
]);
72+
'alpha_spaces',
73+
],
74+
]);
75+
76+
$columns = $request->input('columns', null);
77+
if (!$columns) {
78+
$columns = DefaultColumns::get('tasks');
79+
}
7380

7481
// We always create a new saved search when we create a new inbox rule
7582
$savedSearch = InboxRule::createSavedSearch([
76-
'columns' => $request->input('columns'),
83+
'columns' => $columns,
7784
'advanced_filter' => $request->input('advanced_filter'),
7885
'pmql' => $request->input('pmql') ?? '',
7986
'user_id' => $request->user()->id,
@@ -98,7 +105,7 @@ public function store(Request $request)
98105
$inboxRule->applyToExistingTasks();
99106
}
100107

101-
return response([], 204);
108+
return response($inboxRule, 201);
102109
}
103110

104111
/**

0 commit comments

Comments
 (0)