Skip to content

Commit

Permalink
ci: support multiple author in sync GH
Browse files Browse the repository at this point in the history
The sync GH action only works for a single author, producing unexpected
results when using list of authors.

This change also prevent problems with new files that are not rules
(`.yml`). (such as `.github/scripts/changelog_author.py`)

Closes mandiant/capa#555
  • Loading branch information
Ana06 committed May 11, 2021
1 parent 78f1619 commit e1643cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/scripts/changelog_author.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import yaml
import sys

rule_file = sys.argv[1]
with open(rule_file, 'r') as stream:
rule_yaml = yaml.safe_load(stream)

author_value = rule_yaml["rule"]["meta"]["author"]
if isinstance(author_value, list): # list of authors
print(" ".join(author_value))
else: # one author
print(author_value)
10 changes: 9 additions & 1 deletion .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ jobs:
- name: Get modified files
id: files
uses: jitterbit/get-changed-files@v1
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install Python dependencies
run:
pip install pyyaml
- 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' )
[[ $added_file != *.yml ]] && continue # Skip files that are not rules
author=$(python rules/.github/scripts/changelog_author.py rules/$added_file)
rule=$(echo $added_file | sed 's/\//\\\//g' | sed 's/\.yml//')
sed -i "0,/- *$/s//- $rule $author\n-/" CHANGELOG.md
done
Expand Down

1 comment on commit e1643cc

@thisguy726
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.