|
1 | | -name: Auto update generated client |
2 | | -on: |
3 | | - workflow_dispatch: |
4 | | - schedule: |
5 | | - - cron: '0 0 * * *' |
6 | 1 |
|
7 | | - # Allows external webhook trigger |
8 | 2 | repository_dispatch: |
9 | 3 | types: |
10 | 4 | - 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: "" |
27 | 5 | jobs: |
28 | | - get-template-version: |
| 6 | + update-code: |
29 | 7 | runs-on: ubuntu-latest |
30 | 8 | steps: |
31 | | - - uses: actions/checkout@v2 |
32 | | - # Find all relevant semver versions needed to figure out how to update the client |
33 | | - - name: Fetch the last AsyncAPI document version that generated the client |
34 | | - run: echo "document_last_version=$(cat ./configs.json | jq -r '.document_last_version')" >> $GITHUB_ENV |
35 | | - - name: Fetch the last template version that generated the client |
36 | | - run: echo "template_last_version=$(cat ./configs.json | jq -r '.template_last_version')" >> $GITHUB_ENV |
37 | | - - name: Fetch the last library version |
38 | | - run: echo "library_last_version=$(cat ./package.json | jq -r '.version':=0.0.0)" >> $GITHUB_ENV |
39 | | - - name: Fetch current template version |
40 | | - run: echo "template_current_version=$(curl -sL https://api.github.com/repos/asyncapi/ts-nats-template/releases/latest | jq -r '.tag_name' | sed 's/v//')" >> $GITHUB_ENV |
41 | | - - name: Get all the application AsyncAPI documents |
42 | | - uses: actions/checkout@v2 |
| 9 | + - uses: actions/checkout@v3 |
| 10 | + |
| 11 | + - uses: actions/setup-node@v3 |
43 | 12 | with: |
44 | | - repository: GamingAPI/definitions |
45 | | - path: "./definitions" |
46 | | - - name: Get the version of the API |
47 | | - run: echo "document_current_version=$(cat ./definitions/bundled/rust.asyncapi.json | jq -r '.info.version' | sed 's/v//')" >> $GITHUB_ENV |
| 13 | + node-version: '14' |
48 | 14 |
|
49 | | - # Figure out how the template version have changed |
50 | | - - 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 |
51 | | - - 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 |
52 | | - - 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 |
53 | | - - 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 |
54 | | - - 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 |
55 | | - - 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 |
56 | | - - if: ${{ env.major_template_current_version > env.major_template_last_version }} |
57 | | - run: echo "major_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}Template have changed to a new major version." >> $GITHUB_ENV |
58 | | - - if: ${{ env.minor_template_current_version > env.minor_template_last_version }} |
59 | | - run: echo "minor_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}Template have changed to a new minor version." >> $GITHUB_ENV |
60 | | - - if: ${{ env.patch_template_current_version > env.patch_template_last_version }} |
61 | | - run: echo "patch_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}Template have changed to a new patch version." >> $GITHUB_ENV |
62 | | - |
63 | | - # Figure out how the AsyncAPI document have changed |
64 | | - - 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 |
65 | | - - 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 |
66 | | - - 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 |
67 | | - - 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 |
68 | | - - 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 |
69 | | - - 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 |
70 | | - - if: ${{ env.major_document_current_version > env.major_document_last_version }} |
71 | | - run: echo "major_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}AsyncAPI document have changed to a new major version. " >> $GITHUB_ENV |
72 | | - - if: ${{ env.minor_document_current_version > env.minor_document_last_version && env.major_document_current_version < env.major_document_last_version }} |
73 | | - run: echo "minor_version_change=true" >> $GITHUB_ENV && echo "commit_message=${commit_message}AsyncAPI document have changed to a new minor version. " >> $GITHUB_ENV |
74 | | - - 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 }} |
75 | | - 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 |
| 15 | + - name: Generate code |
| 16 | + run: chmod +x ./generate.sh && ./generate.sh |
76 | 17 |
|
77 | | - # Make changes to the client code if needed |
78 | | - - name: Remove previous files to ensure clean slate |
79 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
80 | | - run: find . -not \( -name configs.json -or -name .gitignore -or -name custom_package.json -or -iwholename *.github* -or -iwholename *./definitions* -or -iwholename *.git* -or -name . \) -exec echo {} + |
81 | | - - name: Generating client from the AsyncAPI document |
82 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
83 | | - uses: docker://asyncapi/github-action-for-generator |
| 18 | + - name: Set Environment Variables from generator file |
| 19 | + uses: ./.github/actions/setvars |
84 | 20 | with: |
85 | | - template: '@asyncapi/ts-nats-template' |
86 | | - filepath: ./definitions/bundled/rust.asyncapi.json |
87 | | - output: ./ |
88 | | - - name: Write new config file to ensure we keep the new state for next time |
89 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
90 | | - run: | |
91 | | - contents="$(jq ".template_last_version = \"$template_current_version\" | .document_last_version = \"$document_current_version\"" configs.json)" && echo "${contents}" > configs.json |
92 | | - - name: Write old version to package.json file as it was cleared by the generator |
93 | | - if: ${{ env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
94 | | - run: contents="$(jq ".version = \"$library_last_version\"" package.json)" && echo "${contents}" > package.json |
95 | | - - name: Merge custom package file with template generated |
96 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
97 | | - run: jq -s '.[0] * .[1]' ./package.json ./custom_package.json > ./package_tmp.json |
98 | | - - name: Remove old package file |
99 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
100 | | - run: rm ./package.json |
101 | | - - name: Take new package file in use |
102 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
103 | | - run: mv ./package_tmp.json ./package.json |
104 | | - |
105 | | - # Clean up from code generation |
106 | | - - name: Remove excess files |
107 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
108 | | - run: rm -rf ./definitions |
109 | | - |
110 | | - # Build the library |
111 | | - - name: Install dependencies |
112 | | - if: ${{env.major_version_change == 'true' || env.minor_version_change == 'true' || env.patch_version_change == 'true'}} |
113 | | - run: npm i |
114 | | - |
| 21 | + varFilePath: ./.github/variables/generator.env |
115 | 22 | # Follow conventional commit for PR's to ensure accurate updates |
116 | 23 | - name: Create pull request for major version if needed |
117 | 24 | if: ${{env.major_version_change == 'true'}} |
118 | | - uses: peter-evans/create-pull-request@v3 |
| 25 | + uses: peter-evans/create-pull-request@v4 |
119 | 26 | with: |
120 | 27 | title: "feat!: major version change" |
121 | | - committer: GamingEventapiBot <gamingeventapi@gmail.com> |
122 | | - author: GamingEventapiBot <gamingeventapi@gmail.com> |
123 | | - delete-branch: true |
124 | | - commit-message: ${{env.commit_message}}. Library require a new major version change. |
125 | | - body: ${{env.commit_message}}. Library require a new major version change. |
| 28 | + |
126 | 29 | - name: Create pull request for minor version if needed |
127 | 30 | if: ${{env.minor_version_change == 'true'}} |
128 | | - uses: peter-evans/create-pull-request@v3 |
| 31 | + uses: peter-evans/create-pull-request@v4 |
129 | 32 | with: |
130 | 33 | title: "feat: minor version change" |
131 | | - committer: GamingEventapiBot <gamingeventapi@gmail.com> |
132 | | - author: GamingEventapiBot <gamingeventapi@gmail.com> |
133 | | - delete-branch: true |
134 | | - commit-message: ${{env.commit_message}}. Library require a new minor version change. |
135 | | - body: ${{env.commit_message}}. Library require a new minor version change. |
| 34 | + |
136 | 35 | - name: Create pull request for patch version if needed |
137 | 36 | if: ${{env.patch_version_change == 'true'}} |
138 | | - uses: peter-evans/create-pull-request@v3 |
| 37 | + uses: peter-evans/create-pull-request@v4 |
139 | 38 | with: |
140 | 39 | title: "fix: patch version change" |
141 | | - committer: GamingEventapiBot <gamingeventapi@gmail.com> |
142 | | - author: GamingEventapiBot <gamingeventapi@gmail.com> |
143 | | - delete-branch: true |
144 | | - commit-message: ${{env.commit_message}}. Library require a new patch version change. |
145 | | - body: ${{env.commit_message}}. Library require a new patch version change. |
0 commit comments