Skip to content

Commit df0aa85

Browse files
asyncapi-botasyncapi-bot
andauthored
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]>
1 parent f22cda2 commit df0aa85

25 files changed

+2710
-21
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This workflow is centrally managed in https://github.com/asyncapi/.github/
2+
# 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
3+
4+
# Purpose of this workflow is to enable anyone to label issue with 'Good First Issue' and 'area/*' with a single command.
5+
name: Add 'Good First Issue' and 'area/*' labels # if proper comment added
6+
7+
on:
8+
issue_comment:
9+
types:
10+
- created
11+
12+
jobs:
13+
add-labels:
14+
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' ))}}
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Add label
18+
uses: actions/github-script@v6
19+
with:
20+
github-token: ${{ secrets.GH_TOKEN }}
21+
script: |
22+
const areas = ['javascript', 'typescript', 'java' , 'go', 'docs', 'ci-cd', 'design'];
23+
const words = context.payload.comment.body.trim().split(" ");
24+
const areaIndex = words.findIndex((word)=> word === '/gfi' || word === '/good-first-issue') + 1
25+
let area = words[areaIndex];
26+
switch(area){
27+
case 'ts':
28+
area = 'typescript';
29+
break;
30+
case 'js':
31+
area = 'javascript';
32+
break;
33+
case 'markdown':
34+
area = 'docs';
35+
break;
36+
}
37+
if(!areas.includes(area)){
38+
const message = `Hey @${context.payload.sender.login}, your message doesn't follow the requirements, you can try \`/help\`.`
39+
40+
await github.rest.issues.createComment({
41+
issue_number: context.issue.number,
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
body: message
45+
})
46+
} else {
47+
48+
// remove area if there is any before adding new labels.
49+
const currentLabels = (await github.rest.issues.listLabelsOnIssue({
50+
issue_number: context.issue.number,
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
})).data.map(label => label.name);
54+
55+
const shouldBeRemoved = currentLabels.filter(label => (label.startsWith('area/') && !label.endsWith(area)));
56+
shouldBeRemoved.forEach(label => {
57+
github.rest.issues.deleteLabel({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
name: label,
61+
});
62+
});
63+
64+
// Add new labels.
65+
github.rest.issues.addLabels({
66+
issue_number: context.issue.number,
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
labels: ['good first issue', `area/${area}`]
70+
});
71+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# This workflow is centrally managed in https://github.com/asyncapi/.github/
2+
# 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
3+
4+
# Purpose of this workflow is to enable anyone to label PR with the following labels:
5+
# `ready-to-merge` and `do-not-merge` labels to get stuff merged or blocked from merging
6+
# `autoupdate` to keep a branch up-to-date with the target branch
7+
8+
name: Label PRs # if proper comment added
9+
10+
on:
11+
issue_comment:
12+
types:
13+
- created
14+
15+
jobs:
16+
add-ready-to-merge-label:
17+
if: >
18+
github.event.issue.pull_request &&
19+
github.event.issue.state != 'closed' &&
20+
github.actor != 'asyncapi-bot' &&
21+
(
22+
contains(github.event.comment.body, '/ready-to-merge') ||
23+
contains(github.event.comment.body, '/rtm' )
24+
)
25+
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Add ready-to-merge label
29+
uses: actions/github-script@v6
30+
with:
31+
github-token: ${{ secrets.GH_TOKEN }}
32+
script: |
33+
const prDetailsUrl = context.payload.issue.pull_request.url;
34+
const { data: pull } = await github.request(prDetailsUrl);
35+
const { draft: isDraft} = pull;
36+
if(!isDraft) {
37+
console.log('adding ready-to-merge label...');
38+
github.rest.issues.addLabels({
39+
issue_number: context.issue.number,
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
labels: ['ready-to-merge']
43+
})
44+
}
45+
46+
const { data: comparison } =
47+
await github.rest.repos.compareCommitsWithBasehead({
48+
owner: pull.head.repo.owner.login,
49+
repo: pull.head.repo.name,
50+
basehead: `${pull.base.label}...${pull.head.label}`,
51+
});
52+
if (comparison.behind_by !== 0 && pull.mergeable_state === 'behind') {
53+
console.log(`This branch is behind the target by ${comparison.behind_by} commits`)
54+
console.log('adding out-of-date comment...');
55+
github.rest.issues.createComment({
56+
issue_number: context.issue.number,
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
body: `Hello, @${{ github.actor }}! 👋🏼
60+
This PR is not up to date with the base branch and can't be merged.
61+
Please update your branch manually with the latest version of the base branch.
62+
PRO-TIP: To request an update from the upstream branch, simply comment \`/u\` or \`/update\` and our bot will handle the update operation promptly.
63+
64+
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.
65+
Thanks 😄`
66+
})
67+
}
68+
69+
add-do-not-merge-label:
70+
if: >
71+
github.event.issue.pull_request &&
72+
github.event.issue.state != 'closed' &&
73+
github.actor != 'asyncapi-bot' &&
74+
(
75+
contains(github.event.comment.body, '/do-not-merge') ||
76+
contains(github.event.comment.body, '/dnm' )
77+
)
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: Add do-not-merge label
81+
uses: actions/github-script@v6
82+
with:
83+
github-token: ${{ secrets.GH_TOKEN }}
84+
script: |
85+
github.rest.issues.addLabels({
86+
issue_number: context.issue.number,
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
labels: ['do-not-merge']
90+
})
91+
add-autoupdate-label:
92+
if: >
93+
github.event.issue.pull_request &&
94+
github.event.issue.state != 'closed' &&
95+
github.actor != 'asyncapi-bot' &&
96+
(
97+
contains(github.event.comment.body, '/autoupdate') ||
98+
contains(github.event.comment.body, '/au' )
99+
)
100+
runs-on: ubuntu-latest
101+
steps:
102+
- name: Add autoupdate label
103+
uses: actions/github-script@v6
104+
with:
105+
github-token: ${{ secrets.GH_TOKEN }}
106+
script: |
107+
github.rest.issues.addLabels({
108+
issue_number: context.issue.number,
109+
owner: context.repo.owner,
110+
repo: context.repo.repo,
111+
labels: ['autoupdate']
112+
})
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow is centrally managed in https://github.com/asyncapi/.github/
2+
# 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
3+
4+
# 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!
5+
name: Automerge For Humans
6+
7+
on:
8+
pull_request_target:
9+
types:
10+
- labeled
11+
- unlabeled
12+
- synchronize
13+
- opened
14+
- edited
15+
- ready_for_review
16+
- reopened
17+
- unlocked
18+
19+
jobs:
20+
automerge-for-humans:
21+
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
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Get list of authors
25+
uses: sergeysova/jq-action@v2
26+
id: authors
27+
with:
28+
# This cmd does following (line by line):
29+
# 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.
30+
# 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.
31+
# 3. Grabs the data we need for adding the `Co-authored-by: ...` lines later and puts it into objects to be used later on.
32+
# 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.
33+
# 5. Removes repeated authors (authors can have more than one commit in the PR).
34+
# 6. Builds the `Co-authored-by: ...` lines with actual info.
35+
# 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).
36+
cmd: |
37+
curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" "${{github.event.pull_request._links.commits.href}}?per_page=100" |
38+
jq -r '[.[]
39+
| {name: .commit.author.name, email: .commit.author.email, login: .author.login}]
40+
| map(select(.login != "${{github.event.pull_request.user.login}}"))
41+
| unique
42+
| map("Co-authored-by: " + .name + " <" + .email + ">")
43+
| join("\n")'
44+
multiline: true
45+
- name: Automerge PR
46+
uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6
47+
env:
48+
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
49+
MERGE_LABELS: "!do-not-merge,ready-to-merge"
50+
MERGE_METHOD: "squash"
51+
# Using the output of the previous step (`Co-authored-by: ...` lines) as commit description.
52+
# 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
53+
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ steps.authors.outputs.value }}"
54+
MERGE_RETRIES: "20"
55+
MERGE_RETRY_SLEEP: "30000"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow is centrally managed in https://github.com/asyncapi/.github/
2+
# 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
3+
4+
# Defence from evil contributor that after adding `ready-to-merge` all suddenly makes evil commit or evil change in PR title
5+
# Label is removed once above action is detected
6+
name: Remove ready-to-merge label
7+
8+
on:
9+
pull_request_target:
10+
types:
11+
- synchronize
12+
- edited
13+
14+
jobs:
15+
remove-ready-label:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Remove label
19+
uses: actions/github-script@v6
20+
with:
21+
github-token: ${{ secrets.GH_TOKEN }}
22+
script: |
23+
const labelToRemove = 'ready-to-merge';
24+
const labels = context.payload.pull_request.labels;
25+
const isLabelPresent = labels.some(label => label.name === labelToRemove)
26+
if(!isLabelPresent) return;
27+
github.rest.issues.removeLabel({
28+
issue_number: context.issue.number,
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
name: labelToRemove
32+
})
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This action is centrally managed in https://github.com/asyncapi/.github/
2+
# 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
3+
4+
name: 'Notify on failing automerge'
5+
6+
on:
7+
schedule:
8+
- cron: "0 0 * * *"
9+
10+
jobs:
11+
identify-orphans:
12+
if: startsWith(github.repository, 'asyncapi/')
13+
name: Find orphans and notify
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v3
18+
- name: Get list of orphans
19+
uses: actions/github-script@v6
20+
id: orphans
21+
with:
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
script: |
24+
const query = `query($owner:String!, $name:String!) {
25+
repository(owner:$owner, name:$name){
26+
pullRequests(first: 100, states: OPEN){
27+
nodes{
28+
title
29+
url
30+
author {
31+
resourcePath
32+
}
33+
}
34+
}
35+
}
36+
}`;
37+
const variables = {
38+
owner: context.repo.owner,
39+
name: context.repo.repo
40+
};
41+
const { repository: { pullRequests: { nodes } } } = await github.graphql(query, variables);
42+
43+
let orphans = nodes.filter( (pr) => pr.author.resourcePath === '/asyncapi-bot' || pr.author.resourcePath === '/apps/dependabot')
44+
45+
if (orphans.length) {
46+
core.setOutput('found', 'true');
47+
//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
48+
//The thing is that handling multiple PRs will increase a complexity in this PR that in my opinion we should avoid
49+
//The other PRs will be reported the next day the action runs, or person that checks first url will notice the other ones
50+
core.setOutput('url', orphans[0].url);
51+
core.setOutput('title', orphans[0].title);
52+
}
53+
- if: steps.orphans.outputs.found == 'true'
54+
name: Convert markdown to slack markdown
55+
uses: asyncapi/.github/.github/actions/slackify-markdown@master
56+
id: issuemarkdown
57+
with:
58+
markdown: "-> [${{steps.orphans.outputs.title}}](${{steps.orphans.outputs.url}})"
59+
- if: steps.orphans.outputs.found == 'true'
60+
name: Send info about orphan to slack
61+
uses: rtCamp/action-slack-notify@v2
62+
env:
63+
SLACK_WEBHOOK: ${{secrets.SLACK_CI_FAIL_NOTIFY}}
64+
SLACK_TITLE: 🚨 Not merged PR that should be automerged 🚨
65+
SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}}
66+
MSG_MINIMAL: true

