name: "Refresh jdk25 from Upstream"
on:
  schedule:
    - cron: '0 8 * * *'
  workflow_dispatch:
env:
  UPSTREAM_REMOTE: https://github.com/openjdk/jdk.git
  LOCAL_BRANCH: develop
  
jobs:
    refresh-jdk:
        runs-on: ubuntu-latest
        name: "Update Corretto-25"
        if: github.repository_owner == 'corretto'
        steps:
            - name: "Checkout code"
              uses: actions/checkout@v2
              with:
                fetch-depth: 0
                ref: ${{ env.LOCAL_BRANCH }}
                
            - name: "Configure the user"
              run: |
                git config user.email "no-reply@amazon.com"
                git config user.name "corretto-github-robot"
                
            - name: "Merge openjdk/jdk:jdk25 to the corretto-25:develop"
              run: |
                git fetch $UPSTREAM_REMOTE jdk25 || exit 1
                git merge -m "Merge upstream-jdk" FETCH_HEAD
                
            - name: "Update Corretto version"
              shell: bash
              run: bash ./.github/scripts/update-version.sh $UPSTREAM_REMOTE

            - name: "Push to the corretto-25"
              run: git push origin $LOCAL_BRANCH
