Skip to content

Commit 4c3666e

Browse files
authored
ci: update global workflows
1 parent 2c8b765 commit 4c3666e

14 files changed

+536
-36
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 `ready-to-merge` and `do-not-merge` labels to get stuff merged or blocked from merging
5+
name: Add ready-to-merge or do-not-merge label # if proper comment added
6+
7+
on:
8+
issue_comment:
9+
types:
10+
- created
11+
12+
jobs:
13+
parse-comment-and-add-ready: # for handling cases when you want to mark as ready to merge
14+
if: github.event.issue.pull_request && github.event.issue.state != 'closed' && github.actor != 'asyncapi-bot'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check if PR is draft # such info is not available in the context of issue_comment event
18+
uses: actions/github-script@v5
19+
id: checkDraft
20+
with:
21+
result-encoding: string
22+
script: |
23+
const prDetailsUrl = context.payload.issue.pull_request.url;
24+
const response = await github.request(prDetailsUrl);
25+
return response.data.draft;
26+
- name: Add label
27+
if: steps.checkDraft.outputs.result == 'false' && (contains(github.event.comment.body, '/ready-to-merge') || contains(github.event.comment.body, '/rtm' ))
28+
uses: actions/github-script@v5
29+
with:
30+
github-token: ${{ secrets.GH_TOKEN }}
31+
script: |
32+
github.rest.issues.addLabels({
33+
issue_number: context.issue.number,
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
labels: ['ready-to-merge']
37+
})
38+
39+
parse-comment-and-add-block: # for handling cases when you want to mark as do-not-merge
40+
if: github.event.issue.pull_request && github.event.issue.state != 'closed' && github.actor != 'asyncapi-bot'
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Add label
44+
if: contains(github.event.comment.body, '/do-not-merge') || contains(github.event.comment.body, '/dnm' )
45+
uses: actions/github-script@v5
46+
with:
47+
github-token: ${{ secrets.GH_TOKEN }}
48+
script: |
49+
github.rest.issues.addLabels({
50+
issue_number: context.issue.number,
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
labels: ['do-not-merge']
54+
})
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+
#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: Automerge PR
25+
uses: pascalgn/automerge-action@v0.14.3
26+
env:
27+
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
28+
MERGE_LABELS: "!do-not-merge,ready-to-merge"
29+
MERGE_METHOD: "squash"
30+
MERGE_COMMIT_MESSAGE: "pull-request-title"
31+
MERGE_RETRIES: "20"
32+
MERGE_RETRY_SLEEP: "30000"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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@v5
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+
26+
const isLabelPresent = labels.some(label => label.name === labelToRemove)
27+
28+
if(!isLabelPresent) return;
29+
30+
github.rest.issues.removeLabel({
31+
issue_number: context.issue.number,
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
name: labelToRemove
35+
})

.github/workflows/automerge.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
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.
33

44
name: Automerge release bump PR
55

@@ -17,31 +17,43 @@ on:
1717
pull_request_review:
1818
types:
1919
- submitted
20-
20+
2121
jobs:
2222

2323
autoapprove:
24-
if: github.event.pull_request.draft == false
24+
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]') && !contains(github.event.pull_request.labels.*.name, 'released')
2525
runs-on: ubuntu-latest
2626
steps:
2727
- name: Autoapproving
2828
uses: hmarr/auto-approve-action@v2
29-
if: github.actor == ('asyncapi-bot' || github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]') && !contains(github.event.pull_request.labels.*.name, 'released')
3029
with:
3130
github-token: "${{ secrets.GITHUB_TOKEN }}"
3231

32+
- name: Label autoapproved
33+
uses: actions/github-script@v5
34+
with:
35+
github-token: ${{ secrets.GH_TOKEN }}
36+
script: |
37+
github.rest.issues.addLabels({
38+
issue_number: context.issue.number,
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
labels: ['autoapproved']
42+
})
43+
44+
3345
automerge:
3446
needs: [autoapprove]
47+
if: 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]'
3548
runs-on: ubuntu-latest
3649
steps:
3750
- name: Automerging
3851
uses: pascalgn/automerge-action@v0.13.0
39-
if: github.actor == 'asyncapi-bot' || github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
4052
env:
4153
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
4254
GITHUB_LOGIN: asyncapi-bot
4355
MERGE_LABELS: ""
4456
MERGE_METHOD: "squash"
4557
MERGE_COMMIT_MESSAGE: "pull-request-title"
4658
MERGE_RETRIES: "20"
47-
MERGE_RETRY_SLEEP: "30000"
59+
MERGE_RETRY_SLEEP: "30000"

.github/workflows/autoupdate.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#This workflow is designed to work with:
5+
# - autoapprove and automerge workflows for dependabot and asyncapibot.
6+
# - 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
7+
8+
# It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch.
9+
#Autoupdating to latest destination branch works only in the context of upstream repo and not forks
10+
11+
name: autoupdate
12+
13+
on:
14+
push: {}
15+
16+
jobs:
17+
18+
autoupdate:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Autoupdating
22+
uses: docker://chinthakagodawita/autoupdate-action:v1
23+
env:
24+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
25+
PR_FILTER: "labelled"
26+
PR_LABELS: "autoapproved"
27+
PR_READY_STATE: "ready_for_review"
28+
MERGE_CONFLICT_ACTION: "ignore"

