-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (77 loc) · 2.98 KB
/
pull-request-24.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Diff code list 24
on:
pull_request:
paths:
- 'CLR/Rec24/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/Rec24/current/code-list.csv" code-list-new.csv
curl -o code-list-old.csv "https://raw.githubusercontent.com/uncefact/vocab-codes/main/CLR/Rec24/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
csv-diff code-list-old.csv code-list-new.csv --key=Code --singular=record --plural=records --json > message.json
cat message.txt
# todo: add check for message.txt content
# mv code-list-new-sorted.csv "CRL/Rec24/current/code-list.csv"
- run: jq -c '.added[] | select (.CI != "+")' < message.json >> errors.txt
- run: |
[ -s errors.txt ] || rm -f errors.txt
- name: Check errors.txt file
if: ${{ hashFiles('errors.txt') != '' }}
uses: mb2dev/[email protected]
with:
message: "A new code list value was added, but CI wasn't set to '+'."
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Exit if there are any errors
if: ${{ hashFiles('errors.txt') != '' }}
run: |
echo "Proposed changes validation failed. " >> $GITHUB_STEP_SUMMARY
exit 1
- name: Set variables
if: ${{ hashFiles('message.txt') != '' }}
run: |
{
echo 'MESSAGE<<EOF'
cat message.txt
echo EOF
} >> "$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/Rec24/current/code-list.csv"
timestamp=$(date -u)
git commit -F message.txt || exit 0
git push