From 4f94c5d8fc92387a982f0c989eadfb3123ffecc1 Mon Sep 17 00:00:00 2001 From: Naresh Date: Mon, 15 Apr 2024 09:47:24 +0100 Subject: [PATCH] Update action to sync upstream --- .github/workflows/sync.yaml | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/sync.yaml b/.github/workflows/sync.yaml index 669673c39a8..8917f398861 100644 --- a/.github/workflows/sync.yaml +++ b/.github/workflows/sync.yaml @@ -5,40 +5,46 @@ on: - cron: "0 8 * * *" # Runs every day at 8 AM GMT workflow_dispatch: +permissions: + contents: write + pull-requests: write + jobs: update_fork: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 + token: ${{ secrets.BINARIES_RELEASE_PAT }} - - name: Configure Git + - name: Get current date + id: current_date run: | - git config --global user.email "actions@github.com" - git config --global user.name "GitHub Actions" + echo "date=$(date +'%d%m%y')" >> $GITHUB_OUTPUT + echo "time=$(date +'%d%m%y %H:%M')" >> $GITHUB_OUTPUT - - name: Add upstream remote + - name: Configure git + env: + GITHUB_USERNAME: ${{ github.repository_owner }} run: | - git remote add upstream https://github.com/microsoft/vscode.git + git config --global user.email "$( echo "${GITHUB_USERNAME}" | awk '{print tolower($0)}' )-ci@not-real.com" + git config --global user.name "${GITHUB_USERNAME} CI" - name: Fetch upstream changes + continue-on-error: true run: | + git remote add upstream https://github.com/microsoft/vscode.git git fetch upstream - - - name: Merge upstream changes - run: | - git checkout -b update-from-upstream - git merge upstream/main - - - name: Push changes to fork - run: | - git push -u origin update-from-upstream + git merge upstream/main || true + git add -A - name: Create pull request - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh pr create --base main --head update-from-upstream --title "Update from upstream" --body "This pull request updates the fork with the latest changes from the upstream repository." + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.BINARIES_RELEASE_PAT }} + commit-message: Fetch upstream ${{ steps.current_date.outputs.time }} + branch: fetch-upstream-${{ steps.current_date.outputs.date }} + title: Fetch upstream ${{ steps.current_date.outputs.date }}