-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Lukasz Gornicki <[email protected]>
- Loading branch information
1 parent
ac7b58a
commit 9b309c0
Showing
5 changed files
with
142 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
# This action is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# This workflow is designed to work with: | ||
# - autoapprove and automerge workflows for dependabot and asyncapibot. | ||
# - special release branches that we from time to time create in upstream repos. If we open up PRs for them from the very beginning of the release, the release branch will constantly update with new things from the destination branch they are opened against | ||
|
||
# It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch. | ||
# Autoupdating to latest destination branch works only in the context of upstream repo and not forks | ||
|
||
name: autoupdate | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- 'version-bump/**' | ||
- 'dependabot/**' | ||
- 'bot/**' | ||
- 'all-contributors/**' | ||
|
||
jobs: | ||
autoupdate-for-bot: | ||
if: startsWith(github.repository, 'asyncapi/') | ||
name: Autoupdate autoapproved PR created in the upstream | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Autoupdating | ||
uses: docker://chinthakagodawita/autoupdate-action:v1 | ||
env: | ||
GITHUB_TOKEN: '${{ secrets.GH_TOKEN_BOT_EVE }}' | ||
PR_FILTER: "labelled" | ||
PR_LABELS: "autoupdate" | ||
PR_READY_STATE: "ready_for_review" | ||
MERGE_CONFLICT_ACTION: "ignore" | ||
# This action is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# This workflow is designed to work with: | ||
# - autoapprove and automerge workflows for dependabot and asyncapibot. | ||
# - special release branches that we from time to time create in upstream repos. If we open up PRs for them from the very beginning of the release, the release branch will constantly update with new things from the destination branch they are opened against | ||
|
||
# It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch. | ||
# Autoupdating to latest destination branch works only in the context of upstream repo and not forks | ||
|
||
name: autoupdate | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- 'version-bump/**' | ||
- 'dependabot/**' | ||
- 'bot/**' | ||
- 'all-contributors/**' | ||
|
||
jobs: | ||
autoupdate-for-bot: | ||
if: startsWith(github.repository, 'asyncapi/') | ||
name: Autoupdate autoapproved PR created in the upstream | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Autoupdating | ||
uses: docker://chinthakagodawita/autoupdate-action:v1 | ||
env: | ||
GITHUB_TOKEN: '${{ secrets.GH_TOKEN_BOT_EVE }}' | ||
PR_FILTER: "labelled" | ||
PR_LABELS: "autoupdate" | ||
PR_READY_STATE: "ready_for_review" | ||
MERGE_CONFLICT_ACTION: "ignore" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,7 @@ jobs: | |
uses: derberg/manage-files-in-multiple-repositories@beecbe897cf5ed7f3de5a791a3f2d70102fe7c25 | ||
with: | ||
github_token: ${{ secrets.GH_TOKEN }} | ||
patterns_to_include: .github/workflows/scripts,.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml,.github/workflows/add-good-first-issue-labels.yml,.github/workflows/automerge-for-humans-merging.yml,.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml,.github/workflows/automerge-orphans.yml,.github/workflows/automerge.yml,.github/workflows/autoupdate.yml,.github/workflows/help-command.yml,.github/workflows/issues-prs-notifications.yml,.github/workflows/lint-pr-title.yml,.github/workflows/notify-tsc-members-mention.yml,.github/workflows/stale-issues-prs.yml,.github/workflows/welcome-first-time-contrib.yml,.github/workflows/release-announcements.yml,.github/workflows/bounty-program-commands.yml,.github/workflows/please-take-a-look-command.yml | ||
patterns_to_include: .github/workflows/scripts,.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml,.github/workflows/add-good-first-issue-labels.yml,.github/workflows/automerge-for-humans-merging.yml,.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml,.github/workflows/automerge-orphans.yml,.github/workflows/automerge.yml,.github/workflows/autoupdate.yml,.github/workflows/help-command.yml,.github/workflows/issues-prs-notifications.yml,.github/workflows/lint-pr-title.yml,.github/workflows/notify-tsc-members-mention.yml,.github/workflows/stale-issues-prs.yml,.github/workflows/welcome-first-time-contrib.yml,.github/workflows/release-announcements.yml,.github/workflows/bounty-program-commands.yml,.github/workflows/please-take-a-look-command.yml,.github/workflows/update-pr.yml | ||
committer_username: asyncapi-bot | ||
committer_email: [email protected] | ||
commit_message: "ci: update of files from global .github repo" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# This workflow is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# This workflow will run on every comment with /update or /u. And will create merge-commits for the PR. | ||
# This also works with forks, not only with branches in the same repository/organization. | ||
# Currently, does not work with forks in different organizations. | ||
|
||
# This workflow will be distributed to all repositories in the AsyncAPI organization | ||
|
||
name: Update PR branches from fork | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
update-pr: | ||
if: > | ||
startsWith(github.repository, 'asyncapi/') && | ||
github.event.issue.pull_request && | ||
github.event.issue.state != 'closed' && ( | ||
contains(github.event.comment.body, '/update') || | ||
contains(github.event.comment.body, '/u') | ||
) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get Pull Request Details | ||
id: pr | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} | ||
previews: 'merge-info-preview' # https://docs.github.com/en/graphql/overview/schema-previews#merge-info-preview-more-detailed-information-about-a-pull-requests-merge-state-preview | ||
script: | | ||
const prNumber = context.payload.issue.number; | ||
core.debug(`PR Number: ${prNumber}`); | ||
const { data: pr } = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: prNumber | ||
}); | ||
// If the PR has conflicts, we don't want to update it | ||
const updateable = ['behind', 'blocked', 'unknown', 'draft', 'clean'].includes(pr.mergeable_state); | ||
console.log(`PR #${prNumber} is ${pr.mergeable_state} and is ${updateable ? 'updateable' : 'not updateable'}`); | ||
core.setOutput('updateable', updateable); | ||
core.debug(`Updating PR #${prNumber} with head ${pr.head.sha}`); | ||
return { | ||
id: pr.node_id, | ||
number: prNumber, | ||
head: pr.head.sha, | ||
} | ||
- name: Update the Pull Request | ||
if: steps.pr.outputs.updateable == 'true' | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} | ||
script: | | ||
const mutation = `mutation update($input: UpdatePullRequestBranchInput!) { | ||
updatePullRequestBranch(input: $input) { | ||
pullRequest { | ||
mergeable | ||
} | ||
} | ||
}`; | ||
const pr_details = ${{ steps.pr.outputs.result }}; | ||
try { | ||
const { data } = await github.graphql(mutation, { | ||
input: { | ||
pullRequestId: pr_details.id, | ||
expectedHeadOid: pr_details.head, | ||
} | ||
}); | ||
} catch (GraphQLError) { | ||
core.debug(GraphQLError); | ||
if ( | ||
GraphQLError.name === 'GraphqlResponseError' && | ||
GraphQLError.errors.some( | ||
error => error.type === 'FORBIDDEN' || error.type === 'UNAUTHORIZED' | ||
) | ||
) { | ||
// Add comment to PR if the bot doesn't have permissions to update the PR | ||
const comment = `Hi @${context.actor}. Update of PR has failed. It can be due to one of the following reasons: | ||
- I don't have permissions to update this PR. To update your fork with upstream using bot you need to enable [Allow edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) option in the PR. | ||
- The fork is located in an organization, not under your personal profile. No solution for that. You are on your own with manual update. | ||
- There may be a conflict in the PR. Please resolve the conflict and try again.`; | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
body: comment | ||
}); | ||
core.setFailed('Bot does not have permissions to update the PR'); | ||
} else { | ||
core.setFailed(GraphQLError.message); | ||
} | ||
} |