Skip to content

feat: draft workflow to diff csv files requested to be updated #4

feat: draft workflow to diff csv files requested to be updated

feat: draft workflow to diff csv files requested to be updated #4

Workflow file for this run

name: Diff code list
on:
pull_request:
workflow_dispatch:
jobs:
scheduled:
runs-on: ubuntu-latest
steps:
- name: Check out this repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- 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 "Code List Recommendations/Rec 24 – Trade and Transport Status Codes/current/rec24_Rev6e_2017.csv" rec24-new.csv
curl -o rec24-old.csv "https://raw.githubusercontent.com/uncefact/vocab-codes/main/Code%20List%20Recommendations/Rec%2024%20%E2%80%93%20Trade%20and%20Transport%20Status%20Codes/current/rec24_Rev6e_2017.csv"
# Remove heading line and use it to start a new file
head -n 1 rec24-new.csv > rec24-new-sorted.csv
# Sort all but the first line and append to that file
tail -n +2 "rec24-new.csv" | sort >> rec24-new-sorted.csv
# Generate commit message using csv-diff
csv-diff rec24-old.csv rec24-new-sorted.csv --key=Code --singular=record --plural=records > message.txt
# todo: add check for message.txt content
mv rec24-new-sorted.csv "Code List Recommendations/Rec 24 – Trade and Transport Status Codes/current/rec24_Rev6e_2017.csv"
- name: Commit and push if it changed
run: |-
git config user.name "Automated"
git config user.email "[email protected]"
git add "Code List Recommendations/Rec 24 – Trade and Transport Status Codes/current/rec24_Rev6e_2017.csv"
timestamp=$(date -u)
git commit -F message.txt || exit 0
git push