Skip to content

Commit 13bd163

Browse files
committed
refactor: add new generator setup
1 parent 19bc972 commit 13bd163

File tree

6 files changed

+51
-125
lines changed

6 files changed

+51
-125
lines changed

.github/setvars/action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Set environment variables'
2+
description: 'Configures environment variables for a workflow'
3+
inputs:
4+
varFilePath:
5+
description: 'File path to variable file or directory. Defaults to ./.github/variables/* if none specified and runs against each file in that directory.'
6+
required: false
7+
default: ./.github/variables/*
8+
runs:
9+
using: "composite"
10+
steps:
11+
- run: |
12+
sed "" ${{ inputs.varFilePath }} >> $GITHUB_ENV
13+
shell: bash

.github/workflows/auto-update.yml

Lines changed: 17 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -8,129 +8,38 @@ on:
88
repository_dispatch:
99
types:
1010
- webhook
11-
env:
12-
library_last_version: 0.0.0
13-
template_last_version: 0.0.0
14-
template_current_version: 0.0.0
15-
document_last_version: 0.0.0
16-
document_current_version: 0.0.0
17-
major_template_last_version: 0
18-
minor_template_last_version: 0
19-
patch_template_last_version: 0
20-
major_template_current_version: 0
21-
minor_template_current_version: 0
22-
patch_template_current_version: 0
23-
major_version_change: false
24-
minor_version_change: false
25-
patch_version_change: false
26-
commit_message: ""
2711
jobs:
28-
get-template-version:
12+
auto-update-:
2913
runs-on: ubuntu-latest
3014
steps:
31-
- name: Get utility library
32-
uses: actions/checkout@v2
15+
- uses: actions/checkout@v3
16+
17+
- uses: actions/setup-node@v3
3318
with:
34-
repository: tyleradams/json-toolkit
35-
path: "./tooling"
36-
- name: Install and build utility tools
37-
run: cd ./tooling && make && sudo make install && cd ..
38-
- uses: actions/checkout@v2
39-
# Find all relevant semver versions needed to figure out how to update the client
40-
- name: Fetch the last AsyncAPI document version that generated the client
41-
run: echo "document_last_version=$(cat ./configs.json | jq -r '.document_last_version')" >> $GITHUB_ENV
42-
- name: Fetch the last template version that generated the client
43-
run: echo "template_last_version=$(cat ./configs.json | jq -r '.template_last_version')" >> $GITHUB_ENV
44-
- name: Fetch the last library version
45-
run: echo "library_last_version=$(cat ./AsyncapiNatsClient/AsyncapiNatsClient.csproj | xml-to-json | jq -r '.Project.PropertyGroup.Version')" >> $GITHUB_ENV
46-
- name: Fetch current template version
47-
run: echo "template_current_version=$(curl -sL https://api.github.com/repos/asyncapi/dotnet-nats-template/releases/latest | jq -r '.tag_name' | sed 's/v//')" >> $GITHUB_ENV
48-
- name: Get all the application AsyncAPI documents
49-
uses: actions/checkout@v2
50-
with:
51-
repository: GamingAPI/definitions
52-
path: "./definitions"
53-
- name: Get the version of the API
54-
run: echo "document_current_version=$(cat ./definitions/bundled/rust.asyncapi.json | jq -r '.info.version' | sed 's/v//')" >> $GITHUB_ENV
19+
node-version: '14'
5520

56-
# Figure out how the template version have changed
57-
- run: semver_template_last_version=( ${template_last_version//./ } ) && major_template_last_version=${semver_template_last_version[0]} && echo "major_template_last_version=$major_template_last_version" >> $GITHUB_ENV
58-
- run: semver_template_last_version=( ${template_last_version//./ } ) && minor_template_last_version=${semver_template_last_version[1]} && echo "minor_template_last_version=$minor_template_last_version" >> $GITHUB_ENV
59-
- run: semver_template_last_version=( ${template_last_version//./ } ) && patch_template_last_version=${semver_template_last_version[2]} && echo "patch_template_last_version=$patch_template_last_version" >> $GITHUB_ENV
60-
- run: semver_template_current_version=( ${template_current_version//./ } ) && major_template_current_version=${semver_template_current_version[0]} && echo "major_template_current_version=$major_template_current_version" >> $GITHUB_ENV
61-
- run: semver_template_current_version=( ${template_current_version//./ } ) && minor_template_current_version=${semver_template_current_version[1]} && echo "minor_template_current_version=$minor_template_current_version" >> $GITHUB_ENV
62-
- run: semver_template_current_version=( ${template_current_version//./ } ) && patch_template_current_version=${semver_template_current_version[2]} && echo "patch_template_current_version=$patch_template_current_version" >> $GITHUB_ENV
63-
- if: ${{ env.major_template_current_version > env.major_template_last_version }}
64-
run: echo "major_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}Template have changed to a new major version." >> $GITHUB_ENV
65-
- if: ${{ env.minor_template_current_version > env.minor_template_last_version }}
66-
run: echo "minor_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}Template have changed to a new minor version." >> $GITHUB_ENV
67-
- if: ${{ env.patch_template_current_version > env.patch_template_last_version }}
68-
run: echo "patch_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}Template have changed to a new patch version." >> $GITHUB_ENV
69-
70-
# Figure out how the AsyncAPI document have changed
71-
- run: semver_document_last_version=( ${document_last_version//./ } ) && major_document_last_version=${semver_document_last_version[0]} && echo "major_document_last_version=$major_document_last_version" >> $GITHUB_ENV
72-
- run: semver_document_last_version=( ${document_last_version//./ } ) && minor_document_last_version=${semver_document_last_version[1]} && echo "minor_document_last_version=$minor_document_last_version" >> $GITHUB_ENV
73-
- run: semver_document_last_version=( ${document_last_version//./ } ) && patch_document_last_version=${semver_document_last_version[2]} && echo "patch_document_last_version=$patch_document_last_version" >> $GITHUB_ENV
74-
- run: semver_document_current_version=( ${document_current_version//./ } ) && major_document_current_version=${semver_document_current_version[0]} && echo "major_document_current_version=$major_document_current_version" >> $GITHUB_ENV
75-
- run: semver_document_current_version=( ${document_current_version//./ } ) && minor_document_current_version=${semver_document_current_version[1]} && echo "minor_document_current_version=$minor_document_current_version" >> $GITHUB_ENV
76-
- run: semver_document_current_version=( ${document_current_version//./ } ) && patch_document_current_version=${semver_document_current_version[2]} && echo "patch_document_current_version=$patch_document_current_version" >> $GITHUB_ENV
77-
- if: ${{ env.major_document_current_version > env.major_document_last_version }}
78-
run: echo "major_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}AsyncAPI document have changed to a new major version. " >> $GITHUB_ENV
79-
- if: ${{ env.minor_document_current_version > env.minor_document_last_version && env.major_document_current_version < env.major_document_last_version }}
80-
run: echo "minor_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}AsyncAPI document have changed to a new minor version. " >> $GITHUB_ENV
81-
- if: ${{ env.patch_document_current_version > env.patch_document_last_version && env.minor_document_current_version < env.minor_document_last_version && env.major_document_current_version < env.major_document_last_version }}
82-
run: echo "patch_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}AsyncAPI document have changed to a new patch template version. " >> $GITHUB_ENV
21+
- name: Generate code
22+
run: chmod +x ./generate.sh && ./generate.sh
8323

84-
# Make changes to the code if needed
85-
- name: Remove previous files to ensure clean slate
86-
if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}}
87-
run: find . -not \( -name configs.json -or -name .gitignore -or -iwholename *.github* -or -iwholename *./definitions* -or -iwholename *.git* -or -name . \) -exec echo {} +
88-
- name: Generating code from the AsyncAPI document
89-
if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}}
90-
uses: docker://asyncapi/github-action-for-generator
24+
- name: Set Environment Variables from generator file
25+
uses: ./.github/actions/setvars
9126
with:
92-
template: '@asyncapi/dotnet-nats-template'
93-
filepath: ./definitions/bundled/rust.asyncapi.json
94-
output: ./
95-
parameters: "version=${{env.library_last_version}}"
96-
- name: Write new config file to ensure we keep the new state for next time
97-
if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}}
98-
run: |
99-
contents="$(jq ".template_last_version = \"$template_current_version\" | .document_last_version = \"$document_current_version\"" configs.json)" && echo "${contents}" > configs.json
100-
101-
# Clean up from code generation
102-
- name: Remove excess files
103-
if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}}
104-
run: rm -rf ./definitions && rm -rf ./tooling
105-
27+
varFilePath: ./.github/variables/generator.env
10628
# Follow conventional commit for PR's to ensure accurate updates
10729
- name: Create pull request for major version if needed
10830
if: ${{env.major_version_change == 'true'}}
109-
uses: peter-evans/create-pull-request@v3
31+
uses: peter-evans/create-pull-request@v4
11032
with:
11133
title: "feat!: major version change"
112-
committer: GamingEventapiBot <gamingeventapi@gmail.com>
113-
author: GamingEventapiBot <gamingeventapi@gmail.com>
114-
delete-branch: true
115-
commit-message: ${{env.commit_message}}. Library require a new major version change.
116-
body: ${{env.commit_message}}. Library require a new major version change.
34+
11735
- name: Create pull request for minor version if needed
118-
if: ${{env.major_version_change == 'false' && env.minor_version_change == 'true'}}
119-
uses: peter-evans/create-pull-request@v3
36+
if: ${{env.minor_version_change == 'true'}}
37+
uses: peter-evans/create-pull-request@v4
12038
with:
12139
title: "feat: minor version change"
122-
committer: GamingEventapiBot <gamingeventapi@gmail.com>
123-
author: GamingEventapiBot <gamingeventapi@gmail.com>
124-
delete-branch: true
125-
commit-message: ${{env.commit_message}}. Library require a new minor version change.
126-
body: ${{env.commit_message}}. Library require a new minor version change.
40+
12741
- name: Create pull request for patch version if needed
128-
if: ${{env.major_version_change == 'false' && env.minor_version_change == 'false' && env.patch_version_change == 'true'}}
129-
uses: peter-evans/create-pull-request@v3
42+
if: ${{env.patch_version_change == 'true'}}
43+
uses: peter-evans/create-pull-request@v4
13044
with:
13145
title: "fix: patch version change"
132-
committer: GamingEventapiBot <gamingeventapi@gmail.com>
133-
author: GamingEventapiBot <gamingeventapi@gmail.com>
134-
delete-branch: true
135-
commit-message: ${{env.commit_message}}. Library require a new patch version change.
136-
body: ${{env.commit_message}}. Library require a new patch version change.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ msbuild.err
3434
msbuild.wrn
3535

3636
# Visual Studio 2015
37-
.vs/
37+
.vs/
38+
39+
.github/variables

custom_package.json

Lines changed: 0 additions & 2 deletions
This file was deleted.

generate.sh

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,27 @@ commit_message=""
1919

2020
document_last_version=$(cat ./configs.json | jq -r '.document_last_version')
2121
template_last_version=$(cat ./configs.json | jq -r '.template_last_version')
22-
library_last_version=$(cat ./package.json | jq -r '.version')
2322

2423
[ -d "./definitions" ] && rm -rf ./definitions
24+
[ -d "./tooling" ] && rm -rf ./tooling
2525

26-
template_current_version=$(curl -sL https://api.github.com/repos/asyncapi/ts-nats-template/releases/latest | jq -r '.tag_name' | sed 's/v//')
26+
template_current_version=$(curl -sL https://api.github.com/repos/asyncapi/dotnet-nats-template/releases/latest | jq -r '.tag_name' | sed 's/v//')
2727

2828
git clone https://github.com/GamingAPI/definitions.git definitions
2929
document_current_version=$(cat ./definitions/bundled/rust.asyncapi.json | jq -r '.info.version' | sed 's/v//')
3030

31+
if [ -f "./AsyncapiNatsClient/AsyncapiNatsClient.csproj" ]; then
32+
if ! command -v xml-to-json &> /dev/null
33+
then
34+
git clone https://github.com/tyleradams/json-toolkit.git tooling
35+
cd ./tooling && make json-diff json-empty-array python-dependencies && sudo make install
36+
cd ..
37+
fi
38+
library_last_version=$(cat ./AsyncapiNatsClient/AsyncapiNatsClient.csproj | xml-to-json | jq -r '.Project.PropertyGroup.Version')
39+
else
40+
library_last_version="0.0.0"
41+
fi
42+
3143
semver_template_last_version=( ${template_last_version//./ } )
3244
major_template_last_version=${semver_template_last_version[0]}
3345
minor_template_last_version=${semver_template_last_version[1]}
@@ -70,26 +82,20 @@ fi
7082

7183
if $major_version_change == 'true' || $minor_version_change == 'true' || $patch_version_change == 'true'; then
7284
# Remove previous files to ensure clean slate
73-
find . -not \( -name configs.json -or -name .gitignore -or -name LICENSE -or -name custom_package.json -or -name generate.sh -or -iwholename *.github* -or -iwholename *./definitions* -or -iwholename *.git* -or -name . \) -exec rm -rf {} +
85+
find . -not \( -name configs.json -or -name .gitignore -or -name LICENSE -or -name generate.sh -or -iwholename *.github* -or -iwholename *./definitions* -or -iwholename *.git* -or -name . \) -exec rm -rf {} +
7486

7587
# Generating client from the AsyncAPI document
7688
if ! command -v ag &> /dev/null
7789
then
7890
npm install -g @asyncapi/generator
7991
fi
8092

81-
ag --force-write --output ./ ./definitions/bundled/rust.asyncapi.json @asyncapi/ts-nats-template
93+
ag --force-write --output ./ ./definitions/bundled/rust.asyncapi.json @asyncapi/dotnet-nats-template -p version="$library_last_version"
8294

8395
# Write new config file to ensure we keep the new state for next time
8496
contents="$(jq ".template_last_version = \"$template_current_version\" | .document_last_version = \"$document_current_version\"" configs.json)" && echo "${contents}" > configs.json
85-
# Write old version to package.json file as it was cleared by the generator
86-
contents="$(jq ".version = \"$library_last_version\"" package.json)" && echo "${contents}" > package.json
87-
# Merge custom package file with template generated
88-
jq -s '.[0] * .[1]' ./package.json ./custom_package.json > ./package_tmp.json
89-
rm ./package.json
90-
mv ./package_tmp.json ./package.json
9197
rm -rf ./definitions
92-
npm i
98+
9399
fi
94100
mkdir -p ./.github/variables
95101
echo "
@@ -98,3 +104,4 @@ minor_version_change="$minor_version_change"
98104
patch_version_change="$patch_version_change"
99105
" > ./.github/variables/generator.env
100106
rm -rf ./definitions
107+
rm -rf ./tooling

package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)