-
Notifications
You must be signed in to change notification settings - Fork 1
140 lines (119 loc) · 4.52 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Generate Utils From JSON
on:
push:
branches: [ "master" ]
paths:
- "SC24/**.json"
workflow_dispatch:
env:
JSON_FILES_DIR: ./SC24
PYTHON_VERSION: '3.10'
ARTIFACT_DIR: tmp/artifacts
jobs:
list-json-files:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Select JSON files
id: set-matrix
run: echo "matrix=$(find $JSON_FILES_DIR | egrep '\.json$' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
sync-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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:
max-parallel: 1
matrix:
json-file: ${{ fromJson(needs.list-json-files.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Get filenames
run: |
mkdir -p ${{ env.ARTIFACT_DIR }}
mkdir -p ${{ env.ARTIFACT_DIR }}/c_source
path=$(echo ${{ matrix.json-file }} | cut -d. -f2)
file=$(basename $path)
lcPath=${path,,}
lcFile=$(basename $lcPath)
dir=$(dirname $path)
echo "OUT_DIR=$(echo $dir | cut -c 2-)" >> $GITHUB_ENV
echo "FILENAME=$(echo $file)" >> $GITHUB_ENV
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@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip packages
id: pip-cache
uses: actions/cache@v4
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: Print dir
run: ls -R
- 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.OUT_DIR }}/artifacts/${{ env.FILENAME }}
SKIP_EMPTY_COMMITS: true
MESSAGE: generated from ${{ matrix.json-file }} at {sha}
- name: Push to build branch
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: acmelib
FOLDER: ${{ env.ARTIFACT_DIR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_DIR: ${{ env.OUT_DIR }}/artifacts/${{ env.FILENAME }}
SKIP_EMPTY_COMMITS: true
MESSAGE: generated from ${{ matrix.json-file }} at {sha}