name: Update Content

on:
  workflow_dispatch:
  push:
    branches:
      - "*"
      - "!main"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12

      - name: Install python dependencies
        run: python -m pip install -r requirements.txt

      - name: Update logos
        run: npm run gen-logos

      - name: Update content
        run: npm run gen

      - name: Install node dependencies
        run: npm ci

      - name: Test updated files
        run: npm test

      - name: Check for modified files
        id: git-check
        run: echo ::set-output name=modified::$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)

      - name: Update changes in GitHub repository
        if: steps.git-check.outputs.modified == 'true'
        run: |
          git config --global user.name 'WormholeBot'
          git config --global user.email 'wormhole@wormholenetwork.com'
          git add -A
          git commit -m '[automated] update content'
          git push
