Update from upstream #156
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update from upstream | |
on: | |
schedule: [cron: '12 4 * * *'] | |
workflow_dispatch: | |
jobs: | |
Fetch-Files: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install required packages | |
run: sudo apt install libxml2-utils pandoc | |
- uses: actions/checkout@v3 | |
- name: Prepare Git environment | |
run: | | |
git config --global user.name "Benjamin Somers" | |
git config --global user.email benjamin.somers@imt-atlantique.fr | |
- name: Fetch last LICENSE | |
run: curl https://capec.mitre.org/about/termsofuse.html | xmllint --html -xpath "//*[preceding-sibling::comment()[1][contains(., 'begin Main Content')]][following-sibling::comment()[1][contains(., 'end Main Content')]]" - | pandoc --from=html --to=gfm-raw_html > LICENSE.md | |
- name: Commit new LICENSE | |
run: | | |
git add LICENSE.md | |
if git commit -m "Update LICENSE" | |
then | |
git push origin latest | |
else | |
echo "Nothing to do" | |
fi | |
- name: Fetch last CAPEC files | |
run: | | |
curl -o files.zip https://capec.mitre.org/data/archive/capec_latest.zip | |
unzip -d tmp files.zip | |
for file in tmp/*.xml | |
do | |
mv "$file" data.xml | |
done | |
for file in tmp/*.xsd | |
do | |
mv "$file" schema.xsd | |
done | |
rm files.zip | |
rmdir tmp | |
- name: Commit new files | |
run: | | |
DATA_VERSION=$(xmllint -xpath "string(/*/@Version)" data.xml) | |
SCHEMA_VERSION=$(xmllint -xpath "string(/*/@version)" schema.xsd) | |
VERSION="Version $DATA_VERSION (schema $SCHEMA_VERSION)" | |
git add data.xml schema.xsd | |
if git commit -m "Automatic update: $VERSION" | |
then | |
TAG="$DATA_VERSION+$SCHEMA_VERSION" | |
git tag -a "$TAG" -m "$VERSION" | |
git push --atomic origin latest "$TAG" | |
else | |
echo "Nothing to do" | |
fi |