Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set up github actions for easier contribution #12

Open
0xa3k5 opened this issue May 28, 2024 · 0 comments
Open

set up github actions for easier contribution #12

0xa3k5 opened this issue May 28, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@0xa3k5
Copy link
Owner

0xa3k5 commented May 28, 2024

I've tried to build this myself, but I couldn't succeed.

There is a script add-icons which accepts a string as the second parameter and runs validation checks, finds matching rawdata and updates the relevant metadata.json with the correct object structure.

The github action should be triggered on:

  • pull_request
  • push to main
  • pull_request_target (to enable prs from forks)

and then should:

  • compared the committed changes in packages/core/src/raw-svgs/ with the last commit of main and pass the modified or newly added paths to the add-icons script:
bun run add-icons {{SVG_PATHS}}

afterwards the action should build the packages

bun run build --filter=@token-icons/react --filter=@token-icons/core

write a commit message with the newly added svgs and commit to the trigger (to pull request or directly to the main brach)

the draft version of this action can be found under icon-add.yml

name: icon-add

permissions:
  contents: write
  pull-requests: write

on:
  push:
    branches:
      - main
    paths:
      - 'packages/core/src/raw-svgs/**'
  pull_request:
    branches:
      - main
    paths:
      - 'packages/core/src/raw-svgs/**'

jobs:
  update-and-rebuild:
    runs-on: ubuntu-latest
    steps:
      - name: Setup bun
        uses: oven-sh/setup-bun@v1

      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 10

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '20'

      - name: Install dependencies
        run: bun install

      - name: Identify New SVG Files
        id: files
        run: |
          SVG_FILES=$(git diff --name-only HEAD^ HEAD | grep 'packages/core/src/raw-svgs/' | tr '\n' ',')
          echo "SVG_FILES=${SVG_FILES%,}" >> $GITHUB_ENV
          echo "New SVG Files: $SVG_FILES"
          echo "New Token Icons: $newTokenIcons"
          echo "New Network Icons: $newNetworkIcons"

      - name: Update Metadata
        if: env.SVG_FILES
        run: |
          newTokenIcons=$(git diff --name-only HEAD^ HEAD | grep 'packages/core/src/raw-svgs/tokens/' | xargs basename -a | sed 's/.svg//' | sort -u | tr '\n' ', ' | sed 's/, $//')
          newNetworkIcons=$(git diff --name-only HEAD^ HEAD | grep 'packages/core/src/raw-svgs/networks/' | xargs basename -a | sed 's/.svg//' | sort -u | tr '\n' ', ' | sed 's/, $//')
          echo "newTokenIcons=$newTokenIcons" >> $GITHUB_ENV
          echo "newNetworkIcons=$newNetworkIcons" >> $GITHUB_ENV
          bun run ./packages/utils/src/scripts/add-icons.ts ${{ env.SVG_FILES }}

      - name: Build Packages
        run: |
          bun run build --filter=@tknicns/core --filter=@tknicns/react
        
      - name: Commit Changes
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
          git add .
          commitMessage=""
          description=""

          if [ -n "$newTokenIcons" ] && [ -n "$newNetworkIcons" ]; then
            commitMessage="core: add new token icons & network icons"
            description+="token icons: $newTokenIcons\nnetwork icons: $newNetworkIcons"
          elif [ -n "$newTokenIcons" ]; then
            commitMessage="core: add new token icons"
            description+="token icons: $newTokenIcons"
          elif [ -n "$newNetworkIcons" ]; then
            commitMessage="core: add new network icons"
            description+="network icons: $newNetworkIcons"
          fi

          if [ -n "$description" ]; then
            git commit -m "$commitMessage" -m "$description" || echo "No changes to commit"
          else
            echo "No new icons to commit"
          fi
          git push origin ${GITHUB_HEAD_REF:-${GITHUB_REF}}
@0xa3k5 0xa3k5 added the help wanted Extra attention is needed label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant