Skip to content

Commit 69d540c

Browse files
authored
Merge pull request #4 from SUSE/PLAT-1431-release-drafter-workflow
PLAT-1431 Added release drafter workflow
2 parents a57f8dd + 51c7c0b commit 69d540c

File tree

4 files changed

+149
-116
lines changed

4 files changed

+149
-116
lines changed
Lines changed: 58 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,67 @@
1-
name: "kubewarden-policy-gh-action-dependencies"
2-
description: "Install all the binaries needed inside of GH action"
1+
name: "Get policy information"
32
branding:
43
icon: "package"
54
color: "blue"
65
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}}
2326
runs:
2427
using: "composite"
2528
steps:
26-
- name: Install cosign
27-
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
28-
- name: Install kwctl
29+
- name: Get policy info
2930
shell: bash
31+
id: policy-info
3032
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
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 'Policy Matrix'
2+
description: 'Retrieves the changed policies'
3+
outputs:
4+
policy_working_dirs:
5+
description: 'The directories of the changed policies'
6+
value: ${{ steps.calculate-policy-dirs.outputs.policy_working_dirs }}
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: calculate which policies need a CI job
11+
id: calculate-policy-dirs
12+
shell: bash
13+
run: |
14+
git remote -v
15+
16+
policies_working_dirs=($(find policies -maxdepth 2 -name Makefile -exec dirname '{}' \;))
17+
if [ "${{github.event_name}}" == "pull_request" ]; then
18+
# list only changes of files in `policies/`:
19+
git_files="$(git diff --no-color --find-renames --find-copies --name-only origin/${{ github.base_ref }} ${{ github.sha }} -- policies)"
20+
21+
# build policy_working_dirs:
22+
policies_working_dirs=($(echo "$git_files" | cut -d/ -f1,2 ))
23+
fi
24+
25+
declare -p policies_working_dirs # for debug
26+
policy_working_dirs=$(jq --compact-output --null-input '$ARGS.positional | map(select(. != "policies/Cargo.lock" and . != "policies/Cargo.toml" and . != "policies/go.mod" and . != "policies/go.sum")) | unique' --args -- "${policies_working_dirs[@]}")
27+
echo "policy_working_dirs=$policy_working_dirs"
28+
echo "policy_working_dirs=$policy_working_dirs" >> $GITHUB_OUTPUT
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release drafter auto labeler
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, reopened, synchronize, edited]
9+
# pull_request_target:
10+
# types: [opened, reopened, synchronize, edited]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
calculate-policy-matrix:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
policy_working_dirs: ${{ steps.policy-matrix.outputs.policy_working_dirs }}
20+
steps:
21+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
22+
with:
23+
fetch-depth: 0 # checkout all history to do git diff
24+
- name: 'Policy Matrix'
25+
id: policy-matrix
26+
uses: ./.github/actions/policy-matrix
27+
auto_labeler:
28+
uses: ./.github/workflows/reusable-auto-labeler.yaml
29+
needs: calculate-policy-matrix
30+
permissions:
31+
contents: write
32+
pull-requests: write
33+
if: ${{ needs.calculate-policy-matrix.outputs.policy_working_dirs != '[]' }}
34+
strategy:
35+
fail-fast: true
36+
matrix:
37+
policy-working-dir: ${{ fromJSON(needs.calculate-policy-matrix.outputs.policy_working_dirs) }}
38+
with:
39+
policy-working-dir: ${{ matrix.policy-working-dir}}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
policy-working-dir:
5+
description: "Working directory of the policy. Useful for repos with policies in folders"
6+
required: false
7+
type: string
8+
default: "."
9+
jobs:
10+
auto-labeler:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
14+
- name: Get policy metadata
15+
id: policy-info
16+
uses: ./.github/actions/get-policy-metadata
17+
with:
18+
policy-working-dir: "${{ inputs.policy-working-dir }}"
19+
- uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0
20+
with:
21+
config-name: "release-drafter-${{ steps.policy-info.outputs.policy-basename }}.yml"
22+
prerelease: ${{ contains(steps.policy-info.outputs.policy-version, '-alpha') || contains(steps.policy-info.outputs.policy-version, '-beta') || contains(steps.policy-info.outputs.policy-version, '-rc') }}
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)