Skip to content

fix: address PR comments from #211 #113

fix: address PR comments from #211

fix: address PR comments from #211 #113

##
# Copyright (C) 2023-2024 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
name: Update README.md
on:
workflow_dispatch:
pull_request:
defaults:
run:
shell: bash
jobs:
update:
runs-on: [self-hosted, Linux, medium, ephemeral]
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- name: Checkout Code for Pull Request
run: |
git clone https://github.com/hashgraph/solo.git
git checkout ${{ github.event.pull_request.head.sha }}
- name: Readme Update Check
id: readme-update-check
run: |
# determine if any javascript files change since last "auto update README.md"
git --no-pager diff --name-only ${{ github.event.pull_request.head.ref }} $(git merge-base ${{ github.event.pull_request.head.ref }} ${{ github.event.pull_request.base.ref }})
CHANGED_FILES=$(git --no-pager diff --name-only ${{ github.event.pull_request.head.ref }} $(git merge-base ${{ github.event.pull_request.head.ref }} ${{ github.event.pull_request.base.ref }}) | grep -E -i ".*\.(mjs|cjs|js|package*\.json)")
[ "${#CHANGED_FILES}" -gt 0 ] && FILES_CHANGED=true || FILES_CHANGED=false
git --no-pager log --reverse --pretty="%H|%an|%s" ${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.ref }} | awk '/github-actions\[bot\]\|auto update README\.md/ {s=""; next} {s = s $0 RS} END {printf "%s", s}'
COMMITS_SINCE_UPDATE=$(git --no-pager log --reverse --pretty="%H|%an|%s" ${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.ref }} | awk '/github-actions\[bot\]\|auto update README\.md/ {s=""; next} {s = s $0 RS} END {printf "%s", s}')
[ "${#COMMITS_SINCE_UPDATE}" -gt 0 ] && UPDATE_NEEDED=true || UPDATED_NEEDED=false
- name: Setup Node
if: ${{ steps.readme-update-check.outputs.FILES_CHANGED == 'true' && steps.readme-update-check.outputs.UPDATE_NEEDED == 'true' }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20
cache: npm
- name: Setup Kind
if: ${{ steps.readme-update-check.outputs.FILES_CHANGED == 'true' && steps.readme-update-check.outputs.UPDATE_NEEDED == 'true' }}
uses: helm/kind-action@99576bfa6ddf9a8e612d83b513da5a75875caced # v1.9.0
with:
install_only: true
node_image: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72
version: v0.21.0
kubectl_version: v1.28.6
verbosity: 3
wait: 120s
- name: Install NVM & Dependencies
if: ${{ steps.readme-update-check.outputs.FILES_CHANGED == 'true' && steps.readme-update-check.outputs.UPDATE_NEEDED == 'true' }}
id: npm-deps
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install lts/hydrogen
nvm use lts/hydrogen
npm ci
- name: Install gettext-base
if: ${{ steps.readme-update-check.outputs.FILES_CHANGED == 'true' && steps.readme-update-check.outputs.UPDATE_NEEDED == 'true' }}
id: gettext-base
run: |
sudo apt-get update
sudo apt-get install gettext-base
- name: Update README.md
if: ${{ steps.readme-update-check.outputs.FILES_CHANGED == 'true' && steps.readme-update-check.outputs.UPDATE_NEEDED == 'true' }}
run: |
npm install -g @hashgraph/solo
which solo
export SOLO_CLUSTER_NAME=solo
export SOLO_NAMESPACE=solo
export SOLO_CLUSTER_SETUP_NAMESPACE=solo-cluster
echo "Perform the following kind and solo commands and save output to environment variables"
export KIND_CREATE_CLUSTER_OUTPUT=$( kind create cluster -n "${SOLO_CLUSTER_NAME}" 2>&1 | tee test.log )
export SOLO_INIT_OUTPUT=$( solo init -t v0.42.5 -i node0,node1,node2 -n "${SOLO_NAMESPACE}" -s \
"${SOLO_CLUSTER_SETUP_NAMESPACE}" --key-format pfx | tee test.log )
export SOLO_NODE_KEYS_OUTPUT=$( solo node keys --gossip-keys --tls-keys --key-format pfx | tee test.log )
export SOLO_CLUSTER_SETUP_OUTPUT=$( solo cluster setup | tee test.log )
export SOLO_NETWORK_DEPLOY_OUTPUT=$( solo network deploy | tee test.log )
export SOLO_NODE_SETUP_OUTPUT=$( solo node setup | tee test.log )
export SOLO_NODE_START_OUTPUT=$( solo node start | tee test.log )
export SOLO_MIRROR_NODE_DEPLOY_OUTPUT=$( solo mirror-node deploy | tee test.log )
export SOLO_RELAY_DEPLAY_OUTPUT=$( solo relay deploy -i node0,node1 | tee test.log )
export SOLO_INIT_047_OUTPUT=$( solo init -t v0.47.0-alpha.0 -i node0,node1,node2 -n "${SOLO_NAMESPACE}" \
-s "${SOLO_CLUSTER_SETUP_NAMESPACE}" --key-format pem | tee test.log )
export SOLO_NODE_KEY_PEM_OUTPUT=$( solo node keys --gossip-keys --tls-keys --key-format pem | tee test.log )
export SOLO_RELAY_DEPLOY_OUTPUT=$( solo relay deploy | tee test.log )
echo "Generate README.md"
envsubst '$KIND_CREATE_CLUSTER_OUTPUT,$SOLO_INIT_OUTPUT,$SOLO_NODE_KEYS_OUTPUT, $SOLO_CLUSTER_SETUP_OUTPUT, \
$SOLO_NETWORK_DEPLOY_OUTPUT,$SOLO_NODE_SETUP_OUTPUT,$SOLO_NODE_START_OUTPUT,$SOLO_MIRROR_NODE_DEPLOY_OUTPUT,\
$SOLO_RELAY_DEPLAY_OUTPUT,$SOLO_INIT_047_OUTPUT,$SOLO_NODE_KEY_PEM_OUTPUT,$SOLO_RELAY_DEPLOY_OUTPUT'\
< README.md.template > README.md
echo "Remove color codes and lines showing intermediate progress"
sed -i 's/\[32m//g' README.md
sed -i 's/\[33m//g' README.md
sed -i 's/\[39m//g' README.md
egrep -v '↓|❯|•' README.md > README.md.tmp && mv README.md.tmp README.md
- name: Check README.md Changes
if: ${{ steps.readme-update-check.outputs.FILES_CHANGED == 'true' && steps.readme-update-check.outputs.UPDATE_NEEDED == 'true' }}
id: check-readme-changes
run: |
CHANGES=$(git diff --stat)
echo "Changes: $CHANGES"
INSERTIONS=$(echo $CHANGES | grep -o -P '(?<=insertions\(\+\), )\d+')
echo "Insertions: $INSERTIONS"
DELETIONS=$(echo $CHANGES | grep -o '[0-9]\+' | tail -1)
echo "Deletions: $DELETIONS"
# Calculate total lines changed if INSERTIONS and DELETIONS are not empty
if [ -z "$INSERTIONS" ]; then
INSERTIONS=0
fi
if [ -z "$DELETIONS" ]; then
DELETIONS=0
fi
TOTAL_LINES_CHANGED=$(($INSERTIONS + $DELETIONS))
echo "Total README lines changed: $TOTAL_LINES_CHANGED"
echo "TOTAL_LINES_CHANGED=$TOTAL_LINES_CHANGED" >> "${GITHUB_OUTPUT}"
# Signed Commits by actions https://github.com/actions/runner/issues/667
- name: Commit README.md Changes
if: ${{ steps.readme-update-check.outputs.FILES_CHANGED == 'true' && steps.readme-update-check.outputs.UPDATE_NEEDED == 'true' && steps.check-readme-changes.outputs.TOTAL_LINES_CHANGED > 20 }}
uses: planetscale/[email protected]
with:
commit_message: "auto update README.md"
repo: ${{ github.repository }}
branch: ${{ github.head_ref || github.ref_name }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}