This command line tool validates your XML files for proper formatting. If they are not formatted correctly, it prints the difference and returns with an error. You can use it two ways: 1) to fail your build if any X-like files (XML, XSD, XSL, XHTML) are not formatted correctly, and 2) to format them correctly.
Read this blog post of mine first: XCOP—XML Style Checker.
Install it first (read below if you can't install it):
$ gem install xcop
Run it locally and read its output:
$ xcop --help
To validate formatting of your XML files just pass their names as arguments:
$ xcop file1.xml file2.xml
If your files are not formatted correctly and xcop
complains, you
can ask it to "beautify" them, using --fix
option:
$ xcop --fix broken-file.xml
To fix all files in the directory you can do (won't work if your file names contain spaces):
$ xcop --fix $(find . -name '*.xml')
This is what you need there:
require 'xcop/rake_task'
desc 'Run XCop on all XML/XSL files in all directories'
Xcop::RakeTask.new(:xcop) do |task|
task.license = 'LICENSE.txt' # no license by default
task.quiet = true # FALSE by default
task.includes = ['**/*.xml', '**/*.xsl'] # xml|xsd|xhtml|xsl|html by default
task.excludes = ['target/**/*'] # empty by default
end
Create new workflow file in repository under .github/workflows/xcop.yml
:
---
name: XCOP
"on":
# run on push to master events
push:
branches:
- master
# run on pull requests to master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: g4s8/xcop-action@master
To customize license location or files pattern use action inputs license
and files
:
- uses: g4s8/xcop-action@master
with:
license: MY_LICENSE.txt
files: "src/*.xml"
You can integrate it with the help of maven-antrun-plugin:
<project>
[...]
<build>
[...]
<plugins>
[...]
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>verify</phase>
<configuration>
<target>
<apply executable="xcop" failonerror="true">
<arg value="--license"/>
<arg value="LICENSE.txt"/>
<fileset dir=".">
<include name="**/*.xml"/>
<include name="**/*.xsd"/>
<exclude name="target/**/*"/>
<exclude name=".idea/**/*"/>
</fileset>
</apply>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Something like this should work:
<project>
[...]
<target name="xcop">
<apply executable="xcop" failonerror="true">
<arg value="--license"/>
<arg value="LICENSE.txt"/>
<fileset dir=".">
<include name="**/*.xml"/>
<include name="**/*.xsd"/>
<exclude name="target/**/*"/>
<exclude name=".idea/**/*"/>
</fileset>
</apply>
</target>
</project>
Read these guidelines. Make sure you build is green before you contribute your pull request. You will need to have Ruby 2.3+ and Bundler installed. Then:
$ bundle update
$ bundle exec rake
If it's clean and you don't see any error messages, submit your pull request.