.github/workflows/automerge.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This action is centrally managed in https://github.com/asyncapi/.github/
2+
# 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.
3+
4+
name: Automerge PRs from bots
5+
6+
on:
7+
pull_request_target:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
autoapprove-for-bot:
14+
name: Autoapprove PR comming from a bot
15+
if: >
16+
contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.event.pull_request.user.login) &&
17+
contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.actor) &&
18+
!contains(github.event.pull_request.labels.*.name, 'released')
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Autoapproving
22+
uses: hmarr/auto-approve-action@44888193675f29a83e04faf4002fa8c0b537b1e4 # v3.2.1 is used https://github.com/hmarr/auto-approve-action/releases/tag/v3.2.1
23+
with:
24+
github-token: "${{ secrets.GH_TOKEN_BOT_EVE }}"
25+
26+
- name: Label autoapproved
27+
uses: actions/github-script@v6
28+
with:
29+
github-token: ${{ secrets.GH_TOKEN }}
30+
script: |
31+
github.rest.issues.addLabels({
32+
issue_number: context.issue.number,
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
labels: ['autoapproved', 'autoupdate']
36+
})
37+
38+
automerge-for-bot:
39+
name: Automerge PR autoapproved by a bot
40+
needs: [autoapprove-for-bot]
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Automerging
44+
uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6
45+
env:
46+
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
47+
GITHUB_LOGIN: asyncapi-bot
48+
MERGE_LABELS: "!do-not-merge"
49+
MERGE_METHOD: "squash"
50+
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})"
51+
MERGE_RETRIES: "20"
52+
MERGE_RETRY_SLEEP: "30000"

0 commit comments

Comments
 (0)