Skip to content

Commit

Permalink
fix: PR creation when not up-to-date [DT-7485] (#314)
Browse files Browse the repository at this point in the history
* fix: PR creation when not up-to-date

* fix: Environment variables in between jobs

* fix: Checkout tag

* fix: Push new branch

* fix: Adjust permissions

* fix: Adjust permissions

* fix: Adjust permissions

* fix: Adjust permissions

* fix: Adjust permissions

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Set user/email for commit

* fix: debugging

* fix: debugging

* fix: debugging

* fix: debugging

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Exclude workflow files

* fix: Create PR in coveooss repo

* fix: Create PR in coveooss repo

* fix: Create PR in coveooss repo

* fix: Write all permissions

* fix: Without `env`

* fix: With `github.token`

* fix: Removed the repo

* fix: Added the repo

* fix: Debug auth status

* fix: Use `github-script`

* fix: Syntax in workflow

* fix: Syntax in workflow

* feat: Notify on Slack

* feat: Notify on Slack

* ci: testing

* feat: Use `slackapi/[email protected]`

* ci: Testing

* ci: Testing

* ci: Testing

* ci: Testing

* ci: Testing

* ci: Remove logging

* ci: Set permissions

* ci: Change bool
  • Loading branch information
nicolegros authored Nov 26, 2024
1 parent d04752b commit 8d56aa8
Showing 1 changed file with 66 additions and 13 deletions.
79 changes: 66 additions & 13 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ on:
- cron: '0 12 * * *' # Runs daily at 12:00 UTC
workflow_dispatch: # Allows manual triggering of the workflow

permissions: {}

jobs:
check-latest-release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0

- name: Fetch Latest Release from Upstream
id: latest-release
Expand All @@ -33,25 +38,73 @@ jobs:
echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" >> $GITHUB_ENV
echo "LATEST_RELEASE_COMMIT=$LATEST_RELEASE_COMMIT" >> $GITHUB_ENV
echo "UPSTREAM_OWNER=$UPSTREAM_OWNER" >> $GITHUB_ENV
echo "UPSTREAM_REPO=$UPSTREAM_REPO" >> $GITHUB_ENV
- name: Check if Fork Contains Latest Release Commit
run: |
if git merge-base --is-ancestor $LATEST_RELEASE_COMMIT HEAD; then
echo "Your fork contains the latest release commit from the upstream repository ($LATEST_RELEASE_COMMIT)."
echo "UP_TO_DATE=true" >> $GITHUB_ENV
else
echo "Your fork does NOT contain the latest release commit from the upstream repository ($LATEST_RELEASE_COMMIT)."
echo "UP_TO_DATE=false" >> $GITHUB_ENV
echo "UPDATE=true" >> $GITHUB_ENV
fi
- name: Create PR
if: env.UP_TO_DATE == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add upstream repository
if: env.UPDATE
run: |
git remote add upstream https://github.com/$UPSTREAM_OWNER/$UPSTREAM_REPO.git
git fetch upstream --tags
- name: Create branch from upstream tag
if: env.UPDATE
run: |
git fetch upstream $LATEST_RELEASE_TAG
git checkout $LATEST_RELEASE_TAG
new_branch="pr-from-$LATEST_RELEASE_TAG"
git checkout -b "$new_branch"
echo "NEW_BRANCH=$new_branch" >> $GITHUB_ENV
- name: Exclude workflow files from the branch
if: env.UPDATE
run: |
git config --global user.email "[email protected]"
git config --global user.name "coveobot"
git restore --source=origin/main -- .github
git add .github/
git commit -m "chore: checkout .github/ files from main branch"
- name: Push branch to fork
if: env.UPDATE
run: |
gh pr create \
--title "Update from Upstream ($LATEST_RELEASE_TAG)" \
--body "This PR updates the fork with the latest changes from upstream, including the latest release tag: $LATEST_RELEASE_TAG." \
--head update-from-upstream \
--base main
git push origin $NEW_BRANCH
- name: Open pull request
if: env.UPDATE
id: open-pull-request
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
github-token: ${{ github.token }}
result-encoding: string
script: |
const {data} = await github.rest.pulls.create({
owner: 'coveooss',
repo: '${{ env.UPSTREAM_REPO }}',
head: '${{ env.NEW_BRANCH }}',
base: 'main',
title: "chore: Update from ${{ env.UPSTREAM_OWNER }}/${{ env.UPSTREAM_REPO }} (${{ env.LATEST_RELEASE_TAG }})",
body: "A new tag (${{ env.LATEST_RELEASE_TAG }}) has been released in the upstream repository (${{ env.UPSTREAM_OWNER }}/${{ env.UPSTREAM_REPO }}). This PR updates the main branch to this version. "
})
return data.html_url
- name: Slack Notify
uses: slackapi/[email protected]
if: env.UPDATE
with:
method: chat.postMessage
token: ${{ secrets.RELEASE_SLACK_BOT_TOKEN }}
errors: true
payload: |
channel: "C05H5DA6CE8"
text: "New pull request in https://github.com/${{ github.repository }} \n ${{ steps.open-pull-request.outputs.result}}"

0 comments on commit 8d56aa8

Please sign in to comment.