Skip to content

Commit afdc091

Browse files
authored
fix: Openapi spec version and update gh workflow (#470)
* fix: Openapi spec version and update gh workflow * fix: Inject version via modifiers
1 parent dfb12e0 commit afdc091

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

.github/workflows/release-please.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,61 @@ jobs:
182182
Cargo.lock
183183
docs/antora.yml
184184
185+
# Update openapi json file
186+
update-openapi-spec-file:
187+
name: Update openapi.json file
188+
needs: release-please
189+
if: ${{ needs.release-please.outputs.release_created == 'false' && needs.release-please.outputs.pr_created == 'true' }}
190+
runs-on: ubuntu-latest
191+
steps:
192+
- name: Harden the runner (Audit all outbound calls)
193+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
194+
with:
195+
egress-policy: audit
196+
- name: Get github app token
197+
uses: actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b # v2.1.1
198+
id: gh-app-token
199+
with:
200+
app-id: ${{ vars.GH_APP_ID }}
201+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
202+
- name: Get PR details
203+
id: release-branch
204+
run: |
205+
echo "pr head branch name: >>>>> ${{ needs.release-please.outputs.release_branch }}"
206+
- name: Checkout release branch
207+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
208+
with:
209+
fetch-depth: 2
210+
token: ${{ steps.gh-app-token.outputs.token }}
211+
ref: ${{ needs.release-please.outputs.release_branch }}
212+
- name: Get GitHub App User ID
213+
id: get-user-id
214+
run: echo "user-id=$(gh api "/users/${{ steps.gh-app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
215+
env:
216+
GH_TOKEN: ${{ steps.gh-app-token.outputs.token }}
217+
- name: Prepare
218+
id: init
219+
uses: ./.github/actions/prepare
220+
- name: Cargo generate api
221+
id: update-openapi-spec-commit
222+
run: |-
223+
OPENAPI_SPEC_FILE="docs/openapi.json"
224+
cargo generate_openapi
225+
if ! git diff --quiet "$OPENAPI_SPEC_FILE"; then
226+
echo "openapi_changed=true" >> $GITHUB_OUTPUT
227+
else
228+
echo "openapi_changed=false" >> $GITHUB_OUTPUT
229+
fi
230+
- name: Commit openapi spec file
231+
if: steps.update-openapi-spec-commit.outputs.openapi_changed == 'true'
232+
uses: iarekylew00t/verified-bot-commit@cc09d455be3e20eb6b1c3d1c30a5221f9475aa10 # v1.5.1
233+
with:
234+
message: 'chore: Updating openapi spec file and bumping version'
235+
token: ${{ steps.gh-app-token.outputs.token }}
236+
ref: ${{ needs.release-please.outputs.release_branch }}
237+
files: |-
238+
docs/openapi.json
239+
185240
# Update rust docs link in nav.adoc
186241
update-rust-docs-link:
187242
needs: release-please

docs/openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"name": "AGPL-3.0 license",
1313
"url": "https://github.com/OpenZeppelin/openzeppelin-relayer/blob/main/LICENSE"
1414
},
15-
"version": "1.0.0"
15+
"version": "1.1.0"
1616
},
1717
"paths": {
1818
"/api/v1/notifications": {

src/openapi.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ use utoipa::{
1111
Modify, OpenApi,
1212
};
1313

14+
const API_VERSION: &str = env!("CARGO_PKG_VERSION");
15+
16+
struct VersionFromEnv;
17+
18+
impl Modify for VersionFromEnv {
19+
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
20+
openapi.info.version = API_VERSION.to_string();
21+
}
22+
}
1423
struct SecurityAddon;
1524

1625
impl Modify for SecurityAddon {
@@ -29,7 +38,7 @@ impl Modify for SecurityAddon {
2938
/// OpenZeppelin Relayer API definitions.
3039
#[derive(OpenApi)]
3140
#[openapi(
32-
modifiers(&SecurityAddon),
41+
modifiers(&SecurityAddon, &VersionFromEnv),
3342
tags(
3443
(name = "Relayers", description = "Relayers are the core components of the OpenZeppelin Relayer API. They are responsible for executing transactions on behalf of users and providing a secure and reliable way to interact with the blockchain."),
3544
(name = "Plugins", description = "Plugins are TypeScript functions that can be used to extend the OpenZeppelin Relayer API functionality."),
@@ -38,7 +47,7 @@ impl Modify for SecurityAddon {
3847
(name = "Metrics", description = "Metrics are responsible for showing the metrics related to the relayers."),
3948
(name = "Health", description = "Health is responsible for showing the health of the relayers.")
4049
),
41-
info(description = "OpenZeppelin Relayer API", version = "1.0.0", title = "OpenZeppelin Relayer API", license(
50+
info(description = "OpenZeppelin Relayer API", version = "0.0.0", title = "OpenZeppelin Relayer API", license(
4251
name = "AGPL-3.0 license",
4352
url = "https://github.com/OpenZeppelin/openzeppelin-relayer/blob/main/LICENSE"
4453
),

0 commit comments

Comments
 (0)