Skip to content

Commit 8708279

Browse files
authored
Merge branch 'main' into BRE-896-update-cd-workflows-for-semver
2 parents a9ecc80 + f8bc2ac commit 8708279

Some content is hidden

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

48 files changed

+1089
-298
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ charts/ @bitwarden/dept-shot
1212

1313
## BRE team owns these workflows ##
1414
.github/workflows/release.yml @bitwarden/dept-bre
15+
16+
# Docker-related files
17+
**/Dockerfile @bitwarden/team-appsec @bitwarden/dept-bre @bitwarden/dept-shot
18+
**/*.dockerignore @bitwarden/team-appsec @bitwarden/dept-bre @bitwarden/dept-shot
19+
**/entrypoint.sh @bitwarden/team-appsec @bitwarden/dept-bre @bitwarden/dept-shot
20+
**/docker-compose.yml @bitwarden/team-appsec @bitwarden/dept-bre @bitwarden/dept-shot

.github/config/sample-bw-secret.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ spec:
1212
authToken:
1313
secretName: bw-auth-token
1414
secretKey: token
15+
map:
16+
- bwSecretId: e30f88bd-9e9c-42ae-83b7-b155012da672
17+
secretKeyName: test__secret__1
18+
- bwSecretId: 9f66ccaf-998e-4e5d-9294-b155012db579
19+
secretKeyName: test__secret__2
20+
- bwSecretId: c2d703cb-9ce0-43b4-a0ab-b155012dc651
21+
secretKeyName: test__secret__3

.github/workflows/_build.yml

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ permissions:
1212
id-token: write
1313
packages: write
1414

15+
env:
16+
_CHART_NAME: ${{ inputs.chart_name }}
17+
1518
jobs:
1619
build:
1720
name: Build Helm charts
1821
runs-on: ubuntu-22.04
19-
environment: Production
2022
permissions:
2123
contents: read
2224
id-token: write
2325
steps:
2426
- name: Checkout repo
2527
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
28+
with:
29+
persist-credentials: false
30+
fetch-depth: 0
31+
fetch-tags: true
2632

2733
- name: Set up Helm
2834
uses: Azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5
@@ -59,6 +65,110 @@ jobs:
5965
- name: Log out from Azure
6066
uses: bitwarden/gh-actions/azure-logout@main
6167

