Skip to content

Commit 19bc972

Browse files
committed
refactor: re-add template
1 parent 87cf544 commit 19bc972

File tree

7 files changed

+164
-120
lines changed

7 files changed

+164
-120
lines changed

.github/actions/setvars/action.yml

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

.github/workflows/auto-update.yml

Lines changed: 109 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Auto update generated client
1+
name: Auto update generated library
22
on:
33
workflow_dispatch:
44
schedule:
@@ -8,38 +8,129 @@ 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: ""
1127
jobs:
12-
update-code:
28+
get-template-version:
1329
runs-on: ubuntu-latest
1430
steps:
15-
- uses: actions/checkout@v3
16-
17-
- uses: actions/setup-node@v3
31+
- name: Get utility library
32+
uses: actions/checkout@v2
33+
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
1850
with:
19-
node-version: '14'
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
2055

21-
- name: Generate code
22-
run: chmod +x ./generate.sh && ./generate.sh
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
2369

24-
- name: Set Environment Variables from generator file
25-
uses: ./.github/actions/setvars
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
83+
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
2691
with:
27-
varFilePath: ./.github/variables/generator.env
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+
28106
# Follow conventional commit for PR's to ensure accurate updates
29107
- name: Create pull request for major version if needed
30108
if: ${{env.major_version_change == 'true'}}
31-
uses: peter-evans/create-pull-request@v4
109+
uses: peter-evans/create-pull-request@v3
32110
with:
33111
title: "feat!: major version change"
34-
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.
35117
- name: Create pull request for minor version if needed
36-
if: ${{env.minor_version_change == 'true'}}
37-
uses: peter-evans/create-pull-request@v4
118+
if: ${{env.major_version_change == 'false' && env.minor_version_change == 'true'}}
119+
uses: peter-evans/create-pull-request@v3
38120
with:
39121
title: "feat: minor version change"
40-
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.
41127
- name: Create pull request for patch version if needed
42-
if: ${{env.patch_version_change == 'true'}}
43-
uses: peter-evans/create-pull-request@v4
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
44130
with:
45131
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.

.github/workflows/pull-request-integration-testing.yml

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

.github/workflows/pull-request-testing.yml

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

.github/workflows/release.yml

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,22 @@ on:
77

88
jobs:
99
release:
10-
name: 'Release NPM, GitHub'
1110
runs-on: ubuntu-latest
11+
permissions:
12+
packages: write
13+
contents: read
1214
steps:
13-
- name: Checkout repo
14-
uses: actions/checkout@v2
15-
- name: Setup Node.js
16-
uses: actions/setup-node@v1
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-dotnet@v1
1717
with:
18-
node-version: 13
19-
- name: Install dependencies
20-
run: npm ci
21-
- name: Build library
22-
run: npm run build
23-
- name: Get version from package.json before release step
24-
id: initversion
25-
run: echo "::set-output name=version::$(npm run get-version --silent)"
26-
- name: Release to NPM and GitHub
27-
id: release
18+
dotnet-version: '3.1.x' # SDK Version to use.
19+
source-url: https://nuget.pkg.github.com/GamingAPI/index.json
2820
env:
29-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
30-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
31-
GIT_AUTHOR_NAME: GamingEventapiBot
32-
GIT_AUTHOR_EMAIL: gamingeventapi@gmail.com
33-
GIT_COMMITTER_NAME: GamingEventapiBot
34-
GIT_COMMITTER_EMAIL: gamingeventapi@gmail.com
35-
run: npm run release
36-
- name: Get version from package.json after release step
37-
id: extractver
38-
run: echo "::set-output name=version::$(npm run get-version --silent)"
39-
- name: Create Pull Request with updated package files
40-
if: steps.initversion.outputs.version != steps.extractver.outputs.version
41-
uses: peter-evans/create-pull-request@v2.4.4
42-
with:
43-
token: ${{ secrets.GH_TOKEN }}
44-
commit-message: 'chore(release): ${{ steps.extractver.outputs.version }}'
45-
committer: GamingEventapiBot <gamingeventapi@gmail.com>
46-
author: GamingEventapiBot <gamingeventapi@gmail.com>
47-
title: 'chore(release): ${{ steps.extractver.outputs.version }}'
48-
body: 'Version bump in package.json and package-lock.json for release [${{ steps.extractver.outputs.version }}](https://github.com/${{github.repository}}/releases/tag/v${{ steps.extractver.outputs.version }})'
49-
branch: version-bump/${{ steps.extractver.outputs.version }}
21+
NUGET_AUTH_TOKEN: ${{secrets.NUGET_AUTH_TOKEN}}
22+
- name: Install dependencies
23+
run: dotnet restore
24+
- run: dotnet build --configuration Release AsyncapiNatsClient
25+
- name: Create the package
26+
run: dotnet pack --configuration Release AsyncapiNatsClient
27+
- name: Publish the package to GitHub registry
28+
run: dotnet nuget push AsyncapiNatsClient/bin/Release/*.nupkg --api-key ${{secrets.NUGET_AUTH_TOKEN}}

.gitignore

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
1-
node_modules
2-
.github/variables
1+
*.swp
2+
*.*~
3+
project.lock.json
4+
.DS_Store
5+
*.pyc
6+
nupkg/
7+
8+
# Visual Studio Code
9+
.vscode
10+
11+
# Rider
12+
.idea
13+
14+
# User-specific files
15+
*.suo
16+
*.user
17+
*.userosscache
18+
*.sln.docstates
19+
20+
# Build results
21+
[Dd]ebug/
22+
[Dd]ebugPublic/
23+
[Rr]elease/
24+
[Rr]eleases/
25+
x64/
26+
x86/
27+
build/
28+
bld/
29+
[Bb]in/
30+
[Oo]bj/
31+
[Oo]ut/
32+
msbuild.log
33+
msbuild.err
34+
msbuild.wrn
35+
36+
# Visual Studio 2015
37+
.vs/

configs.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"template_last_version": "0.0.0",
3-
"document_last_version": "0.0.0"
4-
}
2+
"template_last_version": "0.0.0",
3+
"document_last_version": "0.0.0"
4+
}

0 commit comments

Comments
 (0)