Skip to content

Commit fd24b52

Browse files
authored
Merge branch 'main' into feature/custom-test-rock-artifact-names
2 parents c221d28 + d4b2da7 commit fd24b52

175 files changed

Lines changed: 3524 additions & 3760 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/ISSUE_TEMPLATE/--onboarding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Request adding a new image to the OCI Factory
33
labels: "onboarding"
44
title: "[ONBOARDING] "
55
assignees:
6-
- cjdcordeiro
6+
- zhijie-yang
77
body:
88
- type: markdown
99
attributes:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Check Trivyignore
2+
description: 'Check if the trivyignore file is up to date'
3+
# Reference: https://github.com/canonical/operator-workflows/blob/c68a31ba2c953765654b2c04b6a760b65f9bfe83/.github/workflows/integration_test.yaml#L305
4+
5+
inputs:
6+
image-ref:
7+
description: 'The image to be scanned'
8+
required: true
9+
trivyignores:
10+
description: 'The path to the trivyignore file'
11+
required: true
12+
severity:
13+
description: 'The severity level to be scanned'
14+
default: 'HIGH,CRITICAL'
15+
skip-files:
16+
description: 'The files to be skipped'
17+
default: '/bin/pebble,/usr/bin/pebble'
18+
19+
runs:
20+
using: "composite"
21+
steps:
22+
- name: "Detect trivy installation"
23+
id: detect-trivy
24+
shell: bash
25+
run: |
26+
if ! command -v trivy &> /dev/null
27+
then
28+
echo "trivy-installed=false" >> $GITHUB_OUTPUT
29+
else
30+
echo "trivy-installed=true" >> $GITHUB_OUTPUT
31+
fi
32+
33+
- name: "Install trivy if not present"
34+
if: ${{ steps.detect-trivy.outputs.trivy-installed == 'false' }}
35+
uses: aquasecurity/setup-trivy@v0.2.4
36+
37+
- name: "Check unnecessary trivyignore entries"
38+
shell: bash
39+
run: |
40+
if [ -f "${{ inputs.trivyignores }}" ]
41+
then
42+
json_output=$(trivy image ${{ inputs.image-ref }} --severity ${{ inputs.severity }} -q \
43+
-f json --ignorefile "" --skip-files ${{ inputs.skip-files }} --exit-code 0)
44+
output=$(echo $json_output | jq -r '.Results[] | .Vulnerabilities | try to_entries[] | .value.VulnerabilityID' \
45+
2>/dev/null \
46+
|| echo "No vulnerabilities found")
47+
line=0
48+
while read CVE;
49+
do
50+
line=$(( line + 1 ))
51+
if [[ "$output" != *"$CVE"* && ! "$CVE" =~ ^#.* ]]
52+
then
53+
echo "::notice file=${{ inputs.trivyignores }},line=${line}::$CVE not present anymore, can be safely removed."
54+
fi
55+
done < ${{ inputs.trivyignores }}
56+
else
57+
echo "::warning::File ${{ inputs.trivyignores }} not found."
58+
fi

.github/actions/checkout/action.yaml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ inputs:
1515
submodules:
1616
description: 'Whether to checkout submodules. true|false|recursive according to actions/checkout@v4'
1717
default: 'false'
18-
github-server-url:
19-
description: 'The base URL for the GitHub instance that you are trying to clone from'
20-
default: 'https://github.com'
2118
token:
2219
description: "Github token for pulling from private repositories"
2320
default: ''
@@ -26,17 +23,17 @@ inputs:
2623
runs:
2724
using: "composite"
2825
steps:
26+
27+
- uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.x"
30+
2931
- name: Checkout
3032
shell: bash
3133
run: |
3234
3335
# If URL lacks the protocol, assume it is a github repo
34-
if [[ "${{ inputs.repository }}" =~ https?:// ]]
35-
then
36-
git_url="${{ inputs.repository }}"
37-
else
38-
git_url="${{ inputs.github-server-url }}/${{ inputs.repository }}.git"
39-
fi
36+
git_url="$(python3 ./src/shared/source_url.py "${{ inputs.repository }}")"
4037
4138
# if a token is provided, use it
4239
if ! [[ -z "${{ inputs.token }}" ]]; then
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Commit Releases JSON
2+
description: Commits the _releases.json file to the current repository.
3+
4+
inputs:
5+
image-name:
6+
description: 'OCI image name to fetch the releases JSON for'
7+
required: true
8+
releases-branch:
9+
description: 'Branch where the _releases.json file is located'
10+
required: false
11+
default: '_releases'
12+
directory:
13+
description: 'Directory where the _releases branch of the OCI Factory is checked out'
14+
default: oci-factory-releases
15+
required: false
16+
message:
17+
description: 'Commit message for the changes made to _releases.json'
18+
required: true
19+
email:
20+
description: 'Email address to use for the commit author'
21+
required: true
22+
actor:
23+
description: 'GitHub actor to use for the commit author'
24+
default: ${{ github.actor }}
25+
force:
26+
description: 'Force push the changes to the branch'
27+
required: false
28+
default: '0'
29+
30+
runs:
31+
using: "composite"
32+
steps:
33+
- name: commit _releases.json
34+
shell: bash
35+
run: |
36+
if [[ "$RUNNER_DEBUG" == "1" ]]; then
37+
set -x
38+
fi
39+
40+
if [ "${{ inputs.force }}" != "0" ]; then
41+
FORCE='--force'
42+
fi
43+
44+
cd ${{ inputs.directory }}
45+
46+
git config user.email "${{ inputs.email }}"
47+
git config user.name "${{ inputs.actor }}"
48+
49+
git add oci/${{ inputs.image-name }}/_releases.json
50+
git commit -m "${{ inputs.message }}"
51+
52+
git branch actions-temp-branch
53+
git fetch origin ${{ inputs.releases-branch }}
54+
git checkout ${{ inputs.releases-branch }}
55+
git merge actions-temp-branch
56+
git branch -d actions-temp-branch
57+
58+
git push origin ${{ inputs.releases-branch }} $FORCE
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Fetch Releases JSON
2+
description: Fetches the _releases.json file to the current repository.
3+
4+
inputs:
5+
image-name:
6+
description: 'OCI image name to fetch the releases JSON for'
7+
required: true
8+
releases-branch:
9+
description: 'Branch where the _releases.json file is located'
10+
required: false
11+
default: '_releases'
12+
directory:
13+
description: 'Directory where the _releases branch of the OCI Factory is checked out'
14+
default: oci-factory-releases
15+
16+
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Fetch _releases.json
22+
uses: actions/checkout@v4
23+
with:
24+
repository: canonical/oci-factory
25+
path: ${{ inputs.directory }}
26+
ref: ${{ inputs.releases-branch }}
27+
28+
- name: Copy _releases.json
29+
shell: bash
30+
run: |
31+
if [[ "$RUNNER_DEBUG" == "1" ]]; then
32+
set -x
33+
fi
34+
35+
if [[ "${{ inputs.image-name }}" = "*" ]]; then
36+
echo "Copying all _releases.json files"
37+
cd ${{ inputs.directory }}
38+
find . -name "_releases.json" -exec cp --parents {} $OLDPWD \;
39+
cd $OLDPWD
40+
elif [[ -f "${{ inputs.directory }}/oci/${{ inputs.image-name }}/_releases.json" ]]; then
41+
cp ${{ inputs.directory }}/oci/${{ inputs.image-name }}/_releases.json oci/${{ inputs.image-name }}/_releases.json
42+
fi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Install umoci
2+
description: Reusable action that installs umoci
3+
4+
inputs:
5+
umoci-version:
6+
description: The version of umoci to install
7+
default: "v0.4.7"
8+
umoci-binary:
9+
description: The name of the umoci binary to install
10+
default: "umoci.amd64"
11+
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Install umoci
17+
shell: bash
18+
run: |
19+
wget https://github.com/opencontainers/umoci/releases/download/${{ inputs.umoci-version }}/${{ inputs.umoci-binary }}
20+
sudo mv ${{ inputs.umoci-binary }} /usr/bin/umoci
21+
sudo chmod +x /usr/bin/umoci

.github/actions/validate-actor/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ runs:
3434
env:
3535
GITHUB_TOKEN: ${{ github.token }}
3636
run: |
37-
echo "The workflow is not triggered by a permitted user. Cancelling the workflow."
37+
source src/shared/logs.sh
38+
log_error "The workflow is not triggered by a permitted user. Cancelling the workflow."
3839
gh run cancel ${{ github.run_id }}

.github/actions/validate-actor/test-validate-actor.bats

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,32 @@ setup() {
1515
exit_status=$?
1616
} || true
1717
[[ $exit_status -eq 1 ]]
18-
[[ $(echo "${output}"| tail -n 1) = "The workflow is triggered by a user neither as a code owner nor a maintainer of the image img" ]]
18+
[[ $(echo "${output}" | tail -n 1) =~ "The workflow is triggered by a user neither as a code owner nor a maintainer of the image img" ]]
1919
}
2020

2121
@test "allows code owner" {
2222
output=$(${BATS_TEST_DIRNAME}/validate-actor.sh "code-owner" "true" $workdir "img" 2>&1)
23-
[[ $(echo "${output}"| tail -n 1) = "The workflow is triggered by code-owner as the code owner" ]]
23+
[[ $(echo "${output}" | tail -n 1) =~ "The workflow is triggered by code-owner as the code owner" ]]
2424
}
2525

2626
@test "allows image maintainer" {
2727
output=$(${BATS_TEST_DIRNAME}/validate-actor.sh "maintainer" "true" $workdir "img")
28-
[[ $(echo "${output}"| tail -n 1) = "The workflow is triggered by maintainer as a maintainer of the image img" ]]
28+
[[ $(echo "${output}" | tail -n 1) =~ "The workflow is triggered by maintainer as a maintainer of the image img" ]]
2929
}
3030

3131
@test "allows non-code-owner-non-maintainer user" {
3232
output=$(${BATS_TEST_DIRNAME}/validate-actor.sh "random" "false" $workdir "img")
33-
[[ $(echo "${output}"| tail -n 1) = "The workflow is not restricted to non-code-owner or non-maintainer users" ]]
33+
[[ $(echo "${output}" | tail -n 1) =~ "The workflow is not restricted to non-code-owner or non-maintainer users" ]]
3434
}
3535

3636
@test "user as both code-owner and maintainer is triggered as code owner" {
3737
echo -n " @maintainer" >> $workdir/CODEOWNERS
3838
output=$(${BATS_TEST_DIRNAME}/validate-actor.sh "maintainer" "true" $workdir "img")
39-
[[ $(echo "${output}"| tail -n 1) = "The workflow is triggered by maintainer as the code owner" ]]
39+
[[ $(echo "${output}" | tail -n 1) =~ "The workflow is triggered by maintainer as the code owner" ]]
4040
}
4141

4242
@test "teams are expanded to team members" {
4343
echo -n "@canonical/rocks" >> $workdir/CODEOWNERS
4444
output=$(${BATS_TEST_DIRNAME}/validate-actor.sh "ROCKsBot" "true" $workdir "img")
45-
[[ $(echo "${output}"| tail -n 1) = "The workflow is triggered by ROCKsBot as the code owner" ]]
45+
[[ $(echo "${output}" | tail -n 1) =~ "The workflow is triggered by ROCKsBot as the code owner" ]]
4646
}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#!/bin/bash -e
22

3+
source $(dirname $0)/../../../src/shared/logs.sh
4+
35
actor=$1
46
admin_only=$2
57
workspace=$3
68
image_path=$4
79

8-
echo "github.actor: ${actor}"
10+
log_debug "github.actor: ${actor}"
911
actor=$(echo "$actor" | sed 's/\[/\\[/g;s/\]/\\]/g') # Escape square brackets for actors like renovate[bot]
10-
echo "admin-only: ${admin_only}"
12+
log_debug "admin-only: ${admin_only}"
1113
if [[ ${admin_only} == true ]]; then
1214
exit_status=0
13-
echo "Expanding team mentions in the CODEOWNERS file"
15+
log_debug "Expanding team mentions in the CODEOWNERS file"
1416
codeowners_file=$(mktemp)
1517
cp ${workspace}/CODEOWNERS ${codeowners_file}
1618
teams=$(grep -oE '@[[:alnum:]_.-]+\/[[:alnum:]_.-]+' ${codeowners_file} || true | sort | uniq)
@@ -24,14 +26,14 @@ if [[ ${admin_only} == true ]]; then
2426
done
2527

2628
if grep -wq "@${actor}" ${codeowners_file}; then
27-
echo "The workflow is triggered by ${actor} as the code owner"
29+
log_info "The workflow is triggered by ${actor} as the code owner"
2830
elif cat ${workspace}/${image_path}/contacts.yaml | yq ".maintainers" | grep "\- " | grep -wq "${actor}"; then
29-
echo "The workflow is triggered by ${actor} as a maintainer of the image ${image_path}"
31+
log_info "The workflow is triggered by ${actor} as a maintainer of the image ${image_path}"
3032
else
31-
echo "The workflow is triggered by a user neither as a code owner nor a maintainer of the image ${image_path}"
33+
log_info "The workflow is triggered by a user neither as a code owner nor a maintainer of the image ${image_path}"
3234
exit_status=1
3335
fi
3436
exit ${exit_status}
3537
else
36-
echo "The workflow is not restricted to non-code-owner or non-maintainer users"
38+
log_info "The workflow is not restricted to non-code-owner or non-maintainer users"
3739
fi

.github/base_digests/20.04

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)