2021-03-10 19:02:52 -05:00
name : Check DB migration conflict
on :
push :
paths :
- "superset/migrations/**"
2024-01-23 23:30:53 -05:00
branches :
- 'master'
pull_request :
paths :
- "superset/migrations/**"
types : [ synchronize, opened, reopened, ready_for_review]
2021-03-10 19:02:52 -05:00
2024-02-01 10:08:41 -05:00
# cancel previous workflow jobs for PRs
concurrency :
group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress : true
2021-03-10 19:02:52 -05:00
jobs :
check_db_migration_conflict :
name : Check DB migration conflict
runs-on : ubuntu-20.04
2023-04-14 11:23:00 -04:00
permissions :
contents : read
pull-requests : write
2021-03-10 19:02:52 -05:00
steps :
- name : "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
2024-02-01 13:56:33 -05:00
uses : actions/checkout@v4
2021-03-10 19:02:52 -05:00
- name : Check and notify
2024-02-01 10:09:10 -05:00
uses : actions/github-script@v7
2021-03-10 19:02:52 -05:00
with :
2023-04-14 11:23:00 -04:00
github-token : ${{ github.token }}
2021-03-10 19:02:52 -05:00
script : |
// API reference : https://octokit.github.io/rest.js
const currentBranch = context.ref.replace('refs/heads/', '');
// Find all pull requests to current branch
2024-02-07 11:26:54 -05:00
const opts = github.rest.pulls.list.endpoint.merge({
2021-03-10 19:02:52 -05:00
owner : context.repo.owner,
repo : context.repo.repo,
base : context.ref,
state : 'open' ,
sort : 'updated' ,
per_page : 100 ,
});
2024-02-07 12:38:45 -05:00
const pulls = await github.paginate(opts);
2021-03-10 19:02:52 -05:00
if (pulls.length > 0) {
console.log(`Found ${pulls.length} open PRs for base branch "${currentBranch}"`)
}
for (const pull of pulls) {
2024-02-07 11:26:54 -05:00
const listFilesOpts = await github.rest.pulls.listFiles.endpoint.merge({
2021-03-10 19:02:52 -05:00
owner : context.repo.owner,
repo : context.repo.repo,
pull_number : pull.number,
});
2024-02-07 12:38:45 -05:00
const files = await github.paginate(listFilesOpts);
2021-03-10 19:02:52 -05:00
if (
files.some(x => x.contents_url.includes('/contents/superset/migrations'))
) {
console.log(`PR #${pull.number} "${pull.title}" also added db migration`)
2024-02-07 11:26:54 -05:00
await github.rest.issues.createComment({
2021-03-10 19:02:52 -05:00
issue_number : context.issue.number,
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : pull.number,
body :
2022-05-12 14:37:43 -04:00
`# 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️ 🙅♂️` +
`❗ @${pull.user.login} Your base branch \`${currentBranch}\` has ` +
2021-03-10 19:02:52 -05:00
'also updated `superset/migrations`.\n' +
'\n' +
2022-05-12 14:37:43 -04:00
'**Please consider rebasing your branch and [resolving potential db migration conflicts](https://github.com/apache/superset/blob/master/CONTRIBUTING.md#merging-db-migrations).**' ,
2021-03-10 19:02:52 -05:00
});
}
}