Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: metrics generation workflow #1481

Merged
merged 9 commits into from
Apr 4, 2024
Merged
35 changes: 35 additions & 0 deletions .github/workflows/update-go-versions.yml
@@ -0,0 +1,35 @@
---
name: Generate Metric files for new Go version

on:
workflow_dispatch:
schedule:
# Runs weekly during month of February and August
# Reference: https://go.dev/wiki/Go-Release-Cycle
- cron: '0 0 * 2,8 1'
SachinSahu431 marked this conversation as resolved.
Show resolved Hide resolved

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
21 changes: 21 additions & 0 deletions update-go-version.bash
@@ -0,0 +1,21 @@
#!/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
# New Go version gets appended at top of supported_go_versions.txt, and only top 3 versions are supported
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
make generate-go-collector-test-files
else
echo "No new Go version detected. Current Go version is: $current_version"
fi
SachinSahu431 marked this conversation as resolved.
Show resolved Hide resolved