|
1 | | -name: "kubewarden-policy-gh-action-dependencies" |
2 | | -description: "Install all the binaries needed inside of GH action" |
| 1 | +name: "Get policy information" |
3 | 2 | branding: |
4 | 3 | icon: "package" |
5 | 4 | color: "blue" |
6 | 5 | inputs: |
7 | | - KWCTL_VERSION: |
8 | | - description: "kwctl release to be installed" |
9 | | - required: false |
10 | | - default: v1.31.0 |
11 | | - SYFT_VERSION: |
12 | | - description: "syft release to be installed" |
13 | | - required: false |
14 | | - default: "1.28.0" |
15 | | - arch: |
16 | | - description: "syft arch to be installed" |
17 | | - required: false |
18 | | - default: "linux_amd64" # windows_amd64, darwin_amd64 |
19 | | - BINARYEN_VERSION: |
20 | | - description: "binaryen release to be installed" |
21 | | - required: false |
22 | | - default: "116" |
| 6 | + policy-working-dir: |
| 7 | + description: "Policy folder" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | +outputs: |
| 11 | + policy-id: |
| 12 | + description: "Policy ID extract from the policy OCI URL" |
| 13 | + value: ${{ steps.policy-info.outputs.policy-id}} |
| 14 | + policy-rust-package: |
| 15 | + description: "Rust package name from Cargo.toml" |
| 16 | + value: ${{ steps.policy-info.outputs.policy-rust-package}} |
| 17 | + policy-language: |
| 18 | + description: "Policy programming language detected" |
| 19 | + value: ${{ steps.policy-info.outputs.policy-language}} |
| 20 | + policy-version: |
| 21 | + description: "Policy version from the metadata.yaml" |
| 22 | + value: ${{ steps.policy-info.outputs.policy-version}} |
| 23 | + policy-basename: |
| 24 | + description: "Policy directory basename" |
| 25 | + value: ${{ steps.policy-info.outputs.policy-basename}} |
23 | 26 | runs: |
24 | 27 | using: "composite" |
25 | 28 | steps: |
26 | | - - name: Install cosign |
27 | | - uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0 |
28 | | - - name: Install kwctl |
| 29 | + - name: Get policy info |
29 | 30 | shell: bash |
| 31 | + id: policy-info |
30 | 32 | run: | |
31 | | - #!/bin/bash |
32 | | - set -e |
33 | | -
|
34 | | - # Build name of gihub release asset |
35 | | - OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]' | sed 's/macos/darwin/') |
36 | | - ARCH=$(echo "${{ runner.arch }}" | sed -E 's/X64/x86_64/; s/ARM64/aarch64/') |
37 | | - ASSET="kwctl-${OS}-${ARCH}" |
38 | | -
|
39 | | - INSTALL_DIR=$HOME/.kwctl |
40 | | - RELEASE_URL="download/${{ inputs.KWCTL_VERSION }}" |
41 | | - [ "${{ inputs.KWCTL_VERSION }}" == "latest" ] && RELEASE_URL="latest/download" |
42 | | -
|
43 | | - mkdir -p $INSTALL_DIR |
44 | | - curl -sL https://github.com/kubewarden/kwctl/releases/$RELEASE_URL/$ASSET.zip -o $INSTALL_DIR/$ASSET.zip |
45 | | - unzip -o $INSTALL_DIR/$ASSET.zip -d $INSTALL_DIR |
46 | | - rm $INSTALL_DIR/$ASSET.zip |
47 | | -
|
48 | | - mv $INSTALL_DIR/$ASSET $INSTALL_DIR/kwctl |
49 | | - chmod 755 $INSTALL_DIR/kwctl |
50 | | - echo $INSTALL_DIR >> $GITHUB_PATH |
51 | | -
|
52 | | - $INSTALL_DIR/kwctl -V |
53 | | - - name: Install bats |
54 | | - shell: bash |
55 | | - run: sudo apt install -y bats |
56 | | - - name: Install SBOM generator tool |
57 | | - shell: bash |
58 | | - if: ${{ inputs.arch != 'windows_amd64' }} |
59 | | - run: | |
60 | | - #!/bin/bash |
61 | | - set -e |
62 | | -
|
63 | | - INSTALL_DIR=$HOME/.syft |
64 | | -
|
65 | | - mkdir -p $INSTALL_DIR |
66 | | -
|
67 | | - curl -sL https://github.com/anchore/syft/releases/download/v${{ inputs.SYFT_VERSION }}/syft_${{ inputs.SYFT_VERSION }}_${{ inputs.arch }}.tar.gz -o $INSTALL_DIR/syft.tar.gz |
68 | | - tar xvf $INSTALL_DIR/syft.tar.gz -C $INSTALL_DIR |
69 | | - rm $INSTALL_DIR/syft.tar.gz |
70 | | -
|
71 | | - echo $INSTALL_DIR >> $GITHUB_PATH |
72 | | -
|
73 | | - - name: Install SBOM generator tool |
74 | | - shell: bash |
75 | | - if: ${{ inputs.arch == 'windows_amd64' }} |
76 | | - run: | |
77 | | - #!/bin/bash |
78 | | - set -e |
79 | | -
|
80 | | - INSTALL_DIR=$HOME/.syft |
81 | | -
|
82 | | - mkdir -p $INSTALL_DIR |
83 | | -
|
84 | | - curl -sL https://github.com/anchore/syft/releases/download/v${{ inputs.SYFT_VERSION }}/syft_${{ inputs.SYFT_VERSION }}_windows_amd64.zip -o $INSTALL_DIR/syft.zip |
85 | | - unzip -n $INSTALL_DIR/syft.zip -d $INSTALL_DIR |
86 | | - rm $INSTALL_DIR/syft.zip |
87 | | -
|
88 | | - echo $INSTALL_DIR >> $GITHUB_PATH |
89 | | - - name: Install binaryen tool |
90 | | - shell: bash |
91 | | - run: | |
92 | | - #!/bin/bash |
93 | | - set -e |
94 | | -
|
95 | | - INSTALL_DIR=$HOME/.binaryen |
96 | | -
|
97 | | - mkdir -p $INSTALL_DIR |
98 | | -
|
99 | | - curl -sL https://github.com/WebAssembly/binaryen/releases/download/version_${{ inputs.BINARYEN_VERSION }}/binaryen-version_${{ inputs.BINARYEN_VERSION }}-x86_64-linux.tar.gz -o $INSTALL_DIR/binaryen.tar.gz |
100 | | - tar xvf $INSTALL_DIR/binaryen.tar.gz -C $INSTALL_DIR |
101 | | - mv $INSTALL_DIR/binaryen-version_${{ inputs.BINARYEN_VERSION }}/bin/* $INSTALL_DIR |
102 | | - rm $INSTALL_DIR/binaryen.tar.gz |
103 | | - rm -rf $INSTALL_DIR/binaryen-version_${{ inputs.BINARYEN_VERSION }} |
104 | | -
|
105 | | - echo $INSTALL_DIR >> $GITHUB_PATH |
106 | | - - name: Setup rust toolchain |
107 | | - run: | |
108 | | - rustup toolchain install stable --profile minimal --target wasm32-wasip1 |
109 | | - rustup override set stable |
110 | | - shell: bash |
111 | | - - name: Install tinygo |
112 | | - shell: bash |
113 | | - run: | |
114 | | - wget https://github.com/tinygo-org/tinygo/releases/download/v0.39.0/tinygo_0.39.0_amd64.deb |
115 | | - sudo dpkg -i tinygo_0.39.0_amd64.deb |
116 | | - - name: Install semver tool |
117 | | - shell: bash |
118 | | - run: | |
119 | | - INSTALL_DIR="$HOME"/.semver |
120 | | - mkdir -p "$INSTALL_DIR" |
121 | | - wget -O "$INSTALL_DIR"/semver https://github.com/fsaintjacques/semver-tool/raw/3.4.0/src/semver |
122 | | - chmod +x "$INSTALL_DIR"/semver |
123 | | - echo "$INSTALL_DIR" >> "$GITHUB_PATH" |
124 | | - - name: Install updatecli |
125 | | - uses: updatecli/updatecli-action@719e3592d124cbf826da704cbe557e1221dd4bba # v2.94.0 |
| 33 | + if [ ! -d "${{ inputs.policy-working-dir }}" ]; then |
| 34 | + echo "$policy_working_dir does not exist, policy not found"; |
| 35 | + exit 1; |
| 36 | + fi |
| 37 | +
|
| 38 | + policy_ociUrl=$(yq -r '.annotations."io.kubewarden.policy.ociUrl"' '${{ inputs.policy-working-dir}}/metadata.yml') |
| 39 | + policy_version=$(yq -r '.annotations."io.kubewarden.policy.version"' '${{ inputs.policy-working-dir}}/metadata.yml') |
| 40 | + policy_id=${policy_ociUrl##*/} |
| 41 | + policy_basename=$(basename ${{inputs.policy-working-dir}}) |
| 42 | + policy_language="" |
| 43 | + policy_rust_package="" |
| 44 | +
|
| 45 | + if [ -f '${{ inputs.policy-working-dir}}/Cargo.toml' ]; then |
| 46 | + policy_language="rust" |
| 47 | + policy_rust_package=$(sed -n 's,^name = \"\(.*\)\",\1,p' "${{ inputs.policy-working-dir}}/Cargo.toml") |
| 48 | + if [ '$policy_rust_package' == "" ]; then |
| 49 | + echo 'cannot get rust policy ${{ inputs.policy-working-dir }} package name'; |
| 50 | + exit 1; |
| 51 | + fi |
| 52 | + else |
| 53 | + # Currently this repository supports go and rust policies only |
| 54 | + policy_language="go" |
| 55 | + fi |
| 56 | +
|
| 57 | + echo "policy_language=$policy_language" |
| 58 | + echo "policy_rust_package=$policy_rust_package" |
| 59 | + echo "policy-id=$policy_id" |
| 60 | + echo "policy-version=$policy_version" |
| 61 | + echo "policy-basename=$policy_basename" |
| 62 | +
|
| 63 | + echo "policy-language=$policy_language" >> $GITHUB_OUTPUT |
| 64 | + echo "policy-rust-package=$policy_rust_package" >> $GITHUB_OUTPUT |
| 65 | + echo "policy-id=$policy_id" >> $GITHUB_OUTPUT |
| 66 | + echo "policy-version=$policy_version" >> $GITHUB_OUTPUT |
| 67 | + echo "policy-basename=$policy_basename" >> $GITHUB_OUTPUT |
0 commit comments