2023-02-23 05:08:44 +08:00
name : Check For Common Mistakes
2021-07-27 05:26:28 +08:00
on :
pull_request :
jobs :
2023-02-23 05:08:44 +08:00
Check :
2022-09-24 02:36:45 +08:00
runs-on : ubuntu-22.04
2021-07-27 05:26:28 +08:00
steps :
2023-02-23 05:08:44 +08:00
- name : Checkout
2024-02-02 06:59:24 +08:00
uses : actions/checkout@v4
2021-07-27 05:26:28 +08:00
with :
2021-09-17 02:33:07 +08:00
# fetch-depth 50 tries to ensure we capture the whole history of the branch
fetch-depth : 50
2021-07-27 05:26:28 +08:00
2023-02-23 05:08:44 +08:00
- name : Bootstrap
2021-07-27 05:26:28 +08:00
run : ./bootstrap-vcpkg.sh
- name : Formatting
run : |
git config user.email github-actions
git config user.name github-actions@github.com
2022-09-23 07:55:36 +08:00
git --version
2022-10-14 07:15:20 +08:00
unset VCPKG_ROOT
2022-09-24 02:36:45 +08:00
2023-02-24 09:11:15 +08:00
git diff --name-status --merge-base HEAD^ HEAD --diff-filter=MAR -- '*portfile.cmake' | sed 's/[MAR]\t*//' > .github-pr.changed-portfiles
2023-06-01 02:54:31 +08:00
if [ -s .github-pr.changed-portfiles ]; then (grep -n -H -E '(vcpkg_apply_patches|vcpkg_build_msbuild|vcpkg_extract_source_archive_ex)' $(cat .github-pr.changed-portfiles) || true) > .github-pr.deprecated-function; else touch .github-pr.deprecated-function; fi
if [ -s .github-pr.changed-portfiles ]; then (grep -n -H -E '(vcpkg_install_cmake|vcpkg_build_cmake|vcpkg_configure_cmake|vcpkg_fixup_cmake_targets)' $(cat .github-pr.changed-portfiles) || true) > .github-pr.deprecated-cmake; else touch .github-pr.deprecated-cmake; fi
2022-04-28 03:58:45 +08:00
git diff --name-status --merge-base HEAD^ HEAD --diff-filter=MAR -- '*vcpkg.json' | sed 's/[MAR]\t*//' > .github-pr.changed-manifest-files
2023-02-23 05:08:44 +08:00
cat .github-pr.changed-manifest-files | while read filename; do grep -q -E '"license": ' "$filename" || echo "$filename" || true; done > .github-pr.missing-license
cat .github-pr.changed-manifest-files | while read filename; do match=$(grep -oiP '"license": ".*\K(AGPL-1\.0|AGPL-3\.0|BSD-2-Clause-FreeBSD|BSD-2-Clause-NetBSD|bzip2-1\.0\.5|eCos-2\.0|GFDL-1\.1|GFDL-1\.2|GFDL-1\.3|GPL-1\.0|GPL-1\.0\+|GPL-2\.0|GPL-2\.0\+|GPL-2\.0-with-autoconf-exception|GPL-2\.0-with-bison-exception|GPL-2\.0-with-classpath-exception|GPL-2\.0-with-font-exception|GPL-2\.0-with-GCC-exception|GPL-3\.0|GPL-3\.0\+|GPL-3\.0-with-autoconf-exception|GPL-3\.0-with-GCC-exception|LGPL-2\.0|LGPL-2\.0\+|LGPL-2\.1|LGPL-2\.1\+|LGPL-3\.0|LGPL-3\.0\+|Nunit|StandardML-NJ|wxWindows)(?=[ "])' "$filename" || true); if [ ! -z "$match" ]; then echo "$filename (has deprecated license \"$match\")" ; fi ; done > .github-pr.deprecated-license
2021-09-14 11:05:43 +08:00
./vcpkg format-manifest --all --convert-control
2021-07-27 05:26:28 +08:00
git diff > .github-pr.format-manifest
git add -u
git commit -m "tmp" --allow-empty
# HEAD^^ refers to the "main" commit that was merged into
git checkout HEAD^^ -- versions
git restore --staged versions
2022-04-09 03:58:32 +08:00
./vcpkg x-add-version --all --skip-formatting-check | grep 'instead of "version-string"' | tee .github-pr.version-string.out || true
git checkout -- versions
./vcpkg x-add-version --all --skip-formatting-check --skip-version-format-check | tee .github-pr.x-add-version.out || true
2021-07-27 05:26:28 +08:00
git diff > .github-pr.x-add-version.diff
git reset HEAD~ --mixed
2023-02-23 05:08:44 +08:00
- name : Generate Reply
2024-02-02 06:59:24 +08:00
uses : actions/github-script@v7
2021-07-27 05:26:28 +08:00
with :
script : |
const { promises: fs } = require('fs')
const add_version = (await fs.readFile('.github-pr.x-add-version.diff', 'utf8')).trim()
const add_version_out = (await fs.readFile('.github-pr.x-add-version.out', 'utf8')).trim()
2022-04-09 03:58:32 +08:00
const version_string_out = (await fs.readFile('.github-pr.version-string.out', 'utf8')).trim()
2021-07-27 05:26:28 +08:00
const format = (await fs.readFile('.github-pr.format-manifest', 'utf8')).trim()
2023-06-01 02:54:31 +08:00
const deprecated_function = (await fs.readFile('.github-pr.deprecated-function', 'utf8')).split('\n').filter(s => s.length > 0)
const deprecated_cmake = (await fs.readFile('.github-pr.deprecated-cmake', 'utf8')).split('\n').filter(s => s.length > 0)
2022-01-21 06:04:48 +08:00
const missing_license = (await fs.readFile('.github-pr.missing-license', 'utf8')).trim()
2022-04-28 03:58:45 +08:00
const deprecated_license = (await fs.readFile('.github-pr.deprecated-license', 'utf8')).trim()
2021-07-27 05:26:28 +08:00
2021-09-17 02:33:07 +08:00
let approve = true;
2021-07-27 05:26:28 +08:00
if (format !== "") {
2023-02-23 05:08:44 +08:00
var format_output = '';
format_output += "All vcpkg.json files must be formatted. To fix this problem, run:\n";
format_output += "./vcpkg format-manifest ports/*/vcpkg.json\n";
format_output += "\n";
format_output += "It should make the following changes:";
format_output += "```diff\n" + format + "\n```";
core.error(format_output);
2021-09-17 02:33:07 +08:00
approve = false;
2021-07-27 05:26:28 +08:00
}
if (add_version_out !== "") {
2023-02-23 05:08:44 +08:00
var add_version_output = '';
add_version_output += "PRs must add only one version, and must not modify any published versions.\n";
add_version_output += "When making any changes to a library, the version or port-version in vcpkg.json must be modified, and the version database updated.\n";
add_version_output += "Making the following changes will fix this problem:";
add_version_output += "```diff\n" + add_version_out + "\n```";
core.error(add_version_output);
2021-09-17 02:33:07 +08:00
approve = false;
2021-07-27 05:26:28 +08:00
}
2022-04-09 03:58:32 +08:00
if (version_string_out !== "") {
2023-02-23 05:08:44 +08:00
core.warning(version_string_out);
2022-04-09 03:58:32 +08:00
}
2021-07-27 05:26:28 +08:00
if (add_version !== "") {
2023-02-23 05:08:44 +08:00
var update_version_db_output = '';
update_version_db_output += "After committing all other changes, the version database must be updated.\n";
update_version_db_output += "This can be done by running the following commands after committing your changes:\n"
update_version_db_output += "\n"
update_version_db_output += "git add -u && git commit\n"
update_version_db_output += "git checkout ${{ github.event.pull_request.base.sha }} -- versions\n"
update_version_db_output += "./vcpkg x-add-version --all"
core.error(update_version_db_output);
2021-09-17 02:33:07 +08:00
approve = false;
}
2023-02-24 09:11:15 +08:00
2023-06-01 02:54:31 +08:00
if (deprecated_function.length > 0) {
2023-02-23 05:08:44 +08:00
var deprecated_output = '';
2024-01-04 09:31:13 +08:00
deprecated_output += "**You have modified or added at least one portfile where deprecated functions are used**\n"
2023-02-24 09:11:15 +08:00
deprecated_output += "If you feel able to do so, please consider migrating them to the new functions.\n";
2023-06-01 02:54:31 +08:00
core.warning(deprecated_output);
let deprecated_functions = {
vcpkg_extract_source_archive_ex : 'vcpkg_extract_source_archive https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_extract_source_archive' ,
vcpkg_build_msbuild : 'vcpkg_install_msbuild https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_install_msbuild' ,
vcpkg_apply_patches : 'the PATCHES arguments to the \"extract\" helpers (for example, vcpkg_from_github() (https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_from_github))' ,
};
for (let line of deprecated_function) {
// line has the format : <path>:<line_number>:<matched_string
// For example: ports/rtlsdr/portfile.cmake:42 : vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
[ file, line_number, match] = line.split(':');
for (deprecated_func in deprecated_functions) {
if (match.indexOf(deprecated_func) !== -1) {
core.warning(`The function ${deprecated_func} is deprecated. Please use ${deprecated_functions[deprecated_func]}`, {file, startLine: line_number});
break;
}
}
}
}
if (deprecated_cmake.length > 0) {
var deprecated_output = '';
deprecated_output += "You have modified or added at least one portfile where deprecated functions are used.\n"
deprecated_output += "These functions have been forbidden in vcpkg, please migrating them to the new functions.\n";
deprecated_output += "In the ports that use the new function vcpkg_cmake_configure, vcpkg_cmake_install, vcpkg_cmake_build or vcpkg_cmake_config_fixup, you have to add the corresponding dependencies:\n";
2023-02-23 05:08:44 +08:00
deprecated_output += "```json\n";
deprecated_output += '{\n "name": "vcpkg-cmake",\n "host": true\n},\n'
deprecated_output += '{\n "name": "vcpkg-cmake-config",\n "host": true\n}\n';
deprecated_output += "```\n";
2023-06-01 02:54:31 +08:00
core.error(deprecated_output);
2023-02-24 09:11:15 +08:00
2023-06-01 02:54:31 +08:00
let deprecated_functions = {
2023-02-24 09:11:15 +08:00
vcpkg_install_cmake : 'vcpkg_cmake_install (from port vcpkg-cmake)' ,
vcpkg_install_cmake : 'vcpkg_cmake_install (from port vcpkg-cmake)' ,
vcpkg_build_cmake : 'vcpkg_cmake_build (from port vcpkg-cmake)' ,
vcpkg_configure_cmake : 'vcpkg_cmake_configure (Please remove the option PREFER_NINJA) (from port vcpkg-cmake)' ,
vcpkg_fixup_cmake_targets : 'vcpkg_cmake_config_fixup (from port vcpkg-cmake-config)' ,
};
2023-06-01 02:54:31 +08:00
for (let line of deprecated_cmake) {
2023-02-24 09:11:15 +08:00
// line has the format : <path>:<line_number>:<matched_string
// For example: ports/rtlsdr/portfile.cmake:42 : vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
[ file, line_number, match] = line.split(':');
2023-06-01 02:54:31 +08:00
for (deprecated_cmake_function in deprecated_functions) {
if (match.indexOf(deprecated_cmake_function) !== -1) {
core.warning(`The function ${deprecated_cmake_function} is deprecated. Please use ${deprecated_functions[deprecated_cmake_function]}`, {file, startLine: line_number});
2023-02-24 09:11:15 +08:00
break;
}
}
}
2022-01-21 06:04:48 +08:00
}
2023-02-23 05:08:44 +08:00
2022-04-28 03:58:45 +08:00
if (missing_license !== "" || deprecated_license !== "") {
2023-02-23 05:08:44 +08:00
var license_output = '';
license_output += 'You have modified or added at least one vcpkg.json where you should check the \"license\" field.\n'
2022-04-28 03:58:45 +08:00
if (missing_license !== "") {
2023-02-23 05:08:44 +08:00
license_output += 'If you feel able to do so, please consider adding a "license" field to the following files:\n'
license_output += missing_license
license_output += "\n\nValid values for the license field can be found at https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json#license\n\n"
2022-04-28 03:58:45 +08:00
}
if (deprecated_license !== "") {
2023-02-23 05:08:44 +08:00
license_output += 'If you feel able to do so, please consider replacing the deprecated license identifiers in the following files:\n'
license_output += deprecated_license
license_output += "\n\nDeprecated and non deprecated license identifiers can be found at https://spdx.org/licenses/#deprecated\n"
2022-04-28 03:58:45 +08:00
}
2021-07-27 05:26:28 +08:00
2023-02-23 05:08:44 +08:00
core.warning(license_output);
2021-07-27 05:26:28 +08:00
}
2023-02-23 05:08:44 +08:00
if (!approve) {
process.exitCode = 1;
}