Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoravong committed Sep 18, 2023
1 parent 2a82628 commit f39bf47
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 7 deletions.
File renamed without changes.
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ repos:
hooks:
- id: render
name: Create the rendered Kubernetes manifest resources for the project examples
entry: make repo-update dep-build render
entry: make render
language: system
pass_filenames: false
- id: changelog-ci-validate
name: Check for Changelog Entry if changes updated templates
entry: ./ci_scripts/chloggen-pr-validate.sh
language: script
pass_filenames: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,20 @@ chlog-new: chlog-available ## Creates or updates a YAML file under .chloggen
# make chlog-new CHANGE_TYPE=enhancement COMPONENT=agent NOTE="Add feature X" ISSUES='[4242]' FILENAME=add-feature-x SUBTEXT="Supports Y"
@$(CHLOGGEN_NEW_SCRIPT) || exit 1

.PHONY: chlog-validate
.PHONY: chlog-pr-validate
chlog-pr-validate: ## Validates changelog requirements for pull requests
./ci_scripts/chloggen-pr-validate.sh || exit 1

.PHONY: chlog-release-validate
chlog-validate: chlog-available ## Validates all YAML files in .chloggen
$(CHLOGGEN) validate || exit 1

.PHONY: chlog-preview
chlog-preview: chlog-available ## Provide a preview of the generated CHANGELOG.md file for a release
.PHONY: chlog-release-preview
chlog-preview: chlog-available chlog-release-validate ## Provide a preview of the generated CHANGELOG.md file for a release
$(CHLOGGEN) update --dry || exit 1

.PHONY: chlog-release
chlog-release: chlog-available chlog-validate ## Creates a release CHANGELOG.md entry from content in .chloggen
chlog-release: chlog-available chlog-release-validate ## Creates a release CHANGELOG.md entry from content in .chloggen
# Example Usage: make chlog-update VERSION=0.85.0
@export FORMATTED_VERSION="[$(VERSION)] - $$(date +'%Y-%m-%d')"; \
$(CHLOGGEN) update --version $$FORMATTED_VERSION || exit 1; \
Expand Down
44 changes: 44 additions & 0 deletions ci_scripts/chloggen-pr-validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Get the current branch name
current_branch=$(git rev-parse --abbrev-ref HEAD)

# Get the name of the remote repository (usually 'origin')
remote=$(git for-each-ref --format '%(upstream:short)' $(git symbolic-ref -q HEAD) | sed -Ee 's@^.*/([^/]*)@\1@')

# Initialize variables to keep track of changes
helm_chart_updated=0
rendered_manifests_updated=0
chloggen_file_present=0

# Only proceed if the remote repository is 'origin', indicating it's likely a PR
if [[ "$current_branch" == "main" || "$current_branch" == "master" ]]; then
# Loop through each file in the commit
for file in "$@"; do
# Check if any Helm chart templates are updated
if [[ $file == path/to/helm/chart/templates/* ]]; then
helm_chart_updated=1
fi

# Check if files under ./examples/*/rendered_manifests are updated
if [[ $file == ./examples/*/rendered_manifests/* ]]; then
rendered_manifests_updated=1
fi

# Check if a .chloggen file is present
if [[ $file == *.chloggen ]]; then
chloggen_file_present=1
fi
done

# If Helm chart or rendered manifests are updated, ensure a .chloggen file is present
if [[ $helm_chart_updated -eq 1 ]] || [[ $rendered_manifests_updated -eq 1 ]]; then
if [[ $chloggen_file_present -eq 0 ]]; then
echo "A changelog entry (.chloggen) is required for this commit."
exit 1
fi
fi
fi

echo "Successfully validated any required changelog entries exist for a PR."
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
app.kubernetes.io/version: "0.84.0"
app: splunk-otel-collector
component: otel-operator
chart: splunk-otel-collector-0.84.0
chart: splunk-otel-collector-0.84.0asdfasdf
release: default
heritage: Helm
app.kubernetes.io/component: otel-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
{{- include "splunk-otel-collector.commonLabels" . | nindent 4 }}
app: {{ template "splunk-otel-collector.name" . }}
component: otel-operator
chart: {{ template "splunk-otel-collector.chart" . }}
chart: {{ template "splunk-otel-collector.chart" . }}asdfasdf
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
app.kubernetes.io/component: otel-operator
Expand Down

0 comments on commit f39bf47

Please sign in to comment.