name: Onnxruntime main weekly sync
on:
  schedule:
    - cron: '07 17 * * 5'

jobs:
  createPullRequest:
    name: Update and create pull request
    runs-on: ubuntu-latest
    steps:
      - name: get_date
        run: echo todays_date="$(date +'%Y-%m-%d')" >> $GITHUB_ENV

      - name: extract_sha1 
        run: echo onnxsha="$(git ls-remote https://github.com/microsoft/onnxruntime.git HEAD | awk '{print $1}')" >> $GITHUB_ENV

      - name: echo_sha1
        run: echo ${{ env.onnxsha }}

      - uses: actions/checkout@v3
        with: 
          ref: develop

      - name: update_file
        run:  echo ${{ env.onnxsha }} > test/onnx/.onnxrt-commit

      - name: Make changes to pull request
        uses: peter-evans/create-pull-request@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Update onnxruntime main ${{ env.onnxsha }}
          committer: Github <noreply@github.com>
          author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
          signoff: false
          branch: onnxruntime-sync-${{ env.todays_date }}
          delete-branch: true
          title: 'Onnxruntime Weekly Sync ${{ env.todays_date }}'
          body: |
            Update CI point for Onnxruntime builds
            - Updated with changes from ${{ env.todays_date }}
            - Auto-generated by [create-pull-request][1]
            - Update .onnxrt-commit to ${{ env.onnxsha }}

            [1]: https://github.com/peter-evans/create-pull-request
          labels: |
            onnxruntime
            dependancies
            automated 
          assignees: TedThemistokleous
          reviewers: TedThemistokleous causten
          draft: false
          base: develop