-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (101 loc) · 3.85 KB
/
gen_from_json.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Generate Utils From JSON
on:
push:
branches: [ "master" ]
workflow_dispatch:
env:
JSON_FILES_DIR: SC22EVO
PYTHON_VERSION: '3.10'
ARTIFACT_DIR: tmp/SC22EVO/artifacts
jobs:
list-json-files:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: Select JSON files
id: set-matrix
run: echo "matrix=$(ls $JSON_FILES_DIR/*.json | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
sync-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Merge master into build
uses: devmasx/merge-branch@master
with:
type: now
from_branch: master
target_branch: build
github_token: ${{ secrets.GITHUB_TOKEN }}
message: Merge master into build
generate:
needs: [list-json-files, sync-branch]
runs-on: ubuntu-latest
strategy:
matrix:
json-file: ${{ fromJson(needs.list-json-files.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Get filenames
run: |
mkdir -p ${{ env.ARTIFACT_DIR }}
mkdir -p ${{ env.ARTIFACT_DIR }}/c_source
path=$(echo ${{ matrix.json-file }} | cut -d. -f1)
file=$(basename $path)
lcPath=${path,,}
lcFile=$(basename $lcPath)
echo "DBC_FILE=$(echo ${{ env.ARTIFACT_DIR }})/$(echo $file).dbc" >> $GITHUB_ENV
echo "C_FILE=$(echo $lcFile).c" >> $GITHUB_ENV
echo "H_FILE=$(echo $lcFile).h" >> $GITHUB_ENV
echo "DBF_FILE=$(echo ${{ env.ARTIFACT_DIR }})/$(echo $file).dbf" >> $GITHUB_ENV
echo "XLSX_FILE=$(echo ${{ env.ARTIFACT_DIR }})/$(echo $file).xlsx" >> $GITHUB_ENV
echo "CSV_FILE=$(echo ${{ env.ARTIFACT_DIR }})/$(echo $file).csv" >> $GITHUB_ENV
- name: Download latest jsodbc release
uses: robinraju/[email protected]
with:
repository: "squadracorsepolito/jsondbc"
latest: true
fileName: "jsondbc_Linux_x86_64.tar.gz"
extract: true
out-file-path: "jsondbc"
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip packages
id: pip-cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-python${{ env.PYTHON_VERSION }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install cantools
run: python3 -m pip install cantools
- name: Install canmatrix
run: python3 -m pip install canmatrix[xlsx]
- name: Convert JSON file to dbc
run: ./jsondbc/jsondbc convert --in ${{ matrix.json-file }} --out ${{ env.DBC_FILE }}
- name: Generate .c .h
run: |
python3 -m cantools generate_c_source ${{ env.DBC_FILE }}
mv ${{ env.C_FILE }} ${{ env.ARTIFACT_DIR }}/c_source
mv ${{ env.H_FILE }} ${{ env.ARTIFACT_DIR }}/c_source
- name: Convert dbc to dbf
run: canconvert ${{ env.DBC_FILE }} ${{ env.DBF_FILE }}
- name: Convert dbc to xlsx
run: canconvert ${{ env.DBC_FILE }} ${{ env.XLSX_FILE }}
- name: Convert dbc to csv
run: canconvert ${{ env.DBC_FILE }} ${{ env.CSV_FILE }}
- name: Push to build branch
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: build
FOLDER: ${{ env.ARTIFACT_DIR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_DIR: ${{ env.JSON_FILES_DIR }}/artifacts
SKIP_EMPTY_COMMITS: true
MESSAGE: generated from ${{ matrix.json-file }} at {sha}