From 584f6036ae4b4286ce9f28b6042468995a3d7247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sun, 12 Sep 2021 19:30:56 +0200 Subject: [PATCH] Fix issues with templates & simplify Windows CI --- .github/workflows/main.yml | 33 +------- .github/workflows/pull-request.yml | 33 +------- README.md | 14 ++-- Sources/Configuration/Templates/Blank.yml | 83 +++++++++++++------ .../Configuration/Templates/OpenSource.yml | 22 ++--- 5 files changed, 86 insertions(+), 99 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a691807..0b22d6e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,40 +23,15 @@ jobs: - name: Run tests run: swift test -v --enable-code-coverage - # originally from: https://github.com/compnerd/swift-build/blob/master/.github/workflows/swift-argument-parser.yml test-windows: runs-on: windows-latest timeout-minutes: 15 - strategy: - matrix: - include: - - tag: 5.4.3-RELEASE - branch: swift-5.4.3-release - steps: - uses: actions/checkout@v2 - - name: Install Swift ${{ matrix.tag }} - run: | - function Update-EnvironmentVariables { - foreach ($level in "Machine", "User") { - [Environment]::GetEnvironmentVariables($level).GetEnumerator() | % { - # For Path variables, append the new values, if they're not already in there - if ($_.Name -Match 'Path$') { - $_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -Split ';' | Select -Unique) -Join ';' - } - $_ - } | Set-Content -Path { "Env:$($_.Name)" } - } - } - - Install-Binary -Url "https://swift.org/builds/${{ matrix.branch }}/windows10/swift-${{ matrix.tag }}/swift-${{ matrix.tag }}-windows10.exe" -Name "installer.exe" -ArgumentList ("-q") - Update-EnvironmentVariables - # Reset Path and environment - echo "$env:Path" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 - Get-ChildItem Env: | % { echo "$($_.Name)=$($_.Value)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append } - - - name: Run tests - run: swift test -v + - name: Install Swift & Run tests + uses: MaxDesiatov/swift-windows-action@v1 + with: + shell-action: swift test -v diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f0bd240..c8a4491 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -44,40 +44,15 @@ jobs: - name: Run tests run: swift test -v --enable-code-coverage - # originally from: https://github.com/compnerd/swift-build/blob/master/.github/workflows/swift-argument-parser.yml test-windows: runs-on: windows-latest timeout-minutes: 15 - strategy: - matrix: - include: - - tag: 5.5-DEVELOPMENT-SNAPSHOT-2021-08-30-a - branch: swift-5.5-branch - steps: - uses: actions/checkout@v2 - - name: Install Swift ${{ matrix.tag }} - run: | - function Update-EnvironmentVariables { - foreach ($level in "Machine", "User") { - [Environment]::GetEnvironmentVariables($level).GetEnumerator() | % { - # For Path variables, append the new values, if they're not already in there - if ($_.Name -Match 'Path$') { - $_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -Split ';' | Select -Unique) -Join ';' - } - $_ - } | Set-Content -Path { "Env:$($_.Name)" } - } - } - - Install-Binary -Url "https://swift.org/builds/${{ matrix.branch }}/windows10/swift-${{ matrix.tag }}/swift-${{ matrix.tag }}-windows10.exe" -Name "installer.exe" -ArgumentList ("-q") - Update-EnvironmentVariables - # Reset Path and environment - echo "$env:Path" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 - Get-ChildItem Env: | % { echo "$($_.Name)=$($_.Value)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append } - - - name: Run tests - run: swift test -v + - name: Install Swift & Run tests + uses: MaxDesiatov/swift-windows-action@v1 + with: + shell-action: swift test -v diff --git a/README.md b/README.md index e234a31..0b5b714 100644 --- a/README.md +++ b/README.md @@ -479,7 +479,7 @@ Here are some **advanced Regex features** you might want to use or learn more ab For example, consider a regex violating if there's an empty line after an opening curly brace like so: `{\n\s*\n\s*\S`. This would match the lines of `func do() {\n\n return 5}`, but what you actually want is it to start matching on the empty newline like so: `(?<={\n)\s*\n\s*\S`. See also [#3](https://github.com/Flinesoft/AnyLint/issues/3) - + ## YAML Cheat Sheet Please be aware that in YAML indentation (whitespaces) and newlines are actually important. @@ -492,6 +492,8 @@ string2: 'This is with single quotes.' string3: "This is with double quotes." ``` +Note that only in double-quoted strings you can escape characters, e.g. `'Line1\nLine2'` will keep the `\n` as two characters in the result, whereas `"Line1\nLine2"` will escape `\n` to a newline. We recommend to use single quotes for `regex` arguments (the escaping will happen in the Regex parser) and double-quotes for any examples where you need escaping to be evaluated. + **Multi-line strings** can be written by specifying `|` and then a newline: ```yaml multiline1: | @@ -504,13 +506,13 @@ An additional `+` or `-` specified what to do with trailing newlines: ```yaml multiline2: |+ This will make sure both trailing newlines are kept (ends with ".\n\n"). - - + + multiline3: |- - This will ignore any trailing newlines and + This will ignore any trailing newlines and will end with the last non-newline character (the following dot in this case -->). - - + + ``` **Arrays** can be written in two ways: diff --git a/Sources/Configuration/Templates/Blank.yml b/Sources/Configuration/Templates/Blank.yml index 8dd7b5d..9d9bddf 100644 --- a/Sources/Configuration/Templates/Blank.yml +++ b/Sources/Configuration/Templates/Blank.yml @@ -1,29 +1,64 @@ FileContents: [] -# - id: Readme -# hint: 'Each project should have a README.md file, explaining how to use or contribute to the project.' -# regex: '^README\.md$' -# violateIfNoMatchesFound: true -# matchingExamples: ['README.md'] -# nonMatchingExamples: ['README.markdown', 'Readme.md', 'ReadMe.md'] +# TODO: replace below sample checks with your custom checks and remove empty array specifier `[]` from above + # - id: ReadmeTopLevelTitle + # hint: 'The README.md file should only contain a single top level title.' + # regex: '(^|\n)#[^#](.*\n)*\n#[^#]' + # includeFilters: ['^README\.md$'] + # matchingExamples: + # - | + # # Title + # ## Subtitle + # Lorem ipsum + # + # # Other Title + # ## Other Subtitle + # nonMatchingExamples: + # - | + # # Title + # ## Subtitle + # Lorem ipsum #1 and # 2. + # + # ## Other Subtitle + # ### Other Subsubtitle + # + # - id: ReadmeTypoLicense + # hint: 'ReadmeTypoLicense: Misspelled word `license`.' + # regex: '([\s#]L|l)isence([\s\.,:;])' + # matchingExamples: [' lisence:', "## Lisence\n"] + # nonMatchingExamples: [' license:', "## License\n"] + # includeFilters: ['^README\.md$'] + # autoCorrectReplacement: '$1icense$2' + # autoCorrectExamples: + # - { before: ' lisence:', after: ' license:' } + # - { before: "## Lisence\n", after: "## License\n" } FilePaths: [] -# - id: 'ReadmePath' -# hint: 'The README file should be named exactly `README.md`.' -# regex: '^(.*/)?([Rr][Ee][Aa][Dd][Mm][Ee]\.markdown|readme\.md|Readme\.md|ReadMe\.md)$' -# matchingExamples: ['README.markdown', 'readme.md', 'ReadMe.md'] -# nonMatchingExamples: ['README.md', 'CHANGELOG.md', 'CONTRIBUTING.md', 'api/help.md'] -# autoCorrectReplacement: '$1README.md' -# autoCorrectExamples: -# - { before: 'api/readme.md', after: 'api/README.md' } -# - { before: 'ReadMe.md', after: 'README.md' } -# - { before: 'README.markdown', after: 'README.md' } +# TODO: replace below sample checks with your custom checks and remove empty array specifier `[]` from above + # - id: Readme + # hint: 'Each project should have a README.md file, explaining how to use or contribute to the project.' + # regex: '^README\.md$' + # violateIfNoMatchesFound: true + # matchingExamples: ['README.md'] + # nonMatchingExamples: ['README.markdown', 'Readme.md', 'ReadMe.md'] + # + # - id: ReadmePath + # hint: 'The README file should be named exactly `README.md`.' + # regex: '^(.*/)?([Rr][Ee][Aa][Dd][Mm][Ee]\.markdown|readme\.md|Readme\.md|ReadMe\.md)$' + # matchingExamples: ['README.markdown', 'readme.md', 'ReadMe.md'] + # nonMatchingExamples: ['README.md', 'CHANGELOG.md', 'CONTRIBUTING.md', 'api/help.md'] + # autoCorrectReplacement: '$1README.md' + # autoCorrectExamples: + # - { before: 'api/readme.md', after: 'api/README.md' } + # - { before: 'ReadMe.md', after: 'README.md' } + # - { before: 'README.markdown', after: 'README.md' } CustomScripts: [] -# - id: LintConfig -# hint: 'Lint the AnyLint config file to conform to YAML best practices.' -# command: |- -# if which yamllint > /dev/null; then -# yamllint anylint.yml -# else -# echo '{ "warning": { "YamlLint: Not installed, see instructions at https://yamllint.readthedocs.io/en/stable/quickstart.html#installing-yamllint": [{}] } }' -# fi +# TODO: replace below sample check with your custom checks and remove empty array specifier `[]` from above + # - id: LintConfig + # hint: 'Lint the AnyLint config file to conform to YAML best practices.' + # command: |- + # if which yamllint > /dev/null; then + # yamllint anylint.yml + # else + # echo '{ "warning": { "YamlLint: Not installed, see instructions at https://yamllint.readthedocs.io/en/stable/quickstart.html#installing-yamllint": [{}] } }' + # fi diff --git a/Sources/Configuration/Templates/OpenSource.yml b/Sources/Configuration/Templates/OpenSource.yml index 78cf79f..8f7f88d 100644 --- a/Sources/Configuration/Templates/OpenSource.yml +++ b/Sources/Configuration/Templates/OpenSource.yml @@ -1,15 +1,8 @@ FileContents: - - id: Readme - hint: 'Each project should have a README.md file, explaining how to use or contribute to the project.' - regex: '^README\.md$' - violateIfNoMatchesFound: true - matchingExamples: ['README.md'] - nonMatchingExamples: ['README.markdown', 'Readme.md', 'ReadMe.md'] - - id: ReadmeTopLevelTitle hint: 'The README.md file should only contain a single top level title.' regex: '(^|\n)#[^#](.*\n)*\n#[^#]' - includeFilter: ['^README\.md$'] + includeFilters: ['^README\.md$'] matchingExamples: - | # Title @@ -30,15 +23,22 @@ FileContents: - id: ReadmeTypoLicense hint: 'ReadmeTypoLicense: Misspelled word `license`.' regex: '([\s#]L|l)isence([\s\.,:;])' - matchingExamples: [' lisence:', '## Lisence\n'] - nonMatchingExamples: [' license:', '## License\n'] + matchingExamples: [' lisence:', "## Lisence\n"] + nonMatchingExamples: [' license:', "## License\n"] includeFilters: ['^README\.md$'] autoCorrectReplacement: '$1icense$2' autoCorrectExamples: - { before: ' lisence:', after: ' license:' } - - { before: '## Lisence\n', after: '## License\n' } + - { before: "## Lisence\n", after: "## License\n" } FilePaths: + - id: Readme + hint: 'Each project should have a README.md file, explaining how to use or contribute to the project.' + regex: '^README\.md$' + violateIfNoMatchesFound: true + matchingExamples: ['README.md'] + nonMatchingExamples: ['README.markdown', 'Readme.md', 'ReadMe.md'] + - id: ReadmePath hint: 'The README file should be named exactly `README.md`.' regex: '^(.*/)?([Rr][Ee][Aa][Dd][Mm][Ee]\.markdown|readme\.md|Readme\.md|ReadMe\.md)$'