diff --git a/.github/workflows/vib-scheduled-verify.yaml b/.github/workflows/vib-scheduled-verify.yaml new file mode 100644 index 000000000000..c440c7745f7c --- /dev/null +++ b/.github/workflows/vib-scheduled-verify.yaml @@ -0,0 +1,61 @@ +name: Scheduled VIB +on: + schedule: + - cron: "?/15 * * * *" + workflow_dispatch: + inputs: + container: + description: Force VIB verification with this container + required: false +env: + CSP_API_URL: https://console.cloud.vmware.com + CSP_API_TOKEN: ${{ secrets.CSP_API_TOKEN }} + VIB_PUBLIC_URL: https://cp.bromelia.vmware.com +jobs: + get-container: + runs-on: ubuntu-latest + name: Get random container + outputs: + container: ${{ steps.get-container.outputs.container }} + flavors: ${{ steps.get-container.outputs.flavors }} + steps: + - uses: actions/checkout@v2 + name: Checkout Repository + with: + ref: main + - id: get-container + name: Get random container + run: | + container_name="${{ github.event.inputs.container }}" + if [ -z "$container_name" ]; then + containers=(containers/*) + random_index=$(( $RANDOM % ${#containers[@]} )) + container_name=$(echo "${containers[$random_index]}" | sed "s|containers/||g") + fi + flavors=(containers/${container_name}/*/*/) + flavors_json=$(printf "%s\n" "${flavors[@]}" | jq -R . | jq -cs .) + echo "::set-output name=container::${container_name}" + echo "::set-output name=flavors::${flavors_json}" + vib-verify: + runs-on: ubuntu-latest + needs: get-container + name: Verify + strategy: + matrix: + flavor: ${{ fromJSON(needs.get-container.outputs.flavors) }} + steps: + - uses: actions/checkout@v2 + name: Checkout Repository + with: + ref: main + - uses: vmware-labs/vmware-image-builder-action@main + name: Verify ${{ needs.get-container.outputs.container }} + with: + pipeline: vib-verify.json + env: + # Path with docker resources + VIB_ENV_PATH: ${{ matrix.flavor }} + # Container name + VIB_ENV_CONTAINER: ${{ needs.get-container.outputs.container }} + # TODO: Retrieve version + VIB_ENV_TAG: latest diff --git a/.github/workflows/vib-verify.yaml b/.github/workflows/vib-verify.yaml new file mode 100644 index 000000000000..b6e81586fc62 --- /dev/null +++ b/.github/workflows/vib-verify.yaml @@ -0,0 +1,88 @@ +name: VIB +on: # rebuild any PRs and main branch changes + pull_request_target: + types: + - opened + - reopened + - synchronize + - labeled + branches: + - master + - bitnami:master +env: + CSP_API_URL: https://console.cloud.vmware.com + CSP_API_TOKEN: ${{ secrets.CSP_API_TOKEN }} + VIB_PUBLIC_URL: https://cp.bromelia.vmware.com +jobs: + get-container: + runs-on: ubuntu-latest + name: Get modified containers + outputs: + container: ${{ steps.get-container.outputs.container }} + result: ${{ steps.get-container.outputs.result }} + flavors: ${{ steps.get-container.outputs.flavors }} + steps: + - id: get-container + name: Get modified containers + run: | + # Using the Github API to detect the files changed as git merge-base stops working when the branch is behind + # and jitterbit/get-changed-files does not support pull_request_target + URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" + files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL") + files_changed="$(echo $files_changed_data | jq -r '.[] | .filename')" + # Adding || true to avoid "Process exited with code 1" errors + containers_dirs_changed="$(echo "$files_changed" | xargs dirname | grep -o "containers/[^/]*" | sort | uniq || true)" + flavors=($(echo "$files_changed" | xargs dirname | grep -o "containers/.*/.*/[^/]*" | sort | uniq || true)) + flavors_json=$(printf "%s\n" "${flavors[@]}" | jq -R . | jq -cs .) + # Using grep -c as a better alternative to wc -l when dealing with empty strings." + num_containers_changed="$(echo "$containers_dirs_changed" | grep -c "containers" || true)" + + if [[ "$num_containers_changed" -eq "1" ]]; then + # Changes done in only one container -> OK + container_name=$(echo "$containers_dirs_changed" | sed "s|containers/||g") + echo "::set-output name=result::ok" + echo "::set-output name=container::${container_name}" + echo "::set-output name=flavors::${flavors_json}" + elif [[ "$num_containers_changed" -le "0" ]]; then + # Changes done in the containers/ folder but not inside a container subfolder -> SKIP + echo "::set-output name=error::No changes detected in containers. The rest of the tests will be skipped." + echo "::set-output name=result::skip" + else + # Changes done in more than container -> SKIP + echo -e "::set-output name=error::Changes detected in more than one container directory:\n${containers_dirs_changed}\nIt is strongly advised to change only one container in a PR. The rest of the tests will be skipped." + echo "::set-output name=result::skip" + fi + # Using actions/github-scripts because using exit 1 in the script above would not provide any output + # Source: https://github.community/t/no-output-on-process-completed-with-exit-code-1/123821/3 + - id: show-error + name: Show error + if: ${{ steps.get-container.outputs.result == 'fail' }} + uses: actions/github-script@v3 + with: + script: | + core.setFailed('${{ steps.get-container.outputs.error }}') + vib-verify: + runs-on: ubuntu-latest + needs: get-container + if: ${{ needs.get-container.outputs.result == 'ok' && contains(github.event.pull_request.labels.*.name, 'verify') }} + name: Verify + strategy: + matrix: + flavor: ${{ fromJSON(needs.get-container.outputs.flavors) }} + steps: + - uses: actions/checkout@v2 + name: Checkout Repository + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + - uses: vmware-labs/vmware-image-builder-action@main + name: Verify ${{ needs.get-container.outputs.container }} + with: + pipeline: vib-verify.json + env: + # Path with docker resources + VIB_ENV_PATH: ${{ matrix.flavor }} + # Container name + VIB_ENV_CONTAINER: ${{ needs.get-container.outputs.container }} + # TODO: Retrieve version + VIB_ENV_TAG: latest diff --git a/.vib/vib-verify.json b/.vib/vib-verify.json new file mode 100644 index 000000000000..5b661a56c772 --- /dev/null +++ b/.vib/vib-verify.json @@ -0,0 +1,28 @@ +{ + "phases": { + "package": { + "context": { + "resources": { + "url": "{SHA_ARCHIVE}", + "path": "{VIB_ENV_PATH}" + } + }, + "actions": [ + { + "action_id": "container-image-package", + "params": { + "application": { + "details": { + "name": "{VIB_ENV_CONTAINER}", + "tag": "{VIB_ENV_TAG}" + } + } + } + }, + { + "action_id": "container-image-lint" + } + ] + } + } +} \ No newline at end of file