|
| 1 | +# 📚 Base Workflow - Environment Setup and Command Execution |
| 2 | +# |
| 3 | +# ⚡ Overview: |
| 4 | +# This workflow serves as a reusable base for other workflows, providing a |
| 5 | +# standardized environment to execute custom commands (e.g., `yarn build`, `yarn test`) |
| 6 | +# on source code fetched from a specified Git reference. |
| 7 | +# |
| 8 | +# 🚀 Key Features: |
| 9 | +# - 💻 Docker-Based Environment Setup: Prepares a Docker environment with OpenSearch Dashboards or Kibana. |
| 10 | +# - ⚙️ Custom Command Execution: Runs any specified command on the downloaded source code. |
| 11 | +# - 📦 Artifact and Coverage Upload: Uploads build artifacts and test coverage results to GitHub when configured. |
| 12 | +# |
| 13 | +# 🔗 Designed for: Easy integration and reuse by other workflows. |
| 14 | + |
| 15 | +name: Base workflow - Environment |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_call: |
| 19 | + inputs: |
| 20 | + reference: |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + default: main |
| 24 | + description: Git reference (branch, tag, or commit SHA) to build from. |
| 25 | + command: |
| 26 | + required: true |
| 27 | + type: string |
| 28 | + default: 'yarn build' |
| 29 | + description: Command to run in the environment. |
| 30 | + docker_run_extra_args: |
| 31 | + type: string |
| 32 | + default: '' |
| 33 | + description: Additional parameters for the docker run command. |
| 34 | + required: false |
| 35 | + artifact_name: |
| 36 | + type: string |
| 37 | + default: '' |
| 38 | + description: Artifact name (will be automatically suffixed with .zip). |
| 39 | + required: false |
| 40 | + artifact_path: |
| 41 | + type: string |
| 42 | + default: '' |
| 43 | + description: Folder to include in the archive. |
| 44 | + required: false |
| 45 | + notify_jest_coverage_summary: |
| 46 | + type: boolean |
| 47 | + default: false |
| 48 | + required: false |
| 49 | + |
| 50 | +jobs: |
| 51 | + # Deploy the plugin in a development environment and run a command |
| 52 | + # using a pre-built Docker image, hosted in Quay.io. |
| 53 | + deploy_and_run_command: |
| 54 | + name: Deploy and run command |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Step 01 - Download the plugin's source code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + repository: wazuh/wazuh-security-dashboards-plugin |
| 61 | + ref: ${{ inputs.reference }} |
| 62 | + path: wazuh-security-plugin |
| 63 | + |
| 64 | + # Fix source code ownership so the internal user of the Docker |
| 65 | + # container is also owner. |
| 66 | + - name: Step 02 - Change code ownership |
| 67 | + run: sudo chown 1000:1000 -R wazuh-security-plugin; |
| 68 | + |
| 69 | + - name: Step 03 - Set up the environment and run the command |
| 70 | + run: | |
| 71 | + # Read the platform version from the package.json file |
| 72 | + echo "Reading the platform version from the package.json..."; |
| 73 | + platform_version=$(jq -r '.opensearchDashboards.version | select(. != null)' wazuh-security-plugin/package.json); |
| 74 | + echo "Plugin platform version: $platform_version"; |
| 75 | +
|
| 76 | + # Up the environment and run the command |
| 77 | + docker run -t --rm \ |
| 78 | + -e OPENSEARCH_DASHBOARDS_VERSION=${platform_version} \ |
| 79 | + -v `pwd`/wazuh-security-plugin:/home/node/kbn/plugins/wazuh-security-plugin \ |
| 80 | + ${{ inputs.docker_run_extra_args }} \ |
| 81 | + quay.io/wazuh/osd-dev:${platform_version} \ |
| 82 | + bash -c ' |
| 83 | + yarn config set registry https://registry.yarnpkg.com; |
| 84 | + cd /home/node/kbn/plugins/wazuh-security-plugin && yarn && ${{ inputs.command }}; |
| 85 | + ' |
| 86 | + - name: Get the plugin version and format reference name |
| 87 | + run: | |
| 88 | + echo "githubReference=$(echo ${{ inputs.reference }} | sed 's/\//-/g')" >> $GITHUB_ENV |
| 89 | + echo "version=$(jq -r '.wazuh.version' $(pwd)/wazuh-security-plugin/package.json)" >> $GITHUB_ENV |
| 90 | + echo "revision=$(jq -r '.wazuh.revision' $(pwd)/wazuh-security-plugin/package.json)" >> $GITHUB_ENV |
| 91 | +
|
| 92 | + - name: Step 04 - Upload artifact to GitHub |
| 93 | + if: ${{ inputs.artifact_name && inputs.artifact_path }} |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + with: |
| 96 | + name: ${{ inputs.artifact_name }}_${{ env.version }}-${{ env.revision }}_${{ env.githubReference }}.zip |
| 97 | + path: ${{ inputs.artifact_path }} |
| 98 | + overwrite: true |
| 99 | + |
| 100 | + - name: Step 05 - Upload coverage results to GitHub |
| 101 | + if: ${{ inputs.notify_jest_coverage_summary && github.event_name == 'pull_request' }} |
| 102 | + uses: AthleticNet/[email protected] |
| 103 | + with: |
| 104 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + path: ./wazuh-security-plugin/target/test-coverage/coverage-summary.json |
| 106 | + title: 'Code coverage (Jest)' |
0 commit comments