Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,35 @@ jobs:
token: ${{ secrets.VM_BOT_GH_TOKEN }}
path: __vm-charts-repo

- name: Check operator chart app version
id: chart
env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
run: |
chart_app_version=$(yq -r '.appVersion // ""' charts/victoria-metrics-operator/Chart.yaml)
if [ -z "$chart_app_version" ]; then
echo "failed to read chart appVersion"
exit 1
fi

set +e
python3 ../__vm-operator-repo/hack/compare_versions.py "$chart_app_version" "$RELEASE_VERSION"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this script just produce stdout value and store it to >> $GITHUB_OUTPUT?
then it chould be used in subsequent steps if section

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first option but then I thought that some stdout may also leak there?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only data explicitly written to GITHUB_OUTPUT is a step output, it doesn't capture whole stdout.

exit_code=$?
set -e
if [ "$exit_code" -eq 0 ]; then
touch .update-crds
exit 0
fi

if [ "$exit_code" -ne 10 ]; then
exit "$exit_code"
fi

echo "Skipping CRD update for $release_version, chart appVersion is $chart_app_version"
working-directory: __vm-charts-repo

- name: Import GPG key
if: hashFiles('__vm-charts-repo/.update-crds') != ''
uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd # v7.0.0
id: import-gpg
with:
Expand All @@ -41,6 +69,7 @@ jobs:
workdir: __vm-charts-repo

- name: Update crd yaml in chart repo
if: hashFiles('__vm-charts-repo/.update-crds') != ''
id: update
run: |
cp ../__vm-operator-repo/config/crd/overlay/crd.descriptionless.yaml charts/victoria-metrics-operator/charts/crds/crds/crd.yaml
Expand All @@ -52,6 +81,7 @@ jobs:
working-directory: __vm-charts-repo

- name: Create Pull Request
if: hashFiles('__vm-charts-repo/.update-crds') != ''
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
add-paths: charts
Expand Down
31 changes: 31 additions & 0 deletions hack/compare_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
import sys


def parse_version(version):
"""Parses a version string into a tuple of integers."""
return tuple(
int(part) for part in version.removeprefix("v").split("-", 1)[0].split(".")
)


def main():
if len(sys.argv) != 3:
print(
"usage: compare_versions.py <current-version> <release-version>",
file=sys.stderr,
)
return 2

try:
current_version = parse_version(sys.argv[1])
release_version = parse_version(sys.argv[2])
except ValueError as e:
print(f"failed to parse version: {e}", file=sys.stderr)
return 2

return 0 if release_version >= current_version else 10


if __name__ == "__main__":
sys.exit(main())
Loading