Skip to content

JSON-LD vocabulary generation from CSV files #46

JSON-LD vocabulary generation from CSV files

JSON-LD vocabulary generation from CSV files #46

Workflow file for this run

name: JSON-LD vocabulary generation from CSV files
on:
pull_request:
paths:
- 'scripts/src/**'
- 'locodes/**'
# Manually run the generation or split
workflow_dispatch:
inputs:
mode:
type: choice
description: 'The mode of the transformation to run'
required: true
options:
- split
- json-ld
directory:
type: choice
description: 'The location of input csv files to be split'
required: false
options:
- loc221csv
- loc222csv
jobs:
json-ld:
if: contains(github.event.inputs.mode, 'json-ld')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
- name: package
working-directory: scripts/
run: |
mvn -B package --file pom.xml
- name: copy locodes
run: |
mkdir scripts/target/csv
cp locodes/*.csv scripts/target/csv
- name: generate
working-directory: scripts/target/
run: |
java -jar "$(find -name *.jar)" -t json-ld -d classes/${{github.event.inputs.directory}}
jq --sort-keys . unlocode-countries.jsonld > unlocode-countries-sorted.jsonld
mv unlocode-countries-sorted.jsonld unlocode-countries.jsonld
jq --sort-keys . unlocode-functions.jsonld > unlocode-functions-sorted.jsonld
mv unlocode-functions-sorted.jsonld unlocode-functions.jsonld
jq --sort-keys . unlocode-subdivisions.jsonld > unlocode-subdivisions-sorted.jsonld
mv unlocode-subdivisions-sorted.jsonld unlocode-subdivisions.jsonld
jq --sort-keys . unlocode-vocab.jsonld > unlocode-vocab-sorted.jsonld
mv unlocode-vocab-sorted.jsonld unlocode-vocab.jsonld
jq -c --sort-keys . unlocode.jsonld > unlocode-sorted.jsonld
mv unlocode-sorted.jsonld unlocode.jsonld
mv *.jsonld ../../vocab/
- name: runn diff
working-directory: vocab/
run: |
curl -o unlocode-main.jsonld https://raw.githubusercontent.com/uncefact/vocabulary-outputs/main/unlocode.jsonld && echo "Downloaded"
diff <(jq --sort-keys . unlocode-main.jsonld) <(jq --sort-keys . unlocode.jsonld) > unlocode-diff.txt && echo "Diff created"
curl -o unlocode-subdivisions-main.jsonld https://raw.githubusercontent.com/uncefact/vocabulary-outputs/main/unlocode-subdivisions.jsonld && echo "Downloaded"
diff <(jq --sort-keys . unlocode-subdivisions-main.jsonld) <(jq --sort-keys . unlocode-subdivisions.jsonld) > unlocode-subdivisions-diff.txt && echo "Diff created"
rm unlocode-main.jsonld && echo "File removed"
rm unlocode-subdivisions-main.jsonld && echo "File removed"
- name: commit json-ld
working-directory: vocab/
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "update UN/LOCODE vocabulary"
git push
split:
if: contains(github.event.inputs.mode, 'split')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
- name: package
working-directory: scripts/
run: |
mvn -B package --file pom.xml
- name: upload transformer
uses: actions/upload-artifact@v2
with:
name: unlocode-transformer
path: scripts/target/unlocode-transformer-*.jar
- name: split locodes
working-directory: scripts/target
run: |
java -jar "$(find -name *.jar)" -t split -d classes/${{github.event.inputs.directory}}
mv *.csv ../../locodes/
- name: commit locodes
working-directory: locodes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "update UN/LOCODE files"
git push