.github/workflows/bump.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
#Purpose of this action is to update npm package in libraries that use it. It is like dependabot for asyncapi npm modules only.
5+
#It runs in a repo after merge of release commit and searches for other packages that use released package. Every found package gets updated with lates version
6+
7+
name: Bump package version in dependent repos - if Node project
8+
9+
on:
10+
#It cannot run on release event as when release is created then version is not yet bumped in package.json
11+
#This means we cannot extract easily latest version and have a risk that package is not yet on npm
12+
push:
13+
branches:
14+
- master
15+
16+
jobs:
17+
bump:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v2
22+
- name: Check if Node.js project and has package.json
23+
id: packagejson
24+
run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false"
25+
- if: steps.packagejson.outputs.exists == 'true' && startsWith(github.event.commits[0].message, 'chore(release):')
26+
name: Bumping latest version of this package in other repositories
27+
uses: derberg/npm-dependency-manager-for-your-github-org@v3
28+
with:
29+
github_token: ${{ secrets.GH_TOKEN }}
30+
committer_username: asyncapi-bot
31+
committer_email: info@asyncapi.io
32+
repos_to_ignore: html-template #this is temporary until react component releases 1.0, then it can be removed

.github/workflows/help-command.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
name: Create help comment
5+
6+
on:
7+
issue_comment:
8+
types:
9+
- created
10+
11+
jobs:
12+
create_help_comment:
13+
if: github.event.issue.pull_request
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions-ecosystem/action-create-comment@v1
17+
if: contains(github.event.comment.body, '/help')
18+
with:
19+
github_token: ${{ secrets.GH_TOKEN }}
20+
body: |
21+
Hello, @${{ github.actor }}! 👋🏼
22+
23+
I'm Genie from the magic lamp. Looks like somebody needs a hand! 🆘
24+
25+
At the moment the following comments are supported in pull requests:
26+
27+
- `/ready-to-merge` or `/rtm` - This comment will trigger automerge of PR in case all required checks are green, approvals in place and do-not-merge label is not added
28+
- `/do-not-merge` or `/dnm` - This comment will block automerging even if all conditions are met and ready-to-merge label is added

.github/workflows/if-nodejs-pr-testing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
matrix:
1717
os: [ubuntu-latest, macos-latest, windows-latest]
1818
steps:
19+
- name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows
20+
run: |
21+
git config --global core.autocrlf false
22+
git config --global core.eol lf
1923
- name: Checkout repository
2024
uses: actions/checkout@v2
2125
- name: Check if Node.js project and has package.json

.github/workflows/if-nodejs-release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
matrix:
2222
os: [ubuntu-latest, macos-latest, windows-latest]
2323
steps:
24+
- name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows
25+
run: |
26+
git config --global core.autocrlf false
27+
git config --global core.eol lf
2428
- name: Checkout repository
2529
uses: actions/checkout@v2
2630
- name: Check if Node.js project and has package.json
@@ -46,6 +50,10 @@ jobs:
4650
name: Publish to NPM and GitHub
4751
runs-on: ubuntu-latest
4852
steps:
53+
- name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows
54+
run: |
55+
git config --global core.autocrlf false
56+
git config --global core.eol lf
4957
- name: Checkout repository
5058
uses: actions/checkout@v2
5159
- name: Check if Node.js project and has package.json
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
#It does magic only if there is package.json file in the root of the project
4+
name: Version bump - if Node.js project
5+
6+
on:
7+
release:
8+
types:
9+
- published
10+
11+
jobs:
12+
version_bump:
13+
name: Generate assets and bump
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
with:
19+
# target branch of release. More info https://docs.github.com/en/rest/reference/repos#releases
20+
# in case release is created from release branch then we need to checkout from given branch
21+
# if @semantic-release/github is used to publish, the minimum version is 7.2.0 for proper working
22+
ref: ${{ github.event.release.target_commitish }}
23+
- name: Check if Node.js project and has package.json
24+
id: packagejson
25+
run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false"
26+
- if: steps.packagejson.outputs.exists == 'true'
27+
name: Install dependencies
28+
run: npm install
29+
- if: steps.packagejson.outputs.exists == 'true'
30+
name: Assets generation
31+
run: npm run generate:assets
32+
- if: steps.packagejson.outputs.exists == 'true'
33+
name: Bump version in package.json
34+
# There is no need to substract "v" from the tag as version script handles it
35+
# When adding "bump:version" script in package.json, make sure no tags are added by default (--no-git-tag-version) as they are already added by release workflow
36+
# When adding "bump:version" script in package.json, make sure --allow-same-version is set in case someone forgot and updated package.json manually and we want to avoide this action to fail and raise confusion
37+
run: VERSION=${{github.event.release.tag_name}} npm run bump:version
38+
- if: steps.packagejson.outputs.exists == 'true'
39+
name: Create Pull Request with updated asset files including package.json
40+
uses: peter-evans/create-pull-request@v3
41+
with:
42+
token: ${{ secrets.GH_TOKEN }}
43+
commit-message: 'chore(release): ${{github.event.release.tag_name}}'
44+
committer: asyncapi-bot <info@asyncapi.io>
45+
author: asyncapi-bot <info@asyncapi.io>
46+
title: 'chore(release): ${{github.event.release.tag_name}}'
47+
body: 'Version bump in package.json for release [${{github.event.release.tag_name}}](${{github.event.release.html_url}})'
48+
branch: version-bump/${{github.event.release.tag_name}}

0 commit comments

Comments
 (0)