-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: update of files from global .github repo (#74)
* ci: update update-maintainers-trigger.yaml workflow from global .github repo --------- Co-authored-by: asyncapi-bot <[email protected]>
- Loading branch information
1 parent
f22cda2
commit df0aa85
Showing
25 changed files
with
2,710 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# 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 | ||
|
||
# Purpose of this workflow is to enable anyone to label issue with 'Good First Issue' and 'area/*' with a single command. | ||
name: Add 'Good First Issue' and 'area/*' labels # if proper comment added | ||
|
||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
jobs: | ||
add-labels: | ||
if: ${{(!github.event.issue.pull_request && github.event.issue.state != 'closed' && github.actor != 'asyncapi-bot') && (contains(github.event.comment.body, '/good-first-issue') || contains(github.event.comment.body, '/gfi' ))}} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Add label | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
script: | | ||
const areas = ['javascript', 'typescript', 'java' , 'go', 'docs', 'ci-cd', 'design']; | ||
const words = context.payload.comment.body.trim().split(" "); | ||
const areaIndex = words.findIndex((word)=> word === '/gfi' || word === '/good-first-issue') + 1 | ||
let area = words[areaIndex]; | ||
switch(area){ | ||
case 'ts': | ||
area = 'typescript'; | ||
break; | ||
case 'js': | ||
area = 'javascript'; | ||
break; | ||
case 'markdown': | ||
area = 'docs'; | ||
break; | ||
} | ||
if(!areas.includes(area)){ | ||
const message = `Hey @${context.payload.sender.login}, your message doesn't follow the requirements, you can try \`/help\`.` | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: message | ||
}) | ||
} else { | ||
// remove area if there is any before adding new labels. | ||
const currentLabels = (await github.rest.issues.listLabelsOnIssue({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
})).data.map(label => label.name); | ||
const shouldBeRemoved = currentLabels.filter(label => (label.startsWith('area/') && !label.endsWith(area))); | ||
shouldBeRemoved.forEach(label => { | ||
github.rest.issues.deleteLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: label, | ||
}); | ||
}); | ||
// Add new labels. | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['good first issue', `area/${area}`] | ||
}); | ||
} |
112 changes: 112 additions & 0 deletions
112
.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml
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,112 @@ | ||
# 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 | ||
|
||
# Purpose of this workflow is to enable anyone to label PR with the following labels: | ||
# `ready-to-merge` and `do-not-merge` labels to get stuff merged or blocked from merging | ||
# `autoupdate` to keep a branch up-to-date with the target branch | ||
|
||
name: Label PRs # if proper comment added | ||
|
||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
jobs: | ||
add-ready-to-merge-label: | ||
if: > | ||
github.event.issue.pull_request && | ||
github.event.issue.state != 'closed' && | ||
github.actor != 'asyncapi-bot' && | ||
( | ||
contains(github.event.comment.body, '/ready-to-merge') || | ||
contains(github.event.comment.body, '/rtm' ) | ||
) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Add ready-to-merge label | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
script: | | ||
const prDetailsUrl = context.payload.issue.pull_request.url; | ||
const { data: pull } = await github.request(prDetailsUrl); | ||
const { draft: isDraft} = pull; | ||
if(!isDraft) { | ||
console.log('adding ready-to-merge label...'); | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['ready-to-merge'] | ||
}) | ||
} | ||
const { data: comparison } = | ||
await github.rest.repos.compareCommitsWithBasehead({ | ||
owner: pull.head.repo.owner.login, | ||
repo: pull.head.repo.name, | ||
basehead: `${pull.base.label}...${pull.head.label}`, | ||
}); | ||
if (comparison.behind_by !== 0 && pull.mergeable_state === 'behind') { | ||
console.log(`This branch is behind the target by ${comparison.behind_by} commits`) | ||
console.log('adding out-of-date comment...'); | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Hello, @${{ github.actor }}! 👋🏼 | ||
This PR is not up to date with the base branch and can't be merged. | ||
Please update your branch manually with the latest version of the base branch. | ||
PRO-TIP: To request an update from the upstream branch, simply comment \`/u\` or \`/update\` and our bot will handle the update operation promptly. | ||
The only requirement for this to work is 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 your PR. Also the update will not work if your fork is located in an organization, not under your personal profile. | ||
Thanks 😄` | ||
}) | ||
} | ||
add-do-not-merge-label: | ||
if: > | ||
github.event.issue.pull_request && | ||
github.event.issue.state != 'closed' && | ||
github.actor != 'asyncapi-bot' && | ||
( | ||
contains(github.event.comment.body, '/do-not-merge') || | ||
contains(github.event.comment.body, '/dnm' ) | ||
) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Add do-not-merge label | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
script: | | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['do-not-merge'] | ||
}) | ||
add-autoupdate-label: | ||
if: > | ||
github.event.issue.pull_request && | ||
github.event.issue.state != 'closed' && | ||
github.actor != 'asyncapi-bot' && | ||
( | ||
contains(github.event.comment.body, '/autoupdate') || | ||
contains(github.event.comment.body, '/au' ) | ||
) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Add autoupdate label | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
script: | | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['autoupdate'] | ||
}) |
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,55 @@ | ||
# 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 | ||
|
||
# Purpose of this workflow is to allow people to merge PR without a need of maintainer doing it. If all checks are in place (including maintainers approval) - JUST MERGE IT! | ||
name: Automerge For Humans | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- labeled | ||
- unlabeled | ||
- synchronize | ||
- opened | ||
- edited | ||
- ready_for_review | ||
- reopened | ||
- unlocked | ||
|
||
jobs: | ||
automerge-for-humans: | ||
if: github.event.pull_request.draft == false && (github.event.pull_request.user.login != 'asyncapi-bot' || github.event.pull_request.user.login != 'dependabot[bot]' || github.event.pull_request.user.login != 'dependabot-preview[bot]') #it runs only if PR actor is not a bot, at least not a bot that we know | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get list of authors | ||
uses: sergeysova/jq-action@v2 | ||
id: authors | ||
with: | ||
# This cmd does following (line by line): | ||
# 1. CURL querying the list of commits of the current PR via GH API. Why? Because the current event payload does not carry info about the commits. | ||
# 2. Iterates over the previous returned payload, and creates an array with the filtered results (see below) so we can work wit it later. An example of payload can be found in https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-example-34. | ||
# 3. Grabs the data we need for adding the `Co-authored-by: ...` lines later and puts it into objects to be used later on. | ||
# 4. Filters the results by excluding the current PR sender. We don't need to add it as co-author since is the PR creator and it will become by default the main author. | ||
# 5. Removes repeated authors (authors can have more than one commit in the PR). | ||
# 6. Builds the `Co-authored-by: ...` lines with actual info. | ||
# 7. Transforms the array into plain text. Thanks to this, the actual stdout of this step can be used by the next Workflow step (wich is basically the automerge). | ||
cmd: | | ||
curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" "${{github.event.pull_request._links.commits.href}}?per_page=100" | | ||
jq -r '[.[] | ||
| {name: .commit.author.name, email: .commit.author.email, login: .author.login}] | ||
| map(select(.login != "${{github.event.pull_request.user.login}}")) | ||
| unique | ||
| map("Co-authored-by: " + .name + " <" + .email + ">") | ||
| join("\n")' | ||
multiline: true | ||
- name: Automerge PR | ||
uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6 | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}" | ||
MERGE_LABELS: "!do-not-merge,ready-to-merge" | ||
MERGE_METHOD: "squash" | ||
# Using the output of the previous step (`Co-authored-by: ...` lines) as commit description. | ||
# Important to keep 2 empty lines as https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line mentions | ||
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ steps.authors.outputs.value }}" | ||
MERGE_RETRIES: "20" | ||
MERGE_RETRY_SLEEP: "30000" |
32 changes: 32 additions & 0 deletions
32
.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml
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,32 @@ | ||
# 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 | ||
|
||
# Defence from evil contributor that after adding `ready-to-merge` all suddenly makes evil commit or evil change in PR title | ||
# Label is removed once above action is detected | ||
name: Remove ready-to-merge label | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- synchronize | ||
- edited | ||
|
||
jobs: | ||
remove-ready-label: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Remove label | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
script: | | ||
const labelToRemove = 'ready-to-merge'; | ||
const labels = context.payload.pull_request.labels; | ||
const isLabelPresent = labels.some(label => label.name === labelToRemove) | ||
if(!isLabelPresent) return; | ||
github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: labelToRemove | ||
}) |
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,66 @@ | ||
# 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 | ||
|
||
name: 'Notify on failing automerge' | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
identify-orphans: | ||
if: startsWith(github.repository, 'asyncapi/') | ||
name: Find orphans and notify | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Get list of orphans | ||
uses: actions/github-script@v6 | ||
id: orphans | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const query = `query($owner:String!, $name:String!) { | ||
repository(owner:$owner, name:$name){ | ||
pullRequests(first: 100, states: OPEN){ | ||
nodes{ | ||
title | ||
url | ||
author { | ||
resourcePath | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const variables = { | ||
owner: context.repo.owner, | ||
name: context.repo.repo | ||
}; | ||
const { repository: { pullRequests: { nodes } } } = await github.graphql(query, variables); | ||
let orphans = nodes.filter( (pr) => pr.author.resourcePath === '/asyncapi-bot' || pr.author.resourcePath === '/apps/dependabot') | ||
if (orphans.length) { | ||
core.setOutput('found', 'true'); | ||
//Yes, this is very naive approach to assume there is just one PR causing issues, there can be a case that more PRs are affected the same day | ||
//The thing is that handling multiple PRs will increase a complexity in this PR that in my opinion we should avoid | ||
//The other PRs will be reported the next day the action runs, or person that checks first url will notice the other ones | ||
core.setOutput('url', orphans[0].url); | ||
core.setOutput('title', orphans[0].title); | ||
} | ||
- if: steps.orphans.outputs.found == 'true' | ||
name: Convert markdown to slack markdown | ||
uses: asyncapi/.github/.github/actions/slackify-markdown@master | ||
id: issuemarkdown | ||
with: | ||
markdown: "-> [${{steps.orphans.outputs.title}}](${{steps.orphans.outputs.url}})" | ||
- if: steps.orphans.outputs.found == 'true' | ||
name: Send info about orphan to slack | ||
uses: rtCamp/action-slack-notify@v2 | ||
env: | ||
SLACK_WEBHOOK: ${{secrets.SLACK_CI_FAIL_NOTIFY}} | ||
SLACK_TITLE: 🚨 Not merged PR that should be automerged 🚨 | ||
SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}} | ||
MSG_MINIMAL: true |
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,52 @@ | ||
# 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. | ||
|
||
name: Automerge PRs from bots | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- synchronize | ||
|
||
jobs: | ||
autoapprove-for-bot: | ||
name: Autoapprove PR comming from a bot | ||
if: > | ||
contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.event.pull_request.user.login) && | ||
contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.actor) && | ||
!contains(github.event.pull_request.labels.*.name, 'released') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Autoapproving | ||
uses: hmarr/auto-approve-action@44888193675f29a83e04faf4002fa8c0b537b1e4 # v3.2.1 is used https://github.com/hmarr/auto-approve-action/releases/tag/v3.2.1 | ||
with: | ||
github-token: "${{ secrets.GH_TOKEN_BOT_EVE }}" | ||
|
||
- name: Label autoapproved | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
script: | | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['autoapproved', 'autoupdate'] | ||
}) | ||
automerge-for-bot: | ||
name: Automerge PR autoapproved by a bot | ||
needs: [autoapprove-for-bot] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Automerging | ||
uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6 | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}" | ||
GITHUB_LOGIN: asyncapi-bot | ||
MERGE_LABELS: "!do-not-merge" | ||
MERGE_METHOD: "squash" | ||
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})" | ||
MERGE_RETRIES: "20" | ||
MERGE_RETRY_SLEEP: "30000" |
Oops, something went wrong.