name: "Update challenges in Companion Guide"

on:
  push:
    branches: [ master, develop ]
    paths:
      - 'data/static/challenges.yml'
  workflow_dispatch:

jobs:
  UpdateChallengesOnWebsite:
    if: github.repository == 'juice-shop/juice-shop'
    runs-on: ubuntu-latest
    steps:
    - name: Check out Git repository
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
      with:
        token: ${{ secrets.BOT_TOKEN }}
        repository: juice-shop/pwning-juice-shop
        ref: ${{ github.ref_name }}
    - name: Update challenges.yml
      run: |
        cd docs/modules/ROOT/assets/data
        rm challenges.yml
        wget https://raw.githubusercontent.com/juice-shop/juice-shop/${{ github.ref_name }}/data/static/challenges.yml
    - uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 #v5.0.1
      with:
        commit_message: "Auto-update challenges.yml from ${{ github.sha }}"
        branch: ${{ github.ref_name }}
        commit_options: '--signoff'

        # Optional commit user and author settings
        commit_user_name: JuiceShopBot
        commit_user_email: 61591748+JuiceShopBot@users.noreply.github.com
        commit_author: JuiceShopBot <61591748+JuiceShopBot@users.noreply.github.com>