68+
- name: Generate release notes
69+
id: release_notes
70+
env:
71+
GH_TOKEN: ${{ github.token }}
72+
run: |
73+
# Get the last release tag
74+
last_tag=$(gh release list --exclude-pre-releases --exclude-drafts --json "tagName" --limit 100 | jq -r --arg prefix "$_CHART_NAME" '.[] | select(.tagName | startswith($prefix)) | .tagName' | head -1)
75+
76+
if [ -z "$last_tag" ]; then
77+
echo "No previous release tag found, generating notes from initial commit"
78+
commit_range="$(git rev-list --max-parents=0 HEAD)..HEAD"
79+
else
80+
echo "Generating release notes since tag: $last_tag"
81+
commit_range="${last_tag}..HEAD"
82+
fi
83+
84+
changelog_file="charts/${_CHART_NAME}/CHANGELOG.md"
85+
chart_description=$(helm show chart "charts/${_CHART_NAME}" | yq -e '.description')
86+
chart_version=$(helm show chart "charts/${_CHART_NAME}" | yq -e '.version')
87+
88+
# Initialize arrays for tracking
89+
declare -A prs_found
90+
declare -A contributors
91+
declare -A new_contributors
92+
whats_changed=""
93+
94+
# Get all commits for this chart
95+
while IFS= read -r commit_hash; do
96+
commit_msg=$(git log -1 --pretty=format:"%s" "$commit_hash")
97+
commit_author=$(git log -1 --pretty=format:"%an" "$commit_hash")
98+
commit_email=$(git log -1 --pretty=format:"%ae" "$commit_hash")
99+
100+
# Try to extract PR number from commit message (e.g., "message (#123)" or "Merge pull request #123")
101+
pr_num=""
102+
if [[ $commit_msg =~ \(#([0-9]+)\) ]]; then
103+
pr_num="${BASH_REMATCH[1]}"
104+
elif [[ $commit_msg =~ Merge\ pull\ request\ #([0-9]+) ]]; then
105+
pr_num="${BASH_REMATCH[1]}"
106+
elif [[ $commit_msg =~ \#([0-9]+) ]]; then
107+
pr_num="${BASH_REMATCH[1]}"
108+
fi
109+
110+
# If we found a PR number and haven't processed it yet
111+
if [[ -n "$pr_num" ]] && [[ -z "${prs_found[$pr_num]}" ]]; then
112+
prs_found[$pr_num]=1
113+
114+
# Try to get PR details from GitHub API
115+
if pr_data=$(gh pr view "$pr_num" --json title,author,number,url 2>/dev/null); then
116+
pr_title=$(echo "$pr_data" | jq -r '.title')
117+
pr_author=$(echo "$pr_data" | jq -r '.author.login')
118+
pr_url=$(echo "$pr_data" | jq -r '.url')
119+
120+
# Add to what's changed
121+
whats_changed+="- ${pr_title} by [@${pr_author}](https://github.com/${pr_author}) in [#${pr_num}](${pr_url})"$'\n'
122+
123+
# Track contributor
124+
contributors[$pr_author]=1
125+
126+
# Check if this is a new contributor (first PR)
127+
pr_count=$(gh pr list --author "$pr_author" --state merged --limit 100 --json number | jq '. | length')
128+
if [[ "$pr_count" -eq 1 ]]; then
129+
new_contributors[$pr_author]="[#${pr_num}](${pr_url})"
130+
fi
131+
else
132+
# Fallback if API call fails - use commit info
133+
whats_changed+="- ${commit_msg} (${commit_hash:0:7})"$'\n'
134+
fi
135+
elif [[ -z "$pr_num" ]]; then
136+
# No PR found, add commit directly
137+
whats_changed+="- ${commit_msg} (${commit_hash:0:7})"$'\n'
138+
fi
139+
done < <(git log "$commit_range" --pretty=format:"%H" --reverse -- "charts/${_CHART_NAME}")
140+
141+
# Build the changelog content
142+
{
143+
echo "$chart_description"
144+
echo ""
145+
echo "## What's Changed"
146+
if [[ -n "$whats_changed" ]]; then
147+
echo "$whats_changed"
148+
else
149+
echo "No changes found for this chart."
150+
fi
151+
152+
# Add new contributors section if any
153+
if [[ ${#new_contributors[@]} -gt 0 ]]; then
154+
echo ""
155+
echo "## New Contributors"
156+
for contributor in "${!new_contributors[@]}"; do
157+
pr_link="${new_contributors[$contributor]}"
158+
echo "- [@${contributor}](https://github.com/${contributor}) made their first contribution in ${pr_link}"
159+
done
160+
fi
161+
162+
# Add full changelog link
163+
if [[ -n "$last_tag" ]]; then
164+
echo ""
165+
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${last_tag}...${_CHART_NAME}-${chart_version}"
166+
fi
167+
} > "$changelog_file"
168+
169+
echo "Release notes generated:"
170+
cat "$changelog_file"
171+
62172
- name: Package Helm chart
63173
id: helm_package
64174
run: |
@@ -67,12 +177,14 @@ jobs:
67177
--key "DevOps Team" \
68178
--keyring private.gpg \
69179
--passphrase-file .passphrase \
70-
charts/${{ inputs.chart_name }}
71-
PKG_NAME=$(ls *.tgz)
180+
"charts/${_CHART_NAME}"
181+
PKG_NAME=$(ls ./*.tgz)
72182
echo "name=$PKG_NAME" >> "$GITHUB_OUTPUT"
73183
74184
- name: Verify Helm chart
75-
run: helm verify ${{ steps.helm_package.outputs.name }} --keyring public.gpg
185+
env:
186+
_HELM_OUTPUT_NAME: ${{ steps.helm_package.outputs.name }}
187+
run: helm verify "${_HELM_OUTPUT_NAME}" --keyring public.gpg
76188

77189
- name: Upload Helm chart artifact
78190
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2

.github/workflows/_lint_chart.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Lint Chart (Common)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
chart_name:
7+
description: 'Name of the chart to lint'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: read
13+
14+
env:
15+
_CHART_PATH: charts/${{ inputs.chart_name }}
16+
17+
jobs:
18+
lint:
19+
name: Lint Helm chart
20+
runs-on: ubuntu-24.04
21+
permissions:
22+
contents: read
23+
steps:
24+
- name: Checkout repo
25+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
26+
with:
27+
fetch-depth: 0
28+
persist-credentials: false
29+
30+
- name: Set up Helm
31+
uses: Azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
32+
with:
33+
version: 'v3.19.0'
34+
35+
- name: Set up chart-testing
36+
uses: helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b # v2.7.0
37+
38+
- name: Run chart-testing (lint)
39+
env:
40+
CT_CHECK_VERSION_INCREMENT: false
41+
_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
42+
run: ct lint --charts "$_CHART_PATH"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and push kubectl image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
kubectl_version:
7+
description: "kubectl version"
8+
required: false
9+
default: "1.34"
10+
push:
11+
description: "Push image to GitHub Container Registry"
12+
required: false
13+
type: boolean
14+
default: true
15+
16+
jobs:
17+
build-docker:
18+
name: Build and push kubectl Docker image
19+
runs-on: ubuntu-24.04
20+
permissions:
21+
contents: read
22+
packages: write
23+
id-token: write
24+
steps:
25+
- name: Checkout Bitnami repo
26+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
27+
with:
28+
repository: bitnami/containers
29+
ref: main
30+
persist-credentials: false
31+
32+
- name: Login to GitHub Container Registry
33+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
34+
with:
35+
registry: ghcr.io
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Build and push kubectl image
40+
id: build-docker
41+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
42+
env:
43+
_KUBECTL_VERSION: ${{ inputs.kubectl_version }}
44+
_INPUT_PUSH: ${{ inputs.push }}
45+
with:
46+
context: ./bitnami/kubectl/${_KUBECTL_VERSION}/debian-12
47+
file: ./bitnami/kubectl/${_KUBECTL_VERSION}/debian-12/Dockerfile
48+
push: ${_INPUT_PUSH}
49+
tags: |
50+
ghcr.io/bitwarden/helm-charts/kubectl:latest
51+
ghcr.io/bitwarden/helm-charts/kubectl:${_KUBECTL_VERSION}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint self-host
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "charts/self-host/**"
7+
- ".github/workflows/lint-self-host.yml"
8+
- ".github/workflows/_lint_chart.yml"
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- "charts/self-host/**"
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
lint-self-host:
21+
name: Lint self-host chart
22+
uses: ./.github/workflows/_lint_chart.yml
23+
with:
24+
chart_name: self-host
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint sm-operator
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "charts/sm-operator/**"
7+
- ".github/workflows/lint-sm-operator.yml"
8+
- ".github/workflows/_lint_chart.yml"
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- "charts/sm-operator/**"
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
lint-sm-operator:
21+
name: Lint sm-operator chart
22+
uses: ./.github/workflows/_lint_chart.yml
23+
with:
24+
chart_name: sm-operator

.github/workflows/linter.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
with:
2929
fetch-depth: 0
3030
ref: main
31+
persist-credentials: false
3132

3233
- name: Log in to Azure
3334
uses: bitwarden/gh-actions/azure-login@main
@@ -83,7 +84,8 @@ jobs:
8384
- name: Release Helm chart
8485
if: ${{ github.event.inputs.release_mode != 'Dry Run' }}
8586
env:
86-
CR_GENERATE_RELEASE_NOTES: true
87+
CR_GENERATE_RELEASE_NOTES: false
88+
CR_RELEASE_NOTES_FILE: CHANGELOG.md # Relative path to use chart specific CHANGELOG.md from respective chart directory
8789
CR_MAKE_RELEASE_LATEST: true
8890
CR_SKIP_EXISTING: true
8991
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)