From 9ceef7522504491bce0c78eefc30a9d0a5ee4123 Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Fri, 7 May 2021 09:37:51 +0200 Subject: [PATCH] ci: Update CHANGELOG automatically Update new rules in capa repository's CHANGELOG with a GitHub Action automatically with every push (for example merge of PR). --- .github/workflows/sync.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 87e5b1178..ff472eecc 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -42,10 +42,27 @@ jobs: # one which triggered the action) ref: master path: rules + fetch-depth: 100 # needed so that `git diff` finds `github.event.before` - name: Update rules number badge in README run: | num_rules=$(find rules -type f -name '*.yml' -not -path 'rules/.github/*' | wc -l) sed -i "s/rules-[0-9]*-blue\.svg/rules-$num_rules-blue.svg/" README.md + - name: Update number of new rules in CHANGELOG + run: | + new_rules=$(git -C rules diff -M --summary ${{ github.event.before }} | grep create | wc -l) + old_rules=$(grep -m 1 "### New Rules.*" CHANGELOG.md | sed -r 's/.*\((.*)\)/\1/') + rules=$(($old_rules + $new_rules)) + sed -ir "0,/New Rules.*/s//New Rules \($rules\)/" CHANGELOG.md + - name: Get modified files + id: files + uses: jitterbit/get-changed-files@v1 + - name: Add new rules to CHANGELOG + run: | + for added_file in ${{ steps.files.outputs.added }}; do + author=$(grep 'author:' rules/$added_file | sed 's/^.*: //' | sed 's/"//g' ) + rule=$(echo $added_file | sed 's/\//\\\//g' | sed 's/\.yml//') + sed -i "0,/- *$/s//- $rule $author\n-/" CHANGELOG.md + done - name: Commit changes run: | git config user.email 'capa-dev@fireeye.com'