Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance and fix some GitHub actions workflows #4680

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow calls to `reusable-dev-environment` workflow to run build a package

name: Build package

on:
workflow_dispatch:
inputs:
reference:
required: true
type: string
default: master
description: Branch/Tag/Commit SHA reference for the source code.

jobs:
build-package-on-dispatch:
name: Deploy a dev environment and build a package
uses: ./.github/workflows/reusable-dev-environment.yml
with:
reference: ${{ github.event.inputs.reference }}
command: 'yarn build'
archive_name: 'wazuh-package'
archive_path: './wazuh/build'
secrets: inherit
36 changes: 36 additions & 0 deletions .github/workflows/check-test-unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow calls to `reusable-dev-environment` workflow to run do unit tests

name: Check - Test - Unit

on:
workflow_dispatch:
inputs:
reference:
required: true
type: string
default: master
description: Branch/Tag/Commit SHA reference for the source code.
command:
required: true
type: choice
default: 'yarn test:jest'
description: Test. Select the test to run.
options:
- 'yarn test:jest'
pull_request:
branches:
- 'main'
- 'master'
- '*.*-*.*'
- '*.*-*.*-wzd'

jobs:
check-test-unit:
name: Deploy a dev environment and check the unit tests
uses: ./.github/workflows/reusable-dev-environment.yml
with:
reference: ${{ github.event.inputs.reference }}
command: ${{ github.event.inputs.command || 'yarn test:jest' }}
notify_jest_coverage_summary: true
secrets: inherit

41 changes: 41 additions & 0 deletions .github/workflows/command-dev-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow calls to `reusable-dev-environment` workflow to run some command in a development enviroment

name: Dev env - Command

on:
workflow_dispatch:
inputs:
reference:
required: true
type: string
default: master
description: Branch/Tag/Commit SHA reference for the source code.
command:
required: true
type: string
default: 'yarn test:jest'
description: Docker run. Introduce the command to run.
docker_run_extra_args:
type: string
default: ''
description: Docker run. Extra arguments passed to the docker run command.
archive_name:
type: string
default: ''
description: Archive. Name of the archived file.
archive_path:
type: string
default: ''
description: Archive. Files path to archive.

jobs:
command-dev-environment-on-dispatch:
name: Deploy a dev environment and run a command
uses: ./.github/workflows/reusable-dev-environment.yml
with:
reference: ${{ github.event.inputs.reference }}
command: ${{ github.event.inputs.command }}
docker_run_extra_args: ${{ github.event.inputs.docker_run_extra_args }}
archive_name: ${{ github.event.inputs.archive_name }}
archive_path: ${{ github.event.inputs.archive_path }}
secrets: inherit
44 changes: 0 additions & 44 deletions .github/workflows/create-wazuh-packages.yml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/reusable-dev-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This workflow downloads the source code, mount it as volume in a Docker container, installs the plugin dependencies and run a command

name: Reusable - Dev environment

on:
workflow_call:
inputs:
reference:
required: true
type: string
command:
required: true
type: string
docker_run_extra_args:
type: string
default: ''
archive_name:
type: string
default: ''
archive_path:
type: string
default: ''
notify_jest_coverage_summary:
type: boolean
default: false

jobs:
unit-test:
name: Deploy a plugin in a development environment and run a command using a pre-built Docker image
runs-on: ubuntu-22.04
steps:
- name: Step 01 - Download the plugin source code
uses: actions/checkout@v3
with:
ref: ${{ inputs.reference }}
path: wazuh
- name: Step 02 - Get the plugin platform, version and run commands in the Docker image
run: |
# Get the plugin platform and using the expected Docker images
plugin_platform=kbn;
echo "Getting the plugin platform...";
find wazuh/opensearch_dashboards.json && { plugin_platform=osd; };
echo "Plugin platform: $plugin_platform";

# Get the plugin platform version
echo "Getting the plugin platform version...";
# Support plugins whose version is defined udner pluginPlatform or kibana properties
plugin_platform_version=$(jq -r '.pluginPlatform.version, .kibana.version | select(. != null)' wazuh/package.json);
echo "Plugin platform version: $plugin_platform_version";

# Change the permissions of the plugin source code to use in the Docker image
sudo chown 1000:1000 -R wazuh;

# Run the Docker image, install the plugin dependencies and run the command
[ "$plugin_platform" = "kbn" ] && { docker_env_plugin_platform="KIBANA_VERSION"; };
[ "$plugin_platform" = "osd" ] && { docker_env_plugin_platform="OPENSEARCH_DASHBOARDS_VERSION"; };

docker run -t --rm -e "${docker_env_plugin_platform}=${plugin_platform_version}" -v "`pwd`/wazuh:/home/node/kbn/plugins/wazuh" ${{ inputs.docker_run_extra_args }} "quay.io/wazuh/${plugin_platform}-dev:${plugin_platform_version}" bash -c "yarn config set registry \"https://registry.yarnpkg.com\";cd /home/node/kbn/plugins/wazuh && yarn && ${{ inputs.command }}";
- name: Step 03 - Archive files
if: ${{ inputs.archive_name && inputs.archive_path }}
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.archive_name }}
path: ${{ inputs.archive_path }}
- name: Step 04 - Notify on GitHub comment
if: ${{ inputs.notify_jest_coverage_summary && github.event_name == 'pull_request' }}
uses: AthleticNet/comment-test-coverage@1.2.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: ./wazuh/target/test-coverage/coverage-summary.json
title: "Check - Unit - Jest coverage (`yarn test:jest`)"
71 changes: 0 additions & 71 deletions .github/workflows/wazuh-unit-test.yml

This file was deleted.