-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (59 loc) · 2.19 KB
/
pull-request-28.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: Diff code list 28
on:
pull_request:
paths:
- 'CLR/Rec28/current/code-list.csv'
jobs:
diff:
runs-on: ubuntu-latest
steps:
- name: Check out this repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Checkout PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr checkout ${{ github.event.pull_request.number }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install Python dependencies
run: |-
pip install csv-diff
- name: Fetch latest data
run: |-
cp "CLR/Rec28/current/code-list.csv" code-list-new.csv
curl -o code-list-old.csv "https://raw.githubusercontent.com/uncefact/vocab-codes/main/CLR/Rec28/current/code-list.csv"
# Remove heading line and use it to start a new file
## todo: check if need sorting, simple sort isn't working because CI is the first column
#head -n 1 code-list-new.csv > code-list-new-sorted.csv
## Sort all but the first line and append to that file
#tail -n +2 "code-list-new.csv" | sort >> code-list-new-sorted.csv
# Generate commit message using csv-diff
csv-diff code-list-old.csv code-list-new.csv --key=Code --singular=record --plural=records > message.txt
cat message.txt
# todo: add check for message.txt content
#mv code-list-new.csv "CRL/Rec28/current/code-list.csv"
- name: Set variables
if: ${{ hashFiles('message.txt') != '' }}
run: |
MSG=$(cat message.txt)
echo "MESSAGE=$MSG" >> $GITHUB_ENV
- name: Comment a pull_request
if: ${{ hashFiles('message.txt') != '' }}
uses: mb2dev/[email protected]
with:
message: |
message:
${{ env.MESSAGE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push if it changed
run: |-
git config user.name "Automated"
git config user.email "[email protected]"
git add "CLR/Rec28/current/code-list.csv"
timestamp=$(date -u)
git commit -F message.txt || exit 0
git push