Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a GitHub action for Beckn core specification to validate meta.yaml, registry.yaml and transaction.yaml files against OpenAPI3.0 #407

Open
wants to merge 1 commit into
base: draft
Choose a base branch
from

Conversation

rajaneeshk90
Copy link
Collaborator

@rajaneeshk90 rajaneeshk90 commented Jan 24, 2024

Issue

Summary:
While merging the PRs from other branches (draft, feature branch etc) of the Beckn protocol specification GitHub repository to the master branch of the Beckn protocol specification GitHub repository, openAPI syntactical errors already present in the source branch get added to the master branch.
More details about the issue can be found on the Beckn protocol specification issues page: #366

Changes Made

  1. Added a folder named workflows inside the .github directory at the root of the Beckn core protocol specification GitHub repository.

  2. Created a file under workflows named Beckn-Core-Spec-Validator.yml. Beckn-Core-Spec-Validator.yml. contains the GitHub Action code.

  3. The added GitHub Action validates api/transaction/build/transaction.yaml, api/meta/build/meta.yaml, and api/registry/build/registry.yaml against the OpenAPI 3.0 specification. The GitHub Action runs automatically at the occurrence of 2 events listed below:

    A push to the draft branch of the Beckn core protocol specification GitHub repository

    On creating a PR to the master branch of the Beckn core protocol specification GitHub repository.

  4. The GitHub action utilizes the beckn-spec-validator npm package for OpenAPI validation, created by the Beckn Community. We can find the details about the beckn-spec-validator npm package on the beckn-spec-validator GitHub page: https://github.com/beckn/beckn-utilities/tree/main/beckn-spec-validator

Tests performed to ensure that the created GitHub action is working as expected.

Tested the created GitHub action on a fork of the Beckn protocol specification for 2 cases:

  • Add an openAPI syntax error in the local copy of the fork and push the error to the forked repository's draft branch.

To introduce the error, a reference to a field called "Context1" was added in the api/meta/build/meta.yaml on the local copy of the fork. Adding Context1 introduced and error because the component Context1 is not defined in the api/meta/build/meta.yaml file but is referred.

When the change was pushed to the draft branch of the forked repository, the GitHub action was run. The GitHub action reported the Context1 error present in the Beckn specification. Link to the GitHub log for this run: https://github.com/rajaneeshk90/test-repo/actions/runs/7638902638/job/20810752019

  • Remove the openAPI syntax error from the local copy of the fork which was added in the previous step and push the change to the Beckn core specification GitHub repositors'y draft branch.

To test this scenario, the deliberate error introduced in the previous example (Context1 was added to the api/meta/build/meta.yaml file ) was removed. We change the Context1 back to Context, committed our change and pushed the commit to the forked repository of the core protocol specification. The GitHub action did not report any error for this change. Link to the GitHub log for this run: https://github.com/rajaneeshk90/test-repo/actions/runs/7639408975

Reviewer's Guidelines:

[Bring this change to your fork]
Add this code into your fork repo's draft branch (this code must be checked in inside the .github/workflows directory.
one way of bringing this change to your fork is described in the attached file.

PullPR407.txt

[Test out the github action]

  1. To test if the created GitHub Action catches openAPI syntactical errors in a change made in the Beckn core specification, follow the steps listed below:

Replace any occurrence of '$ref: '#/components/schemas/Context'' in the api/meta/build/meta.yaml file with $ref: '#/components/schemas/Context1 in the local clone of your fork.

Replacement of Context with Context1 will introduced and error because the component Context1 is not defined in the api/meta/build/meta.yaml file but is referred.

Save the file, create a GitHub commit, push the commit to the draft branch of your forked reposiotry. We can use the command 'git push origin <current-branch>:draft' to push the change.

When the change reaches GitHub, the GitHub Action will start running on your forked repository.

Go to the GitHub page of your forked repository. We can find the GitHub Actions in the Actions tab at the home page of your GitHub forked repository. Click on the Actions tab, it will list all the runs of the GitHub Action.

Each run of the GitHub Action will be tagged with the commit message of the change. The latest run would be at the top. click on the top run to check its result.

