Skip to content

Commit 6da0147

Browse files
Add update-spec.yml workflow
Signed-off-by: Lisanna Dettwyler <[email protected]>
1 parent 494a052 commit 6da0147

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

.github/workflows/update-spec.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
on:
2+
pull_request:
3+
branches: [master]
4+
paths:
5+
- .github/workflows/update-spec.yml
6+
workflow_dispatch:
7+
inputs:
8+
repository:
9+
description: Spec repository from which to generate code
10+
type: string
11+
default: oneapi-src/level-zero-spec
12+
ref:
13+
description: Ref to checkout from the spec repository
14+
type: string
15+
default: master
16+
version:
17+
description: Version of the spec to generate code for
18+
type: string
19+
branch:
20+
description: Branch to (force) push generated code to
21+
type: string
22+
default: spec-develop
23+
24+
concurrency: ${{ github.event_name == 'pull_request' && github.run_id || inputs.branch }}
25+
26+
jobs:
27+
generate-code:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: '3.x'
33+
- name: Install dependencies
34+
run: pip install Mako==1.1.0 PyYAML==5.2
35+
- uses: actions/checkout@v3
36+
with:
37+
clean: true
38+
fetch-depth: 0
39+
fetch-tags: true
40+
token: ${{ secrets.TOKEN }}
41+
- name: Checkout develop branch or create local version
42+
if: ${{ github.event_name == 'workflow_dispatch' }}
43+
run: git checkout ${{ inputs.branch }} || git checkout -b ${{ inputs.branch }}
44+
- name: Reset develop branch to master
45+
if: ${{ github.event_name == 'workflow_dispatch' }}
46+
run: git reset --hard origin/master
47+
- name: Checkout spec repository
48+
uses: actions/checkout@v4
49+
with:
50+
repository: ${{ github.event_name == 'pull_request' && 'oneapi-src/level-zero-spec' || inputs.repository }}
51+
clean: true
52+
fetch-depth: 0
53+
path: spec
54+
ref: ${{ github.event_name == 'pull_request' && 'master' || inputs.ref }}
55+
- name: Apply latest spec commit to develop branch
56+
run: | #bash
57+
export LANG="C.UTF-8"
58+
cd spec/scripts
59+
echo "::group::Generate spec/scripts/input.json"
60+
python3 ./run.py --debug '--!html' '--!rst' '--!build' --ver ${{ github.event_name == 'pull_request' && '1.10' || inputs.version }}
61+
echo "::endgroup::"
62+
cd ..
63+
echo "::group::Copy generated header files"
64+
jq -r '.[] | select(.|test("^../include"))' scripts/generated.json | cut -c 4- | sort | xargs -I{} cp -v ./{} ../{}
65+
echo "::endgroup::"
66+
cd ..
67+
echo "::group::Generate source files"
68+
./scripts/json2src.py < spec/scripts/input.json --ver ${{ github.event_name == 'pull_request' && '1.10' || inputs.version }} .
69+
echo "::endgroup::"
70+
if (($(git diff | tee >(wc -l) >&2) == 0)); then
71+
echo "::warning::No changes were made to files"
72+
else
73+
git config user.email "[email protected]"
74+
git config user.name "sys-lzdev"
75+
spec_ver=$(sed -n 's/^.*version v.*-r\([0-9]*\.[0-9]*\.[0-9]*\)/\1/p' include/ze_api.h)
76+
git add -u
77+
git commit -m "Update to spec ${spec_ver}"
78+
fi
79+
- name: Push changes to develop branch
80+
if: ${{ github.event_name == 'workflow_dispatch' }}
81+
run: git push origin ${{ inputs.branch }} -f

0 commit comments

Comments
 (0)