Skip to content

Commit c503c92

Browse files
committed
merge main
2 parents 6471cb2 + 8e8de68 commit c503c92

File tree

134 files changed

+6921
-2838
lines changed

Some content is hidden

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

134 files changed

+6921
-2838
lines changed

.github/actions/e2e/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ runs:
8989
- name: E2E
9090
shell: bash
9191
run: |
92-
SHA=${{ github.event.pull_request.head.sha || github.sha }}
93-
export SHORT_SHA=dev-${SHA::7}
92+
export SHORT_SHA=dev-${GITHUB_SHA::7}
93+
echo "${SHORT_SHA}"
9494
export LICENSE_ID=${{ inputs.license-id }}
9595
export AIRGAP_LICENSE_ID=${{ inputs.airgap-license-id }}
9696
export SNAPSHOT_LICENSE_ID=${{ inputs.snapshot-license-id }}

.github/actions/scan-image/action.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Scan image
2+
description: 'Scan a container image for vulnerabilities and optionally upload the results for GitHub code scanning'
3+
inputs:
4+
image-ref:
5+
description: 'The image to scan'
6+
required: true
7+
upload-sarif:
8+
description: 'Whether to upload the scan results as a SARIF file'
9+
required: false
10+
default: 'false'
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Get image id
16+
id: image-id
17+
shell: bash
18+
run: |
19+
image_id=$(${{github.action_path}}/image_id.sh '${{ inputs.image-ref }}')
20+
echo "image_id=$image_id" >> $GITHUB_OUTPUT
21+
22+
- name: Scan image
23+
uses: aquasecurity/[email protected]
24+
with:
25+
image-ref: '${{ inputs.image-ref }}'
26+
ignore-unfixed: true
27+
severity: CRITICAL,HIGH,MEDIUM
28+
exit-code: 1
29+
30+
- name: Output sarif
31+
uses: aquasecurity/[email protected]
32+
if: ${{ !cancelled() && inputs.upload-sarif == 'true' }}
33+
with:
34+
image-ref: '${{ matrix.image }}'
35+
format: sarif
36+
output: trivy-results.sarif
37+
ignore-unfixed: true
38+
severity: CRITICAL,HIGH,MEDIUM
39+
40+
- name: Upload sarif
41+
if: ${{ !cancelled() && inputs.upload-sarif == 'true' }}
42+
uses: github/codeql-action/upload-sarif@v3
43+
with:
44+
sarif_file: trivy-results.sarif
45+
category: 'image-scan:${{ steps.image-id.outputs.image_id }}'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ "$#" -ne 1 ] || [ "$1" == "" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
6+
echo "Usage: $0 <image_id>"
7+
exit 1
8+
fi
9+
10+
image_id="$1"
11+
image_id=$(echo "$image_id" | cut -d'@' -f1) # remove digest
12+
# make sure if there is only one colon it is not the port
13+
if ! echo "$image_id" | rev | cut -d':' -f1 | rev | grep -q '/' ; then
14+
image_id=$(echo "$image_id" | rev | cut -d':' -f2- | rev) # remove tag
15+
fi
16+
17+
echo -n "$image_id"

.github/dependabot.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ version: 2
33
updates:
44
- package-ecosystem: "gomod"
55
directory: "/"
6+
open-pull-requests-limit: 25
7+
schedule:
8+
interval: "weekly"
9+
day: "saturday"
610
labels:
711
- "dependencies"
812
- "go"
913
- "type::chore"
10-
schedule:
11-
interval: "weekly"
12-
open-pull-requests-limit: 25
14+
groups:
15+
security:
16+
update-types:
17+
- "patch"
1318

1419
- package-ecosystem: "github-actions"
1520
directory: "/"
@@ -19,3 +24,4 @@ updates:
1924
- "type::chore"
2025
schedule:
2126
interval: "weekly"
27+
day: "saturday"
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Automated PRs Manager
2+
3+
on:
4+
schedule:
5+
- cron: "0 */6 * * *" # every 6 hours
6+
workflow_dispatch: {}
7+
8+
jobs:
9+
list-prs:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
prs: ${{ steps.list-prs.outputs.prs }}
13+
env:
14+
GH_TOKEN: ${{ secrets.REPLICATED_GH_PAT }}
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: List PRs
20+
id: list-prs
21+
run: |
22+
set -euo pipefail
23+
24+
# list prs that are less than 24h old and exclude prs from forks
25+
26+
dependabot_prs=$(
27+
gh pr list \
28+
--author 'dependabot[bot]' \
29+
--json url,createdAt,headRefName,headRepository,headRepositoryOwner \
30+
-q '.[] | select((.createdAt | fromdateiso8601 > now - 24*60*60) and .headRepositoryOwner.login == "replicatedhq" and .headRepository.name == "embedded-cluster")'
31+
)
32+
33+
replicated_ci_prs=$(
34+
gh pr list \
35+
--author 'replicated-ci' \
36+
--json url,createdAt,headRefName,headRepository,headRepositoryOwner \
37+
-q '.[] | select((.createdAt | fromdateiso8601 > now - 24*60*60) and .headRepositoryOwner.login == "replicatedhq" and .headRepository.name == "embedded-cluster")'
38+
)
39+
40+
prs=$(echo "$dependabot_prs" "$replicated_ci_prs" | jq -sc '. | unique')
41+
echo "prs=$prs" >> "$GITHUB_OUTPUT"
42+
43+
process-prs:
44+
needs: list-prs
45+
runs-on: ubuntu-latest
46+
if: needs.list-prs.outputs.prs != '[]'
47+
strategy:
48+
matrix:
49+
pr: ${{ fromJson(needs.list-prs.outputs.prs) }}
50+
fail-fast: false
51+
max-parallel: 1
52+
env:
53+
GH_TOKEN: ${{ secrets.REPLICATED_GH_PAT }}
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ matrix.pr.headRefName }}
59+
60+
- name: Process PR
61+
run: |
62+
set -euo pipefail
63+
64+
echo "Checking status of tests..."
65+
run_id=$(gh run list --branch "${{ matrix.pr.headRefName }}" --workflow ci --limit 1 --json databaseId -q '.[0].databaseId')
66+
67+
# If there are still pending jobs, skip.
68+
69+
num_of_pending_jobs=$(gh run view "$run_id" --json jobs -q '.jobs[] | select(.conclusion == "") | .name' | wc -l)
70+
if [ "$num_of_pending_jobs" -gt 0 ]; then
71+
echo "There are still pending jobs. Skipping."
72+
exit 0
73+
fi
74+
75+
# If all tests and required checks passed, approve and merge.
76+
77+
if gh run view "$run_id" --json jobs -q '.jobs[] | select(.name == "validate-success") | .conclusion' | grep -q "success"; then
78+
if gh pr checks "${{ matrix.pr.url }}" --required; then
79+
echo "All tests and required checks passed. Approving and merging."
80+
echo -e "LGTM :thumbsup: \n\nThis PR was automatically approved and merged by the [automated-prs-manager](https://github.com/replicatedhq/embedded-cluster/blob/main/.github/workflows/automated-prs-manager.yaml) GitHub action" > body.txt
81+
gh pr review --approve "${{ matrix.pr.url }}" --body-file body.txt
82+
sleep 10
83+
gh pr merge --auto --squash "${{ matrix.pr.url }}"
84+
exit 0
85+
else
86+
echo "All tests passed, but some required PR checks have not. Skipping."
87+
exit 0
88+
fi
89+
fi
90+
91+
# If more than half of the e2e jobs are successful, re-run the failed jobs.
92+
93+
num_of_jobs=$(gh run view "$run_id" --json jobs -q '.jobs[] | select(.name | startswith("e2e")) | .name' | wc -l)
94+
num_of_successful_jobs=$(gh run view "$run_id" --json jobs -q '.jobs[] | select((.name | startswith("e2e")) and (.conclusion == "success")) | .name' | wc -l)
95+
96+
if [ "$num_of_successful_jobs" -gt $((num_of_jobs / 2)) ]; then
97+
echo "More than half of the e2e jobs are successful. Re-running failed jobs."
98+
gh run rerun "$run_id" --failed
99+
exit 0
100+
fi
101+
102+
echo "Less than half of the e2e jobs are successful. Skipping."

0 commit comments

Comments
 (0)