Please note that as per the current configuration, the GitHub action will run only when we push to the draft branch.

  1. To test if the GitHub Action passes for a valid openAPI change made in the Beckn core specification, follow the steps listed below:

Replace all occurrences of '$ref: '#/components/schemas/Context1'' in the api/meta/build/meta.yaml file with $ref: '#/components/schemas/Context in the local clone of your fork.

Save the file, create a GitHub commit, push the commit to the draft branch of your forked reposiotry. We can use the command 'git push origin <current-branch>:draft' to push the change.

When the change reaches GitHub, the GitHub Action will start running on your forked repository.

Go to the GitHub page of your forked repository. We can find the GitHub Actions in the Actions tab at the home page of your GitHub forked repository. Click on the Actions tab, it will list all the runs of the GitHub Action.

Each run of the GitHub Action will be tagged with the commit message of the change. The latest run would be at the top. click on the top run to check its result.

Any feedback or suggestions on this pull request would be greatly appreciated. Community input is valuable in making the development process more robust and efficient.

Thanks,
Rajaneesh

@rajaneeshk90
Copy link
Collaborator Author

@vbabuEM

Please review this PR.

@ravi-prakash-v
Copy link
Collaborator

Hi @rajaneeshk90,

In Pt 2, of the "Changes Made" section, you have mentioned

  1. Integrated beckn-spec-validator npm package created by the Beckn team for OpenAPI validation.

Can you please specify who is "the Beckn team". As per my knowledge, Beckn does not have a "team". Beckn only has a "community" of volunteers.

In Pt 2 of "Steps to Test" you have mentioned

  1. Cherry pick this change in that

Can you please be more specifi by what "this" and "that" mean?

Secondly, in the section named "Additional Information", you have mentioned,

  1. We are using a tool created by the Beckn team( npm package beckn-spec-validator) for validation.
  2. It gives us full control over the features and functionalities, allowing us to address unique requirements.

In Pt 1, can you please specify who is "we" and "Beckn team" (see my comment above).
In Pt 2, can you please specify who is "us"?

Can you please provide clarity on the above and make the necessary fixes. Thanks!

@rajaneeshk90 rajaneeshk90 changed the title adding github action for core spec to validate meta, registry and transaction yamls against OpenAPI3.0 Adding a GitHub action for Beckn core specification to validate meta.yaml, registry.yaml and transaction.yaml files against OpenAPI3.0 Feb 14, 2024
@ravi-prakash-v
Copy link
Collaborator

ravi-prakash-v commented Feb 19, 2024

@rajaneeshk90 unable to replicate your steps. No action ran on my forked repo

Cloned the forked repo

ravi@multivac:~/specs$ git clone [email protected]:ravi-prakash-v/protocol-specifications.git core-specs-fork-ravi
Cloning into 'core-specs-fork-ravi'...
remote: Enumerating objects: 6885, done.
remote: Counting objects: 100% (1919/1919), done.
remote: Compressing objects: 100% (785/785), done.
remote: Total 6885 (delta 964), reused 1737 (delta 901), pack-reused 4966
Receiving objects: 100% (6885/6885), 3.38 MiB | 1.66 MiB/s, done.
Resolving deltas: 100% (3854/3854), done.
ravi@multivac:~/specs$ cd core-specs-fork-ravi/
ravi@multivac:~/specs/core-specs-fork-ravi$ git checkout -b test-action-validation
Switched to a new branch 'test-action-validation'
ravi@multivac:~/specs/core-specs-fork-ravi$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

Added remote url

ravi@multivac:~/specs/core-specs-fork-ravi$ git remote add beckn-core [email protected]:beckn/protocol-specifications.git

Fetched PR

