Auto-update more versions (#2351)
Co-authored-by: Patrice Chalin <chalin@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
parent
f2650837d0
commit
0a84a68950
|
|
@ -1,27 +0,0 @@
|
|||
name: Check collector version
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 1 * * *'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Make sure that the workflow does not run on forks (add yourself as exception if you work on the workflow)
|
||||
if: github.repository_owner == 'open-telemetry' || github.repository_owner == 'svrnm'
|
||||
name: Check collector version
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Auto-update
|
||||
run: ./.github/workflows/scripts/check-collector-version.sh
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GIT_AUTHOR_NAME: opentelemetrybot
|
||||
GIT_COMMITTER_NAME: opentelemetrybot
|
||||
|
||||
# Set opentelemetrybot's email, otherwise CLA checks will fail
|
||||
GIT_AUTHOR_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com
|
||||
GIT_COMMITTER_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
name: Auto-update versions
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# hourly at minute 10
|
||||
- cron: "10 * * * *"
|
||||
|
||||
jobs:
|
||||
auto-update-versions:
|
||||
name: Auto-update versions
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Use CLA approved github bot
|
||||
run: |
|
||||
git config user.name opentelemetrybot
|
||||
git config user.email 107717825+opentelemetrybot@users.noreply.github.com
|
||||
|
||||
- name: Auto-update
|
||||
run: |
|
||||
.github/workflows/scripts/auto-update-version.sh "opentelemetry-collector-releases" "collectorVersion" "content/en/docs/collector/_index.md"
|
||||
git reset --hard origin/main
|
||||
.github/workflows/scripts/auto-update-version.sh "opentelemetry-java" "javaVersion" "content/en/docs/instrumentation/java/_index.md"
|
||||
env:
|
||||
# change this to secrets.GITHUB_TOKEN when testing against a fork
|
||||
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
repo=$1
|
||||
variable_name=$2
|
||||
file_names=("${@:3}") # remaining args
|
||||
|
||||
latest_version=$(gh api -q .tag_name "repos/open-telemetry/$repo/releases/latest" | sed 's/^v//')
|
||||
|
||||
echo "Repo: $repo"
|
||||
echo "Latest version: $latest_version"
|
||||
|
||||
for file_name in "${file_names[@]}"
|
||||
do
|
||||
if ! grep -q "$variable_name" "$file_name"; then
|
||||
echo "Could not find \"$variable_name\" in $file_name, failing job."
|
||||
exit 1
|
||||
fi
|
||||
sed -i -e "s/$variable_name: .*/$variable_name: $latest_version/" "$file_name"
|
||||
done
|
||||
|
||||
if git diff --quiet; then
|
||||
echo "Already at the latest version."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
message="Update $repo version to $latest_version"
|
||||
body="Update $repo version to \`$latest_version\`.
|
||||
|
||||
See https://github.com/open-telemetry/$repo/releases/tag/v$latest_version."
|
||||
|
||||
existing_pr_count=$(gh pr list --state all --search "in:title $message" | wc -l)
|
||||
if [ "$existing_pr_count" -gt 0 ]; then
|
||||
echo "PR(s) for version $latest_version of $repo already exist:"
|
||||
gh pr list --state all --search "in:title $message"
|
||||
echo "So we won't create another. Exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
branch="opentelemetrybot/auto-update-$repo-$latest_version"
|
||||
|
||||
git checkout -b "$branch"
|
||||
git commit -a -m "$message"
|
||||
git push --set-upstream origin "$branch"
|
||||
|
||||
echo "Submitting auto-update PR '$message'."
|
||||
gh pr create --label auto-update \
|
||||
--title "$message" \
|
||||
--body "$body"
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
#!/bin/bash -e
|
||||
#
|
||||
# Use `--dry-run` to perform a dry run of `gh` and `git` commands that might change your environment.
|
||||
# Set env var `latest_version`` to force a specific version (or for testing purposes).
|
||||
#
|
||||
# This uses a lot of the code from:
|
||||
# https://github.com/grafana/opentelemetry-collector-components/blob/main/scripts/update-to-latest-otelcol.sh
|
||||
|
||||
GH=gh
|
||||
GIT=git
|
||||
REALPATH=realpath
|
||||
BACKUP_EXT=.bak
|
||||
|
||||
if [[ $OSTYPE == 'darwin'* ]]; then
|
||||
REALPATH=echo
|
||||
fi
|
||||
|
||||
if [[ "$1" == "--dry-run" ]]; then
|
||||
echo Doing a dry run.
|
||||
GH="echo > DRY RUN: gh "
|
||||
GIT="echo > DRY RUN: git "
|
||||
fi
|
||||
|
||||
REPO_DIR=$($REALPATH $(dirname $0)/../../..)
|
||||
|
||||
if ! command -v gh &>/dev/null; then
|
||||
echo "Command 'gh' not found, but is required by this script. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the latest tag, without the "v" prefix
|
||||
: ${latest_version:=$(gh api -q .tag_name repos/open-telemetry/opentelemetry-collector-releases/releases/latest | sed 's/^v//')}
|
||||
|
||||
echo "Latest version: $latest_version"
|
||||
|
||||
fileWithVersInfo=${REPO_DIR}/content/en/docs/collector/_index.md
|
||||
|
||||
sed -i$BACKUP_EXT -e "s/collectorVersion:.*/collectorVersion: $latest_version/" $fileWithVersInfo
|
||||
|
||||
if [[ -e $fileWithVersInfo$BACKUP_EXT ]]; then
|
||||
rm $fileWithVersInfo$BACKUP_EXT
|
||||
fi
|
||||
|
||||
if git diff --quiet ${fileWithVersInfo}; then
|
||||
echo "We are already at the latest version."
|
||||
exit 0
|
||||
else
|
||||
echo "Version update necessary:"
|
||||
git diff ${fileWithVersInfo}
|
||||
echo
|
||||
fi
|
||||
|
||||
pr_title="Bump collector version to ${latest_version}"
|
||||
existing_pr_count=$(gh pr list -s all -S "in:title ${pr_title}" | wc -l)
|
||||
if [ $existing_pr_count -gt 0 ] ; then
|
||||
echo "PR for this version was already created:"
|
||||
gh pr list -s all -S "in:title ${pr_title}"
|
||||
echo
|
||||
echo "I won't create a new one. Exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
branch="opentelemetrybot/collector_version_${latest_version}_r${RANDOM}"
|
||||
|
||||
# While developing the workflow this will map to the dev branch, will map to "main" when in production
|
||||
base_branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
$GIT checkout -b "${branch}" "${base_branch}"
|
||||
|
||||
$GIT add ${fileWithVersInfo}
|
||||
|
||||
$GIT commit -m "Bump OpenTelemetry collector version to ${latest_version}"
|
||||
$GIT push --set-upstream origin "${branch}"
|
||||
|
||||
echo "Creating a pull request on your behalf."
|
||||
$GH pr create --label auto-update,sig:collector \
|
||||
--title "${pr_title}" \
|
||||
--body "Update OpenTelemetry collector to v${latest_version}."
|
||||
Loading…
Reference in New Issue