From 76fa9807940a5fd0a4b69b33b8204a18cd8f4549 Mon Sep 17 00:00:00 2001 From: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> Date: Thu, 4 Apr 2024 11:55:38 +0530 Subject: [PATCH] feat: metrics generation workflow (#1481) * Scripts to check new Go version Signed-off-by: Sachin Sahu * Changes to test workflow Signed-off-by: Sachin Sahu * Update workflow to run based on Go release cycle Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> * Revert deleted files for testing workflow Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> * Revert deleted file for testing workflow Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> * Fix linting issue Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> * Update cron schedule to per month Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> * Update bash file Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> * Keep latest 3 Go versions in supported_go_versions Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> --------- Signed-off-by: Sachin Sahu Signed-off-by: Sachin Sahu <75629410+SachinSahu431@users.noreply.github.com> --- .github/workflows/update-go-versions.yml | 33 ++++++++++++++++++++++++ Makefile | 3 +-- update-go-version.bash | 23 +++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/update-go-versions.yml create mode 100644 update-go-version.bash diff --git a/.github/workflows/update-go-versions.yml b/.github/workflows/update-go-versions.yml new file mode 100644 index 0000000..f560564 --- /dev/null +++ b/.github/workflows/update-go-versions.yml @@ -0,0 +1,33 @@ +--- +name: Generate Metric files for new Go version + +on: + workflow_dispatch: + schedule: + - cron: '0 0 1 * *' + +jobs: + update-go-versions: + name: Update Go Versions and Generate Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Execute bash script + run: bash update-go-version.bash + + # If there are no changes (i.e. no diff exists with the checked-out base branch), + # no pull request will be created and the action exits silently. + - name: Create a Pull Request + if: github.event_name != 'pull_request' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Update Go Collector metrics for new Go version" + title: "chore: Update metrics for new Go version" + branch: update-metrics-for-new-go-version + base: main + draft: false + delete-branch: true diff --git a/Makefile b/Makefile index 6fa529a..7aef468 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,7 @@ test-short: deps common-test-short .PHONY: generate-go-collector-test-files file := supported_go_versions.txt -# take top 3 versions -VERSIONS := $(shell cat ${file} | head -n 3) +VERSIONS := $(shell cat ${file}) generate-go-collector-test-files: for GO_VERSION in $(VERSIONS); do \ docker run \ diff --git a/update-go-version.bash b/update-go-version.bash new file mode 100644 index 0000000..02e6aa6 --- /dev/null +++ b/update-go-version.bash @@ -0,0 +1,23 @@ +#!/bin/env bash + +set -e + +get_latest_versions() { + curl -s https://go.dev/VERSION?m=text | sed -E -n 's/go([0-9]+\.[0-9]+|\.[0-9]+).*/\1/p' +} + +current_version=$(cat supported_go_versions.txt | head -n 1) +latest_version=$(get_latest_versions) + +# Check for new version of Go, and generate go collector test files +# Add new Go version to supported_go_versions.txt, and remove the oldest version +if [[ ! $current_version =~ $latest_version ]]; then + echo "New Go version available: $latest_version" + echo "Updating supported_go_versions.txt and generating Go Collector test files" + sed -i "1i $latest_version" supported_go_versions.txt + sed -i '$d' supported_go_versions.txt + make generate-go-collector-test-files +else + echo "No new Go version detected. Current Go version is: $current_version" +fi +