vcpkg/.github/workflows/untrustedPR.yml

136 lines
9.0 KiB
YAML
Raw Normal View History

name: Check For Common Mistakes
on:
pull_request:
jobs:
Check:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# fetch-depth 50 tries to ensure we capture the whole history of the branch
fetch-depth: 50
- name: Bootstrap
run: ./bootstrap-vcpkg.sh
- name: Formatting
run: |
git config user.email github-actions
git config user.name github-actions@github.com
git --version
unset VCPKG_ROOT
git diff --name-status --merge-base HEAD^ HEAD --diff-filter=MAR -- '*portfile.cmake' | sed 's/[MAR]\t*//' | while read filename; do grep -q -E '(vcpkg_apply_patches|vcpkg_copy_tool_dependencies|vcpkg_build_msbuild|vcpkg_extract_source_archive_ex|vcpkg_install_cmake|vcpkg_build_cmake|vcpkg_configure_cmake|vcpkg_fixup_cmake_targets)' "$filename" && echo "$filename" || true; done > .github-pr.deprecated-cmake
git diff --name-status --merge-base HEAD^ HEAD --diff-filter=MAR -- '*vcpkg.json' | sed 's/[MAR]\t*//' > .github-pr.changed-manifest-files
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
./vcpkg format-manifest --all --convert-control
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
./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
git diff > .github-pr.x-add-version.diff
git reset HEAD~ --mixed
- name: Generate Reply
uses: actions/github-script@v6
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()
const version_string_out = (await fs.readFile('.github-pr.version-string.out', 'utf8')).trim()
const format = (await fs.readFile('.github-pr.format-manifest', 'utf8')).trim()
const cmake = (await fs.readFile('.github-pr.deprecated-cmake', 'utf8')).trim()
const missing_license = (await fs.readFile('.github-pr.missing-license', 'utf8')).trim()
const deprecated_license = (await fs.readFile('.github-pr.deprecated-license', 'utf8')).trim()
let approve = true;
if (format !== "") {
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);
approve = false;
}
if (add_version_out !== "") {
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);
approve = false;
}
if (version_string_out !== "") {
core.warning(version_string_out);
}
if (add_version !== "") {
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);
approve = false;
}
if (cmake !== "") {
var deprecated_output = '';
deprecated_output += "You have modified or added at least one portfile where deprecated functions are used.\n"
deprecated_output += "If you feel able to do so, please consider migrating them to the new functions:\n";
deprecated_output += " vcpkg_install_cmake -> vcpkg_cmake_install (from port vcpkg-cmake)\n";
deprecated_output += " vcpkg_build_cmake -> vcpkg_cmake_build (from port vcpkg-cmake)\n";
deprecated_output += " vcpkg_configure_cmake -> vcpkg_cmake_configure (Please remove the option PREFER_NINJA) (from port vcpkg-cmake)\n";
deprecated_output += " vcpkg_fixup_cmake_targets -> vcpkg_cmake_config_fixup (from port vcpkg-cmake-config)\n";
deprecated_output += " vcpkg_extract_source_archive_ex -> vcpkg_extract_source_archive https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_extract_source_archive\n";
deprecated_output += " vcpkg_build_msbuild -> vcpkg_install_msbuild https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_install_msbuild\n";
deprecated_output += " vcpkg_copy_tool_dependencies -> vcpkg_copy_tools https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_copy_tools\n";
deprecated_output += " vcpkg_apply_patches should be replaced by the PATCHES arguments to the \"extract\" helpers (for example, vcpkg_from_github() (https://learn.microsoft.com/en-us/vcpkg/maintainers/functions/vcpkg_from_github))\n";
deprecated_output += "\n";
deprecated_output += "In the ports that use the new function, you have to add the corresponding dependencies:\n";
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";
deprecated_output += `The following files are affected:\n${cmake}`;
core.warning(deprecated_output);
}
if (missing_license !== "" || deprecated_license !== "") {
var license_output = '';
license_output += 'You have modified or added at least one vcpkg.json where you should check the \"license\" field.\n'
if (missing_license !== "") {
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"
}
if (deprecated_license !== "") {
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"
The old link is now 404
}
core.warning(license_output);
}
if (!approve) {
process.exitCode = 1;
}