diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh new file mode 100755 index 00000000000..c20cb643a52 --- /dev/null +++ b/.github/scripts/update-version.sh @@ -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..." +} \ No newline at end of file diff --git a/.github/update.yml b/.github/update.yml deleted file mode 100644 index 1fc554214af..00000000000 --- a/.github/update.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Update Version - -on: - workflow_dispatch: - inputs: - version: - required: true - type: string - description: 'Besu version to be updated' - name: - required: true - type: string - description: 'Name of the author to be included in git commit signature' - email: - required: true - type: string - description: 'Email of the author to be included in git commit signature' - -jobs: - update: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup branch name - id: branch - run: | - echo "BRANCH=update-${{ inputs.version }}-${{ github.run_number }}" >> "$GITHUB_OUTPUT" - - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'yarn' - - - name: Update version - run: | - # Configure git - git config --global user.name "${{ inputs.name }}" - git config --global user.email "${{ inputs.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 - 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 "===================================" - env: - VERSION: ${{ inputs.version }} - FILE: docusaurus.config.js - BRANCH: ${{ steps.branch.outputs.BRANCH }} - - # PR creation requires setting allow PR creation in action settings - - name: Create Pull Request [permission needed] - run: | - echo BASE_BRANCH=$BASE_BRANCH - gh pr create --base $BASE_BRANCH --title "Update Besu version $VERSION" --body "Besu version updated to $VERSION" || { - echo "Action does not have permission to create PRs. Ignoring..." - } - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VERSION: ${{ inputs.version }} - BASE_BRANCH: ${{ github.event.repository.default_branch }} \ No newline at end of file diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml new file mode 100644 index 00000000000..b8fe896efe2 --- /dev/null +++ b/.github/workflows/update-version.yml @@ -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 }}