Skip to content

Commit 6cbd311

Browse files
[Backport 4.4-7.16] Enhance and fix some GitHub actions workflows (#4692)
Enhance and fix some GitHub actions workflows (#4680) - Create a reusable workflow that uses the prebuit Docker images of development mode to mount the plugin source code and run a command. - Create a workflow to build a package on demand - Create a workflow to check the unit test with jest. Enhanced to use the expected platform. - Create a wildcard workflow to run a command in a development mode * Remove .github/workflows/check-code-integrity.yml Co-authored-by: Alex Ruiz Becerra <alejandro.ruiz.becerra@wazuh.com> (cherry picked from commit abee739) Co-authored-by: Antonio <34042064+Desvelao@users.noreply.github.com>
1 parent 613e3e0 commit 6cbd311

7 files changed

+231
-127
lines changed

.github/workflows/build.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow builds a production-ready package from the given Git reference.
2+
# Any branch, tag or commit SHA existing in the origin can be used.
3+
#
4+
# This workflow is based on the `dev-environment` workflow.
5+
6+
name: Build
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
reference:
12+
required: true
13+
type: string
14+
default: master
15+
description: Source code reference (branch, tag or commit SHA)
16+
17+
jobs:
18+
# Build an app package from the given source code reference.
19+
build:
20+
name: Build app package
21+
uses: ./.github/workflows/dev-environment.yml
22+
with:
23+
reference: ${{ github.event.inputs.reference }}
24+
command: 'yarn build'
25+
archive_name: 'wazuh-package'
26+
archive_path: './wazuh/build'
27+
secrets: inherit

.github/workflows/create-wazuh-packages.yml

-44
This file was deleted.

.github/workflows/dev-environment.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# This workflow downloads the source code at the given git reference
2+
# (branch, tag or commit), an sets up an environment (Kibana or OpenSearch)
3+
# to run this code and a command (build, test, ...).
4+
#
5+
# This workflow is used as a base for other workflows.
6+
7+
name: Base workflow - Environment
8+
9+
on:
10+
workflow_call:
11+
inputs:
12+
reference:
13+
required: true
14+
type: string
15+
default: master
16+
description: Source code reference (branch, tag or commit SHA).
17+
command:
18+
required: true
19+
type: string
20+
default: 'yarn build'
21+
description: Command to run in the environment
22+
docker_run_extra_args:
23+
type: string
24+
default: ''
25+
description: Additional paramaters for the docker run command.
26+
required: false
27+
artifact_name:
28+
type: string
29+
default: ''
30+
description: Artifact name (will be automatically suffixed with .zip)
31+
required: false
32+
artifact_path:
33+
type: string
34+
default: ''
35+
description: Folder to include in the archive.
36+
required: false
37+
notify_jest_coverage_summary:
38+
type: boolean
39+
default: false
40+
required: false
41+
42+
jobs:
43+
# Deploy the plugin in a development environment and run a command
44+
# using a pre-built Docker image, hosted in Quay.io.
45+
deploy_and_run_command:
46+
name: Deploy and run command
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Step 01 - Download the plugin's source code
50+
uses: actions/checkout@v3
51+
with:
52+
ref: ${{ inputs.reference }}
53+
path: wazuh
54+
55+
# Fix source code ownership so the internal user of the Docker
56+
# container is also owner.
57+
- name: Step 02 - Change code ownership
58+
run: sudo chown 1000:1000 -R wazuh;
59+
60+
- name: Step 03 - Set up the environment and run the command
61+
run: |
62+
# Detect which platform to use from source code
63+
platform=kbn;
64+
echo "Detecting platform [kbn, osd]...";
65+
find wazuh/opensearch_dashboards.json && { platform=osd; };
66+
echo "Platform is $platform";
67+
68+
# Read the platform version from the package.json file
69+
echo "Reading the platform version from the package.json...";
70+
# Support plugins whose version is defined under pluginPlatform or Kibana properties
71+
platform_version=$(jq -r '.pluginPlatform.version, .kibana.version | select(. != null)' wazuh/package.json);
72+
echo "Plugin platform version: $platform_version";
73+
74+
# Set the environment variable to the correct platform
75+
[ "$platform" = "kbn" ] && { docker_env_plugin_platform="KIBANA_VERSION"; };
76+
[ "$platform" = "osd" ] && { docker_env_plugin_platform="OPENSEARCH_DASHBOARDS_VERSION"; };
77+
78+
# Up the environment and run the command
79+
docker run -t --rm \
80+
-e ${docker_env_plugin_platform}=${platform_version} \
81+
-v `pwd`/wazuh:/home/node/kbn/plugins/wazuh \
82+
${{ inputs.docker_run_extra_args }} \
83+
quay.io/wazuh/${platform}-dev:${platform_version} \
84+
bash -c '
85+
yarn config set registry https://registry.yarnpkg.com;
86+
cd /home/node/kbn/plugins/wazuh && yarn && ${{ inputs.command }};
87+
'
88+
89+
- name: Step 04 - Upload artifact to GitHub
90+
if: ${{ inputs.artifact_name && inputs.artifact_path }}
91+
uses: actions/upload-artifact@v3
92+
with:
93+
name: ${{ inputs.artifact_name }}
94+
path: ${{ inputs.artifact_path }}
95+
96+
- name: Step 05 - Upload coverage results to GitHub
97+
if: ${{ inputs.notify_jest_coverage_summary && github.event_name == 'pull_request' }}
98+
uses: AthleticNet/comment-test-coverage@1.2.2
99+
with:
100+
token: ${{ secrets.GITHUB_TOKEN }}
101+
path: ./wazuh/target/test-coverage/coverage-summary.json
102+
title: "Code coverage (Jest)"

.github/workflows/playground.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow allows you to deploy a development environment and run any
2+
# npm / yarn available command for testing purposes.
3+
# Any branch, tag or commit SHA existing in the origin can be used.
4+
#
5+
# This workflow is based on the `dev-environment` workflow.
6+
7+
name: Playground
8+
9+
on:
10+
workflow_dispatch:
11+
inputs:
12+
reference:
13+
required: true
14+
type: string
15+
default: master
16+
description: Source code reference (branch, tag or commit SHA).
17+
command:
18+
required: true
19+
type: string
20+
default: 'yarn test:jest'
21+
description: Command to run in the environment
22+
docker_run_extra_args:
23+
type: string
24+
default: ''
25+
description: Additional paramaters for the docker run command.
26+
required: false
27+
artifact_name:
28+
type: string
29+
default: ''
30+
description: Artifact name (will be automatically suffixed with .zip)
31+
required: false
32+
artifact_path:
33+
type: string
34+
default: ''
35+
description: Folder to include in the archive.
36+
required: false
37+
38+
jobs:
39+
deploy_and_run_command:
40+
name: Deploy and run command
41+
uses: ./.github/workflows/dev-environment.yml
42+
with:
43+
reference: ${{ github.event.inputs.reference }}
44+
command: ${{ github.event.inputs.command }}
45+
docker_run_extra_args: ${{ github.event.inputs.docker_run_extra_args }}
46+
artifact_name: ${{ github.event.inputs.artifact_name }}
47+
artifact_path: ${{ github.event.inputs.artifact_path }}
48+
secrets: inherit

.github/workflows/unit-test.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This workflow run the unit tests of the app using Jest.
2+
# Any branch, tag or commit SHA existing in the origin can be used.
3+
#
4+
# This workflow is based on the `dev-environment` workflow.
5+
#
6+
# Jest is a third-party software https://jestjs.io/
7+
8+
9+
name: Run unit test
10+
11+
on:
12+
workflow_dispatch:
13+
inputs:
14+
reference:
15+
required: true
16+
type: string
17+
default: master
18+
description: Source code reference (branch, tag or commit SHA)
19+
command:
20+
required: true
21+
type: choice
22+
default: 'yarn test:jest'
23+
description: Select the type of test to run.
24+
options:
25+
- 'yarn test:jest'
26+
pull_request:
27+
branches:
28+
- 'master'
29+
- '*.*-*.*'
30+
- '*.*-*.*-wzd'
31+
32+
jobs:
33+
# Run unit tests with Jest
34+
test:
35+
name: Run unit tests
36+
uses: ./.github/workflows/dev-environment.yml
37+
with:
38+
reference: ${{ github.event.inputs.reference }}
39+
command: ${{ github.event.inputs.command || 'yarn test:jest' }}
40+
notify_jest_coverage_summary: true
41+
secrets: inherit

.github/workflows/wazuh-build-push-docker-action.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# This is a basic workflow that is manually triggered
2+
# @deprecated Official Wazuh images must be used instead: https://hub.docker.com/r/wazuh/wazuh
23

34
name: Manual workflow build and push docker image
45

@@ -12,24 +13,24 @@ on:
1213
type: boolean
1314
description: 'Build manager image'
1415
required: false
15-
wazuh-manager-version:
16+
wazuh-manager-version:
1617
description: 'Wazuh manager version'
1718
default: 'v4.3.8'
1819
required: false
19-
elastic-manager-version:
20+
elastic-manager-version:
2021
description: 'Elastic manager version'
2122
default: '7.17.0'
22-
required: false
23-
23+
required: false
24+
2425
build-agent-image:
2526
type: boolean
2627
description: 'Build agent image'
2728
required: false
28-
wazuh-agent-version:
29+
wazuh-agent-version:
2930
description: 'Wazuh agent version'
3031
default: 'v4.3.8'
3132
required: false
32-
elastic-agent-version:
33+
elastic-agent-version:
3334
description: 'Elastic manager version'
3435
default: '7.17.0'
3536
required: false
@@ -38,11 +39,11 @@ on:
3839
type: boolean
3940
description: 'Build cypress image'
4041
required: false
41-
ubuntu-cypress-branch:
42+
ubuntu-cypress-branch:
4243
description: 'Ubuntu cypress branch: Branch in which the image will be created, this branch must correspond to the wazuh-kibana-app project. It will take the tests written in the wazuh-kibana-app/test/cypress directory.'
4344
default: 'main'
4445
required: false
45-
image-cypress-version:
46+
image-cypress-version:
4647
description: 'Image cypress version'
4748
default: '3.0.0'
4849
required: false
@@ -58,7 +59,7 @@ jobs:
5859
uses: actions/checkout@v2
5960
with:
6061
path: wazuh-kibana-app
61-
- name: Step 02 - Login to quay.io
62+
- name: Step 02 - Login to quay.io
6263
run: |
6364
docker login -u=${{ secrets.QUAYIO_USERNAME }} -p=${{ secrets.QUAYIO_TOKEN }} quay.io
6465
- name: Step 03 - Build image
@@ -70,7 +71,7 @@ jobs:
7071
--build-arg FILEBEAT_WAZUH_TEMPLATE_URL=https://raw.githubusercontent.com/wazuh/wazuh/4.0/extensions/elasticsearch/7.x/wazuh-template.json \
7172
--build-arg FILEBEAT_WAZUH_MODULE_URL=https://packages.wazuh.com/4.x/filebeat/wazuh-filebeat-0.1.tar.gz .
7273
- name: Step 04 - Push image to quay.io
73-
run: |
74+
run: |
7475
docker push quay.io/wazuh/wazuh-manager-image:${{ github.event.inputs.wazuh-manager-version }}-${{ github.event.inputs.elastic-manager-version }}
7576
7677
job-build-agent-image:
@@ -91,7 +92,7 @@ jobs:
9192
docker build -t quay.io/wazuh/wazuh-agent-image:${{ github.event.inputs.wazuh-agent-version }} \
9293
--build-arg WAZUH_VERSION=${{ github.event.inputs.wazuh-agent-version }} .
9394
- name: Step 04 - Push image to quay.io
94-
run: |
95+
run: |
9596
docker push quay.io/wazuh/wazuh-agent-image:${{ github.event.inputs.wazuh-agent-version }}
9697
9798
job-build-cypress-image:
@@ -112,5 +113,5 @@ jobs:
112113
docker build -t quay.io/wazuh/wazuh-ubuntu-cypress:${{ github.event.inputs.image-cypress-version }} \
113114
--build-arg UBUNTU_CYPRESS_BRANCH=${{ github.event.inputs.ubuntu-cypress-branch }} .
114115
- name: Step 04 - Push image to quay.io
115-
run: |
116+
run: |
116117
docker push quay.io/wazuh/wazuh-ubuntu-cypress:${{ github.event.inputs.image-cypress-version }}

0 commit comments

Comments
 (0)