Skip to content

Commit 54f260b

Browse files
author
github-actions
committed
build: 857558b1b86ab25174fab99d5effa59f2561ce84
1 parent 01ad089 commit 54f260b

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

.github/workflows/reusable.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# .github/workflows/reusable-workflow.yml
22
name: branch default workflow
33

4+
env:
5+
EXCHANGES_JSON: '["binance", "okx", "kraken", "coinbase", "bybit"]'
6+
47
on:
58
workflow_call:
69
inputs:
@@ -46,7 +49,19 @@ jobs:
4649
# git pull --allow-unrelated-histories prod main || echo "Git pull failed"
4750
# git push prod main --force
4851

52+
53+
readme_update:
54+
name: readme-upd
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout code
58+
uses: actions/checkout@v4
59+
with:
60+
ref: ${{ github.ref }}
61+
4962
- name: Update README with repository links
63+
env:
64+
EXCHANGES_JSON: '["binance", "okx", "kraken", "coinbase", "bybit"]'
5065
run: chmod +x ./build/update-readme.sh && ./build/update-readme.sh
5166

5267
- name: Commit and push changes

build/update-readme.sh

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
#!/bin/bash
22

3-
# Define array of exchanges
4-
EXCHANGES=("binance" "kucoin" "coinbase" "kraken" "bybit")
3+
# my_array=("binance" "okx")
4+
my_array=()
5+
items=$(echo "$EXCHANGES_JSON" | sed 's/^\[//;s/\]$//;s/"//g;s/ //g')
6+
IFS=',' read -ra my_array <<< "$items"
57

6-
# Create the section content in a variable
7-
SECTION=$'\n## Exchange Repositories\n\n'
8+
# Define the marker string
9+
marker="### See our other exchanges"
810

9-
# Generate links for each exchange
10-
for exchange in "${EXCHANGES[@]}"; do
11-
SECTION+="- [python-${exchange}](https://github.com/ccxt/python-${exchange}.git)"$'\n'
12-
done
11+
# Define the README file path
12+
readme_file="$GITHUB_WORKSPACE/README.md"
1313

14-
# Update README with perl (no temp files)
15-
perl -i -0pe "s/## Exchange Repositories.*?(^##|\Z)/$SECTION\$1/ms" ./../README.md || {
16-
# If section doesn't exist, append it
17-
echo "$SECTION" >> ./../README.md
14+
# Function to generate the list items
15+
generate_list_items() {
16+
local repo_prefix="https://github.com/my/"
17+
local list_string=""
18+
19+
for item in "${my_array[@]}"; do
20+
list_string+="- [**$item** python](${repo_prefix}${item})\n"
21+
done
22+
23+
printf "%s" "$list_string"
1824
}
1925

20-
# Display the changes
21-
cat ./../README.md
26+
# Check if the README file exists
27+
if [ ! -f "$readme_file" ]; then
28+
echo "Error: README.md not found."
29+
exit 1
30+
fi
31+
32+
# Read the README file and remove everything after the marker
33+
content=$(sed "/$marker/q" "$readme_file")
34+
35+
# Generate the list items
36+
list_items=$(generate_list_items)
37+
38+
# Append the marker and the new list items
39+
new_content="$content\n$marker\n$list_items"
40+
41+
# Write the new content to the README file
42+
echo -e "$new_content" > "$readme_file" # -e to process escape sequences
43+
44+
echo "README.md updated successfully."

0 commit comments

Comments
 (0)