Skip to content

Commit

Permalink
Version update automation (#1654)
Browse files Browse the repository at this point in the history
Deleted the workflow added incorrectly to the .github folder. Added new workflow file to perform the version update steps when a new release is created

Signed-off-by: Chaminda Divitotawela <cdivitotawela@gmail.com>
  • Loading branch information
cdivitotawela committed Jul 17, 2024
1 parent 4d4131b commit 7fdbd9a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 93 deletions.
62 changes: 62 additions & 0 deletions .github/scripts/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#
# Besu Docs new Besu version update helper
#

log_error() {
echo "ERROR: $1"
exit 1
}

# Validate the environment variables set
[[ -z "$VERSION" ]] && log_error "Environment variable VERSION cannot be empty"

FILE="${FILE:-docusaurus.config.js}"
GIT_NAME="${GIT_NAME:-Besu Bot}"
GIT_EMAIL="${GIT_EMAIL:-devops@consensys.net}"
BASE_BRANCH="${BASE_BRANCH:-main}"
BRANCH="besu-version-$VERSION"

# Configure git
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"

# Create branch
git checkout -b "$BRANCH"

# https://docs-template.consensys.io/configure/versioning#create-a-docs-version
yarn install
npm run docusaurus docs:version "$VERSION" > /dev/null
git add "versioned_docs/version-$VERSION/"
git add "versioned_sidebars/version-$VERSION-sidebars.json"

git add versions.json

# Remove stable mark from the existing version
sed -i 's/label\: "stable (\([0-9]*\.[0-9]*\.[0-9]*\))"/label: "\1"/' "$FILE"

# Add new release as stable version
sed -i "/\/\/ STABLE-AUTOMATION-TOKEN/a \ \"$VERSION\": {\n\ label: \"stable ($VERSION)\",\n\ }," "$FILE"

# Update the latest version
sed -i "s/lastVersion: \"[0-9]*\.[0-9]*\.[0-9]*\"/lastVersion: \"$VERSION\"/" "$FILE"

# Output the diff
git diff "$FILE"
git diff versions.json

# Commit and push branch
git add "$FILE"
git commit -s -m "Update version $VERSION"
git push origin "$BRANCH"

# Output Git status to see any unexpected file changes. These could be due to changes in the process
echo "===== Git status after commit ====="
git status -s
echo "==================================="

# Attempt to create PR. If no permission skip the PR creation
echo "Attempt to create PR using base branch $BASE_BRANCH"
gh pr create --base "$BASE_BRANCH" --title "Update Besu version $VERSION" --body "Besu version updated to $VERSION" || {
echo "WRAN: Action does not have permission to create PRs. Ignoring..."
}
93 changes: 0 additions & 93 deletions .github/update.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Update Version

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Check release name
id: version
run: |
# User can input anything so check what is provided as release name
echo "${{ github.event.release.name }}" | grep -q -e "^[0-9]*\.[0-9]*\.[0-9]*$" || {
echo "Release name [$RELEASE_NAME] is not in expected format '^[0-9]*\.[0-9]*\.[0-9]*$'"
exit 1
}
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'

- name: Update version
run: .github/scripts/update-version.sh
env:
VERSION: ${{ github.event.release.name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 7fdbd9a

Please sign in to comment.