ravi@multivac:~/specs/core-specs-fork-ravi$ git fetch beckn-core pull/391/head:test-github-action
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 18 (delta 8), reused 16 (delta 8), pack-reused 0
Unpacking objects: 100% (18/18), 9.21 KiB | 1.84 MiB/s, done.
From github.com:beckn/protocol-specifications
 * [new ref]         refs/pull/391/head -> test-github-action
 * [new tag]         0.8.0-rc1          -> 0.8.0-rc1
 * [new tag]         beckn-core-0.9.3   -> beckn-core-0.9.3
 * [new tag]         core-0.8.1         -> core-0.8.1
 * [new tag]         core-0.8.2         -> core-0.8.2
 * [new tag]         core-0.8.3         -> core-0.8.3
 * [new tag]         core-0.9.0         -> core-0.9.0
 * [new tag]         core-0.9.2         -> core-0.9.2
 * [new tag]         core-0.9.3         -> core-0.9.3
 * [new tag]         core-v1.0.0        -> core-v1.0.0
 * [new tag]         core-v1.1.0        -> core-v1.1.0
 * [new tag]         fmd-0.8.0          -> fmd-0.8.0
 * [new tag]         fmd-0.8.0-rc1      -> fmd-0.8.0-rc1
 * [new tag]         fmd-0.8.0-rc2      -> fmd-0.8.0-rc2
 * [new tag]         fmd-0.8.0-rc3      -> fmd-0.8.0-rc3
 * [new tag]         fmd-0.8.0-rc3_002  -> fmd-0.8.0-rc3_002
 * [new tag]         fmd-0.8.1          -> fmd-0.8.1
 * [new tag]         fmd-0.8.2          -> fmd-0.8.2
 * [new tag]         fmd-0.8.3          -> fmd-0.8.3
 * [new tag]         local-retail-0.1.0 -> local-retail-0.1.0
 * [new tag]         mobility-0.8.1     -> mobility-0.8.1
 * [new tag]         mobility-0.8.2     -> mobility-0.8.2
ravi@multivac:~/specs/core-specs-fork-ravi$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Checked out branch test-github-action

Note: Had to checkout test-github-action branch as it was not mentioned in the steps. Hope that's correct.

ravi@multivac:~/specs/core-specs-fork-ravi$ git checkout test-github-action 
Switched to branch 'test-github-action'
ravi@multivac:~/specs/core-specs-fork-ravi$ cd api/
ravi@multivac:~/specs/core-specs-fork-ravi/api$ ls
meta  registry  transaction
ravi@multivac:~/specs/core-specs-fork-ravi/api$ cd meta/
ravi@multivac:~/specs/core-specs-fork-ravi/api/meta$ cd build/

Introduced an error

ravi@multivac:~/specs/core-specs-fork-ravi/api/meta/build$ vim meta.yaml 
ravi@multivac:~/specs/core-specs-fork-ravi/api/meta/build$ git add --all
ravi@multivac:~/specs/core-specs-fork-ravi/api/meta/build$ git commit -m "Introduced error"
[test-github-action bbc1b38] Introduced error
 12 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 api/meta/build/0.8.0-rc1
 create mode 100644 api/meta/build/beckn-core-0.9.3
 create mode 100644 api/meta/build/core-0.8.1
 create mode 100644 api/meta/build/core-0.8.2
 create mode 100644 api/meta/build/core-0.8.3
 create mode 100644 api/meta/build/core-0.9.0
 create mode 100644 api/meta/build/core-0.9.2
 create mode 100644 api/meta/build/core-0.9.3
 create mode 100644 api/meta/build/core-v1.0.0
 create mode 100644 api/meta/build/core-v1.1.0
 create mode 100644 api/meta/build/test-github-action

Pushed to draft

ravi@multivac:~/specs/core-specs-fork-ravi/api/meta/build$ git push origin test-github-action
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 12 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 678 bytes | 678.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: 
remote: Create a pull request for 'test-github-action' on GitHub by visiting:
remote:      https://github.com/ravi-prakash-v/protocol-specifications/pull/new/test-github-action
remote: 
To github.com:ravi-prakash-v/protocol-specifications.git
 * [new branch]      test-github-action -> test-github-action
ravi@multivac:~/specs/core-specs-fork-ravi/api/meta/build$ git push origin test-github-action:draft
Total 0 (delta 0), reused 0 (delta 0)
To github.com:ravi-prakash-v/protocol-specifications.git
   d20be6a..bbc1b38  test-github-action -> draft

Nothing happened...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants