Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
dvp2015 committed Sep 7, 2022
2 parents 86361e7 + a1c35a1 commit 5ed6cdf
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 606 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ per-file-ignores =
src/tests/*:S101,ANN,DAR100,D100,D103,DAR101,DAR103
src/xpypact/Inventory.py:F811
src/xpypact/data_arrays.py:ANN401
src/xpypact/utils/resource.py:ANN202
ignore-decorators=click,pytest
docstring-convention = google
rst-roles = class,const,func,meth,mod,ref
Expand Down
123 changes: 60 additions & 63 deletions .github/workflows/combine-prs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: 'Combine PRs'

#
# Source:
# https://dev.to/denvercoder1/keeping-your-dependencies-updated-automatically-with-dependabot-299g
# https://github.com/hrvey/combine-prs-workflow/blob/master/combine-prs.yml
#

# Controls when the action will run - in this case triggered manually
on:
workflow_dispatch:
Expand Down Expand Up @@ -35,38 +37,36 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/github-script@v6
id: fetch-branch-names
name: Fetch branch names
id: create-combined-pr
name: Create Combined PR
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pulls = await github.paginate('GET /repos/:owner/:repo/pulls', {
owner: context.repo.owner,
repo: context.repo.repo
});
branches = [];
prs = [];
base_branch = null;
let branchesAndPRStrings = [];
let baseBranch = null;
let baseBranchSHA = null;
for (const pull of pulls) {
const branch = pull['head']['ref'];
console.log('Pull for branch: ' + branch);
if (branch.startsWith('${{ github.event.inputs.branchPrefix }}')) {
console.log('Branch matched: ' + branch);
statusOK = true;
console.log('Branch matched prefix: ' + branch);
let statusOK = true;
if(${{ github.event.inputs.mustBeGreen }}) {
console.log('Checking green status: ' + branch);
const statuses = await github.paginate('GET /repos/{owner}/{repo}/commits/{ref}/status', {
const statusResponse = await github.rest.repos.getCombinedStatusForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: branch
});
if(statuses.length > 0) {
const latest_status = statuses[0]['state'];
console.log('Validating status: ' + latest_status);
if(latest_status != 'success') {
console.log('Discarding ' + branch + ' with status ' + latest_status);
statusOK = false;
}
const state = statusResponse['data']['state'];
console.log('Validating status: ' + state);
if(state != 'success') {
console.log('Discarding ' + branch + ' with status ' + state);
statusOK = false;
}
}
console.log('Checking labels: ' + branch);
Expand All @@ -81,65 +81,62 @@ jobs:
}
if (statusOK) {
console.log('Adding branch to array: ' + branch);
branches.push(branch);
prs.push('#' + pull['number'] + ' ' + pull['title']);
base_branch = pull['base']['ref'];
const prString = '#' + pull['number'] + ' ' + pull['title'];
branchesAndPRStrings.push({ branch, prString });
baseBranch = pull['base']['ref'];
baseBranchSHA = pull['base']['sha'];
}
} else {
console.log('Branch didn't match prefix: ' + branch);
}
}
if (branches.length == 0) {
if (branchesAndPRStrings.length == 0) {
core.setFailed('No PRs/branches matched criteria');
return;
}
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/heads/' + '${{ github.event.inputs.combineBranchName }}',
sha: baseBranchSHA
});
} catch (error) {
console.log(error);
core.setFailed('Failed to create combined branch - maybe a branch by that name already exists?');
return;
}
core.setOutput('base-branch', base_branch);
core.setOutput('prs-string', prs.join('\n'));
combined = branches.join(' ')
console.log('Combined: ' + combined);
return combined
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/[email protected]
with:
fetch-depth: 0
# Creates a branch with other PR branches merged together
- name: Created combined branch
env:
BASE_BRANCH: ${{ steps.fetch-branch-names.outputs.base-branch }}
BRANCHES_TO_COMBINE: ${{ steps.fetch-branch-names.outputs.result }}
COMBINE_BRANCH_NAME: ${{ github.event.inputs.combineBranchName }}
run: |
echo "$BRANCHES_TO_COMBINE"
sourcebranches="${BRANCHES_TO_COMBINE%\"}"
sourcebranches="${sourcebranches#\"}"
basebranch="${BASE_BRANCH%\"}"
basebranch="${basebranch#\"}"
git config pull.rebase false
git config user.name github-actions
git config user.email [email protected]
let combinedPRs = [];
let mergeFailedPRs = [];
for(const { branch, prString } of branchesAndPRStrings) {
try {
await github.rest.repos.merge({
owner: context.repo.owner,
repo: context.repo.repo,
base: '${{ github.event.inputs.combineBranchName }}',
head: branch,
});
console.log('Merged branch ' + branch);
combinedPRs.push(prString);
} catch (error) {
console.log('Failed to merge branch ' + branch);
mergeFailedPRs.push(prString);
}
}
git branch $COMBINE_BRANCH_NAME $basebranch
git checkout $COMBINE_BRANCH_NAME
git pull origin $sourcebranches --no-edit
git push origin $COMBINE_BRANCH_NAME
# Creates a PR with the new combined branch
- uses: actions/github-script@v6
name: Create Combined Pull Request
env:
PRS_STRING: ${{ steps.fetch-branch-names.outputs.prs-string }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prString = process.env.PRS_STRING;
const body = 'This PR was created by the Combine PRs action by combining the following PRs:\n' + prString;
await github.pulls.create({
console.log('Creating combined PR');
const combinedPRsString = combinedPRs.join('\n');
let body = '✅ This PR was created by the Combine PRs action by combining the following PRs:\n' + combinedPRsString;
if(mergeFailedPRs.length > 0) {
const mergeFailedPRsString = mergeFailedPRs.join('\n');
body += '\n\n⚠️ The following PRs were left out due to merge conflicts:\n' + mergeFailedPRsString
}
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Combined PR',
head: '${{ github.event.inputs.combineBranchName }}',
base: '${{ steps.fetch-branch-names.outputs.base-branch }}',
base: baseBranch,
body: body
});
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ repos:
types: [python]
- id: flake8
name: flake8
entry: poetry run flake8 src
entry: poetry run flake8
language: system
types: [python]
# Also code format the docs
Expand Down
33 changes: 32 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
from typing import Final, List

import re
import shutil
import sys

Expand Down Expand Up @@ -32,7 +33,37 @@
"docs-build",
)

package: Final = "xpypact"

NAME_RGX = re.compile(r'name\s*=\s*"(?P<package>[_a-zA-Z]*")')


def find_my_name() -> str:
"""Find this package name.
Search the first row in pyproject.toml in format
name = "<package>"
and returns the <package> value.
This allows to reuse the noxfile.py in similar projects
without any changes.
Returns:
str: Current package found in pyproject.toml
Raises:
ValueError: if the pattern is not found.
"""
with Path("pyproject.toml").open() as fid:
for line in fid:
res = NAME_RGX.match(line)
if res is not None:
return res["package"].replace("-", "_")
msg = "Cannot find package name"
raise ValueError(msg)


package: Final = find_my_name()
locations: Final = f"src/{package}", "src/tests", "noxfile.py", "docs/source/conf.py"

supported_pythons: Final = "3.8", "3.9", "3.10", "3.11"
Expand Down
Loading

0 comments on commit 5ed6cdf

Please sign in to comment.