This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
Update Token List #93
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Token List | |
on: | |
workflow_dispatch: | |
inputs: | |
name: | |
description: "Token name" | |
required: true | |
chainId: | |
description: "Chain ID" | |
required: true | |
symbol: | |
description: "Token symbol" | |
required: true | |
address: | |
description: "Token address" | |
required: true | |
decimals: | |
description: "Token decimals" | |
required: true | |
image: | |
description: "Token logo (base64 encoded)" | |
required: true | |
jobs: | |
update-token-list: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20" | |
- name: Set up Git configuration | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "[email protected]" | |
git config core.autocrlf input | |
- name: Decode and save image | |
run: | | |
mkdir -p Tokens/${{ github.event.inputs.address }} | |
echo "${{ github.event.inputs.image }}" | base64 --decode > Tokens/${{ github.event.inputs.address }}/logo.png | |
- name: List files in Tokens directory | |
run: ls -R Tokens/ | |
- name: Prepare branch and token entry | |
id: prepare | |
run: | | |
name="${{ github.event.inputs.name }}" | |
symbol="${{ github.event.inputs.symbol }}" | |
sanitized_name=$(echo "$name" | tr ' ' '-' | tr -cd '[:alnum:]-') | |
sanitized_symbol=$(echo "$symbol" | tr ' ' '-' | tr -cd '[:alnum:]-') | |
branch_name="add-token-$sanitized_name-$sanitized_symbol" | |
# Save branch name to be used in subsequent steps | |
echo "branch_name=$branch_name" >> $GITHUB_ENV | |
- name: Print branch name | |
run: | | |
echo "Branch name: ${{ env.branch_name }}" | |
- name: Remove unwanted files and directories | |
run: | | |
rm -rf .github/workflows | |
- name: Normalize line endings in FXList.json | |
run: | | |
awk '{ sub("\r$", ""); print }' FXList.json > tmp.FXList.json && mv tmp.FXList.json FXList.json | |
- name: Format FXList.json before changes | |
run: | | |
jq --indent 4 . FXList.json > tmp.FXList.json && mv tmp.FXList.json FXList.json | |
- name: Append new token to FXList.json | |
run: | | |
# Create token entry | |
token_entry=$(jq -n \ | |
--arg name "${{ github.event.inputs.name }}" \ | |
--argjson chainId "${{ github.event.inputs.chainId }}" \ | |
--arg symbol "${{ github.event.inputs.symbol }}" \ | |
--argjson decimals "${{ github.event.inputs.decimals }}" \ | |
--arg address "${{ github.event.inputs.address }}" \ | |
--arg logoURI "https://raw.githubusercontent.com/${{ github.repository }}/${{ env.branch_name }}/Tokens/${{ github.event.inputs.address }}/logo.png" \ | |
'{name: $name, chainId: $chainId, symbol: $symbol, decimals: $decimals, address: $address, logoURI: $logoURI}') | |
# Append the new entry to the tokens array in FXList.json | |
jq --argjson token_entry "$token_entry" '.tokens += [$token_entry]' FXList.json > tmp.FXList.json && mv tmp.FXList.json FXList.json | |
- name: Format FXList.json after changes | |
run: | | |
jq --indent 4 . FXList.json > tmp.FXList.json && mv tmp.FXList.json FXList.json | |
- name: Commit changes | |
run: | | |
git checkout -b ${{ env.branch_name }} | |
git add FXList.json Tokens/${{ github.event.inputs.address }}/logo.png | |
git commit -m "Add token ${{ github.event.inputs.name }} (${{ github.event.inputs.symbol }})" | |
git push origin ${{ env.branch_name }} | |
- name: Install GitHub CLI | |
run: | | |
sudo apt-get update | |
sudo apt-get install gh | |
- name: Create Pull Request with GH CLI | |
env: | |
GH_TOKEN: ${{ secrets.TOKEN }} | |
run: | | |
gh pr create --repo FunctionX-SG/FXSwap-TokenList --base main --head isabelle-pundix:${{ env.branch_name }} --title "Add ${{ github.event.inputs.name }} Token" --body "This PR adds a new token with name '${{ github.event.inputs.name }}' and symbol '${{ github.event.inputs.symbol }}'." | |
# gh pr create --title "Add ${{ github.event.inputs.name }} Token" \ | |
# --body "This PR adds a new token with name '${{ github.event.inputs.name }}' and symbol '${{ github.event.inputs.symbol }}'." \ | |
# --base main \ | |
# --head isabelle-pundix:${{ env.branch_name }} |