mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-10-06 10:14:55 +02:00
Build on RHEL9 docker image / build (push) Successful in 3m54s
Build on RHEL8 docker image / build (push) Successful in 5m2s
Build and Deploy on local RHEL8 / build (push) Successful in 5m7s
Run Simulator Tests on local RHEL8 / build (push) Successful in 23m30s
Build and Deploy on local RHEL9 / build (push) Canceled after 0s
Run Simulator Tests on local RHEL9 / build (push) Canceled after 0s
* workflow for detector whole word matching from changes in detectorServer folders, matching in pr title description, linked or references issues and prs, change in code with matching labels, add detector labels * comment * do not look at linked issues or prs * removed warning of deprecated node 20 github maybe? * ignore for infrastructure prs * ignore infrastrucutr prs * makign detector labels a reusable workflow and pr synchronize trigger trigger at synchronize and wait for validation worfklow to be done first * synchronize triger just checks if pr validation is complete and successfull, if not it fails, else it will run detector labesl workflow. it will not wait for pr validation * pr validation should also call detector labels workflow * picked up pr_validation from developer and modified * test sync * removed commit * trigger is just for code sync * look at head branch PRs to find it * ignoring some other workflows for now * no need of if as anything failing before the consequent jobs are skipped anyway * ignore tests fo rnow * make detector labels run all * without pr validate * fix error pr * renaming to make sense * naming * all the triggers are in a different workflow and all the big jobs in separate resuable workflows * validate pr type also separated * validation doesnt have any output anymore because its either setfailed or not, the unrelated labesl output have been moved to edit trigger workflow anyway * minor * add file major and minor version labels * give permissions * changing file version labels should also trigger the file version workflow * fix code * more explicit print * more print * typo * if file major and no brekaing api label, throw error * trigger file version workflow also if brekaing api label change * print message * if file label change, check file version directly, if pr edited, then wait for pr validation and then check file ersion workflow
295 lines
9.6 KiB
YAML
295 lines
9.6 KiB
YAML
# This reusable workflow checks changes to receiver_defs.h.
|
|
# It validates the File Major and File Minor labels based on
|
|
# changes to HDF5_WRITER_VERSION or BINARY_WRITER_VERSION.
|
|
#
|
|
# File Major:
|
|
# The value before the decimal point changes.
|
|
#
|
|
# File Minor:
|
|
# Only the value after the decimal point changes.
|
|
#
|
|
# Existing labels are never silently removed. If the labels do not
|
|
# match the detected version change, the workflow fails.
|
|
|
|
name: PR File Version
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
pr_number:
|
|
required: true
|
|
type: number
|
|
|
|
permissions:
|
|
pull-requests: write
|
|
contents: read
|
|
|
|
jobs:
|
|
file-version:
|
|
name: Check file version
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Check file version
|
|
uses: actions/github-script@v8
|
|
with:
|
|
script: |
|
|
const prNumber = ${{ inputs.pr_number }};
|
|
|
|
const filePath =
|
|
'slsReceiverSoftware/src/receiver_defs.h';
|
|
|
|
const versionDefinitions = [
|
|
'HDF5_WRITER_VERSION',
|
|
'BINARY_WRITER_VERSION'
|
|
];
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 1. Get current PR labels.
|
|
* --------------------------------------------------
|
|
*/
|
|
const { data: currentLabels } =
|
|
await github.rest.issues.listLabelsOnIssue({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber
|
|
});
|
|
|
|
const currentLabelNames =
|
|
currentLabels.map(label => label.name);
|
|
|
|
const hasFileMajor =
|
|
currentLabelNames.includes('File Major');
|
|
|
|
const hasFileMinor =
|
|
currentLabelNames.includes('File Minor');
|
|
|
|
const hasBreakingAPI =
|
|
currentLabelNames.includes('Breaking API');
|
|
|
|
/*
|
|
* File Major and File Minor are mutually exclusive.
|
|
*/
|
|
if (hasFileMajor && hasFileMinor) {
|
|
core.setFailed(
|
|
'Both "File Major" and "File Minor" labels are present. Remove both labels and let the workflow determine the correct label based on changes to receiver_defs.h.'
|
|
);
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 2. Get all files changed by the PR.
|
|
* --------------------------------------------------
|
|
*/
|
|
const files = await github.paginate(
|
|
github.rest.pulls.listFiles,
|
|
{
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: prNumber,
|
|
per_page: 100
|
|
}
|
|
);
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 3. Check whether receiver_defs.h was changed.
|
|
* --------------------------------------------------
|
|
*/
|
|
const changedFile = files.find(
|
|
file => file.filename === filePath
|
|
);
|
|
|
|
if (!changedFile) {
|
|
if (hasFileMajor || hasFileMinor) {
|
|
core.setFailed(
|
|
`${filePath} was not changed, but a File Major/File Minor label is present. Remove the label and let the workflow determine the correct label based on changes to receiver_defs.h.`
|
|
);
|
|
return;
|
|
}
|
|
|
|
core.info(
|
|
`${filePath} was not changed. No file version label required.`
|
|
);
|
|
return;
|
|
}
|
|
|
|
core.info(
|
|
`${filePath} was changed. Checking file version definitions.`
|
|
);
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 4. Check the changed lines in the patch.
|
|
* --------------------------------------------------
|
|
*/
|
|
const patch = changedFile.patch || '';
|
|
|
|
const oldVersions = {};
|
|
const newVersions = {};
|
|
|
|
const versionRegex =
|
|
/^([+-])\s*#define\s+(HDF5_WRITER_VERSION|BINARY_WRITER_VERSION)\s+\((\d+)\.(\d+)\)/;
|
|
|
|
for (const line of patch.split('\n')) {
|
|
const match = line.match(versionRegex);
|
|
|
|
if (!match) {
|
|
continue;
|
|
}
|
|
|
|
const changeType = match[1];
|
|
const name = match[2];
|
|
const major = Number(match[3]);
|
|
const minor = Number(match[4]);
|
|
|
|
if (changeType === '-') {
|
|
oldVersions[name] = {
|
|
major,
|
|
minor
|
|
};
|
|
} else if (changeType === '+') {
|
|
newVersions[name] = {
|
|
major,
|
|
minor
|
|
};
|
|
}
|
|
}
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 5. Determine the file version change.
|
|
* --------------------------------------------------
|
|
*/
|
|
let versionChanged = false;
|
|
let majorChange = false;
|
|
|
|
for (const name of versionDefinitions) {
|
|
const oldVersion = oldVersions[name];
|
|
const newVersion = newVersions[name];
|
|
|
|
/*
|
|
* Both old and new definitions must be present
|
|
* in order to identify a version change.
|
|
*/
|
|
if (!oldVersion || !newVersion) {
|
|
continue;
|
|
}
|
|
|
|
/*
|
|
* Ignore the definition if the version did not
|
|
* actually change.
|
|
*/
|
|
if (
|
|
oldVersion.major === newVersion.major &&
|
|
oldVersion.minor === newVersion.minor
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
versionChanged = true;
|
|
|
|
core.info(
|
|
`${name}: ` +
|
|
`${oldVersion.major}.${oldVersion.minor} -> ` +
|
|
`${newVersion.major}.${newVersion.minor}`
|
|
);
|
|
|
|
/*
|
|
* A change before the decimal point is a
|
|
* major version change.
|
|
*/
|
|
if (oldVersion.major !== newVersion.major) {
|
|
majorChange = true;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 6. No relevant version change.
|
|
* --------------------------------------------------
|
|
*/
|
|
if (!versionChanged) {
|
|
if (hasFileMajor || hasFileMinor) {
|
|
core.setFailed(
|
|
`Neither HDF5_WRITER_VERSION nor BINARY_WRITER_VERSION was changed, but a File Major/File Minor label is present. Remove the labels and let the workflow determine the correct label based on changes to receiver_defs.h.`
|
|
);
|
|
return;
|
|
}
|
|
|
|
core.info(
|
|
'Neither HDF5_WRITER_VERSION nor BINARY_WRITER_VERSION was changed. No file version label required.'
|
|
);
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 7. Major version change.
|
|
* --------------------------------------------------
|
|
*/
|
|
if (majorChange) {
|
|
if (hasFileMinor) {
|
|
core.setFailed(
|
|
'A major file version change was detected, but the PR has the "File Minor" label. Remove the "File Minor" label and let the workflow determine the correct label based on changes to receiver_defs.h.'
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (!hasBreakingAPI) {
|
|
core.setFailed(
|
|
'A major file version change was detected, and the PR has not recognized "Breaking API". Please check the checkbox "Breaking API" in the PR description so that the appropriate label can be added to the PR and milestone recalculated.'
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (!hasFileMajor) {
|
|
await github.rest.issues.addLabels({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
labels: ['File Major']
|
|
});
|
|
|
|
core.info(
|
|
'Added label: File Major'
|
|
);
|
|
} else {
|
|
core.info(
|
|
'File Major label and Breaking API label are correctly present.'
|
|
);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* --------------------------------------------------
|
|
* 8. Minor version change.
|
|
* --------------------------------------------------
|
|
*/
|
|
if (hasFileMajor) {
|
|
core.setFailed(
|
|
'Only a minor file version change was detected, but the PR has the "File Major" label. Remove the "File Major" label and let the workflow determine the correct label based on changes to receiver_defs.h.'
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (!hasFileMinor) {
|
|
await github.rest.issues.addLabels({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
labels: ['File Minor']
|
|
});
|
|
|
|
core.info(
|
|
'Added label: File Minor'
|
|
);
|
|
} else {
|
|
core.info(
|
|
'File Minor label is correctly present.'
|
|
);
|
|
} |