|
| 1 | +## |
| 2 | +# Copyright (C) 2023-2024 Hedera Hashgraph, LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +## |
| 16 | + |
| 17 | +name: Update README.md |
| 18 | +on: |
| 19 | + workflow_dispatch: |
| 20 | + pull_request: |
| 21 | + types: |
| 22 | + - opened |
| 23 | + - reopened |
| 24 | + - synchronize |
| 25 | + paths: |
| 26 | + - '**/*.mjs' |
| 27 | + - '**/*.js' |
| 28 | + - '**/package*.json' |
| 29 | +defaults: |
| 30 | + run: |
| 31 | + shell: bash |
| 32 | +jobs: |
| 33 | + update: |
| 34 | + runs-on: [self-hosted, Linux, medium, ephemeral] |
| 35 | + permissions: |
| 36 | + # Give the default GITHUB_TOKEN write permission to commit and push the |
| 37 | + # added or changed files to the repository. |
| 38 | + contents: write |
| 39 | + steps: |
| 40 | + - name: Checkout Code for Push |
| 41 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 42 | + if: github.event_name == 'push' |
| 43 | + with: |
| 44 | + fetch-depth: 0 |
| 45 | + |
| 46 | + # https://github.com/actions/checkout/issues/124 |
| 47 | + - name: Checkout Code for Pull Request |
| 48 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 49 | + if: github.event_name == 'pull_request' |
| 50 | + with: |
| 51 | + fetch-depth: 0 |
| 52 | + ref: ${{ github.event.pull_request.head.ref }} |
| 53 | + |
| 54 | + - name: Setup Node |
| 55 | + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 |
| 56 | + with: |
| 57 | + node-version: 20 |
| 58 | + cache: npm |
| 59 | + |
| 60 | + - name: Setup Kind |
| 61 | + uses: helm/kind-action@99576bfa6ddf9a8e612d83b513da5a75875caced # v1.9.0 |
| 62 | + with: |
| 63 | + install_only: true |
| 64 | + node_image: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72 |
| 65 | + version: v0.21.0 |
| 66 | + kubectl_version: v1.28.6 |
| 67 | + verbosity: 3 |
| 68 | + wait: 120s |
| 69 | + |
| 70 | + - name: Install NVM & Dependencies |
| 71 | + id: npm-deps |
| 72 | + run: | |
| 73 | + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash |
| 74 | + export NVM_DIR="$HOME/.nvm" |
| 75 | + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm |
| 76 | + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion |
| 77 | + nvm install lts/hydrogen |
| 78 | + nvm use lts/hydrogen |
| 79 | + npm ci |
| 80 | +
|
| 81 | + - name: Install gettext-base |
| 82 | + id: gettext-base |
| 83 | + run: | |
| 84 | + sudo apt-get update |
| 85 | + sudo apt-get install gettext-base |
| 86 | +
|
| 87 | + - name: Update README.md |
| 88 | + run: | |
| 89 | + npm install -g @hashgraph/solo |
| 90 | + which solo |
| 91 | + |
| 92 | + export SOLO_CLUSTER_NAME=solo |
| 93 | + export SOLO_NAMESPACE=solo |
| 94 | + export SOLO_CLUSTER_SETUP_NAMESPACE=solo-cluster |
| 95 | + |
| 96 | + echo "Perform the followng kind and solo commands and save output to environment variables" |
| 97 | + |
| 98 | + export KIND_CREATE_CLUSTER_OUTPUT=$( kind create cluster -n "${SOLO_CLUSTER_NAME}" 2>&1 | tee test.log ) |
| 99 | + |
| 100 | + export SOLO_INIT_OUTPUT=$( solo init -t v0.42.5 -i node0,node1,node2 -n "${SOLO_NAMESPACE}" -s \ |
| 101 | + "${SOLO_CLUSTER_SETUP_NAMESPACE}" --key-format pfx | tee test.log ) |
| 102 | + |
| 103 | + export SOLO_NODE_KEYS_OUTPUT=$( solo node keys --gossip-keys --tls-keys --key-format pfx | tee test.log ) |
| 104 | +
|
| 105 | + export SOLO_CLUSTER_SETUP_OUTPUT=$( solo cluster setup | tee test.log ) |
| 106 | + |
| 107 | + export SOLO_NETWORK_DEPLOY_OUTPUT=$( solo network deploy | tee test.log ) |
| 108 | + |
| 109 | + export SOLO_NODE_SETUP_OUTPUT=$( solo node setup | tee test.log ) |
| 110 | + |
| 111 | + export SOLO_NODE_START_OUTPUT=$( solo node start | tee test.log ) |
| 112 | + |
| 113 | + export SOLO_MIRROR_NODE_DEPLOY_OUTPUT=$( solo mirror-node deploy | tee test.log ) |
| 114 | + |
| 115 | + export SOLO_RELAY_DEPLAY_OUTPUT=$( solo relay deploy -i node0,node1 | tee test.log ) |
| 116 | + |
| 117 | + export SOLO_INIT_047_OUTPUT=$( solo init -t v0.47.0-alpha.0 -i node0,node1,node2 -n "${SOLO_NAMESPACE}" \ |
| 118 | + -s "${SOLO_CLUSTER_SETUP_NAMESPACE}" --key-format pem | tee test.log ) |
| 119 | + |
| 120 | + export SOLO_NODE_KEY_PEM_OUTPUT=$( solo node keys --gossip-keys --tls-keys --key-format pem | tee test.log ) |
| 121 | +
|
| 122 | + export SOLO_RELAY_DEPLOY_OUTPUT=$( solo relay deploy | tee test.log ) |
| 123 | + echo "Generate README.md" |
| 124 | + |
| 125 | + envsubst '$KIND_CREATE_CLUSTER_OUTPUT,$SOLO_INIT_OUTPUT,$SOLO_NODE_KEYS_OUTPUT, $SOLO_CLUSTER_SETUP_OUTPUT, \ |
| 126 | + $SOLO_NETWORK_DEPLOY_OUTPUT,$SOLO_NODE_SETUP_OUTPUT,$SOLO_NODE_START_OUTPUT,$SOLO_MIRROR_NODE_DEPLOY_OUTPUT,\ |
| 127 | + $SOLO_RELAY_DEPLAY_OUTPUT,$SOLO_INIT_047_OUTPUT,$SOLO_NODE_KEY_PEM_OUTPUT,$SOLO_RELAY_DEPLOY_OUTPUT'\ |
| 128 | + < README.md.template > README.md |
| 129 | +
|
| 130 | + echo "Remove color codes and lines showing intermediate progress" |
| 131 | + |
| 132 | + sed -i 's/\[32m//g' README.md |
| 133 | + sed -i 's/\[33m//g' README.md |
| 134 | + sed -i 's/\[39m//g' README.md |
| 135 | + egrep -v '↓|❯|•' README.md > README.md.tmp && mv README.md.tmp README.md |
| 136 | +
|
| 137 | + - name: Check README.md Changes |
| 138 | + id: check-readme-changes |
| 139 | + run: | |
| 140 | + CHANGES=$(git diff --stat) |
| 141 | + echo "Changes: $CHANGES" |
| 142 | + |
| 143 | + INSERTIONS=$(echo $CHANGES | grep -o -P '(?<=insertions\(\+\), )\d+') |
| 144 | + echo "Insertions: $INSERTIONS" |
| 145 | +
|
| 146 | + DELETIONS=$(echo $CHANGES | grep -o '[0-9]\+' | tail -1) |
| 147 | + echo "Deletions: $DELETIONS" |
| 148 | + |
| 149 | + # Calculate total lines changed if INSERTIONS and DELETIONS are not empty |
| 150 | + if [ -z "$INSERTIONS" ]; then |
| 151 | + INSERTIONS=0 |
| 152 | + fi |
| 153 | + if [ -z "$DELETIONS" ]; then |
| 154 | + DELETIONS=0 |
| 155 | + fi |
| 156 | + |
| 157 | + TOTAL_LINES_CHANGED=$(($INSERTIONS + $DELETIONS)) |
| 158 | + echo "Total README lines changed: $TOTAL_LINES_CHANGED" |
| 159 | + echo "TOTAL_LINES_CHANGED=$TOTAL_LINES_CHANGED" >> "${GITHUB_OUTPUT}" |
| 160 | +
|
| 161 | + # Signed Commits by actions https://github.com/actions/runner/issues/667 |
| 162 | + - name: Commit README.md Changes |
| 163 | + if: ${{ steps.check-readme-changes.outputs.TOTAL_LINES_CHANGED > 20 }} |
| 164 | + uses: planetscale/[email protected] |
| 165 | + with: |
| 166 | + commit_message: "auto update README.md" |
| 167 | + repo: ${{ github.repository }} |
| 168 | + branch: ${{ github.head_ref || github.ref_name }} |
| 169 | + env: |
| 170 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
0 commit comments