From 9b1fd8e06a46476cb0bc01e9b606a2d4275446e6 Mon Sep 17 00:00:00 2001 From: API Evolution Management Service CI Date: Sun, 7 May 2023 19:27:54 +0000 Subject: [PATCH] Publish new version from API Evolution Management Service CI (https://circleci.com/gh/fernandomrtnz/api-evolution-management-service/115) --- .github/workflows/main.yml | 24 ++++++++++++++ README.md | 66 ++++++++++++++++++++++++++++++++++++++ action.yml | 49 ++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 README.md create mode 100644 action.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5ffb369 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,24 @@ +name: Publish + +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Bump version and create a release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.CREATE_RELEASE_TOKEN }} + with: + tag_name: v1.0.0-beta + release_name: Release v1.0.0-beta + draft: false + prerelease: false diff --git a/README.md b/README.md new file mode 100644 index 0000000..5354b82 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# API Evolution Check Action + +This GitHub Action checks for breaking changes in your API specifications by comparing the current branch's API specification file with the one in the main branch. It requires a file path to your OpenAPI specification file and an access token for the API Evolution Management Service. + +## Usage + +Add the following workflow configuration (e.g., `.github/workflows/api_check.yml`) to your repository: + +```yaml +name: API Evolution Check + +on: + push: + branches: + - main + - '*' # This will match any branch + +jobs: + api_evolution_check: + runs-on: ubuntu-latest + + steps: + - name: Run API Evolution Check + uses: /gh-action-test-tostones@ + with: + file_path: path/to/api/specification/file.yaml + access_token: ${{ secrets.API_EVOLUTION_ACCESS_TOKEN }} +``` + +Replace `` with the actual GitHub username and `` with the desired version (e.g., `v1` or `main`) of the action. Also, replace `path/to/api/specification/file.yaml` with the path to your OpenAPI specification file. + +For the `access_token` input, use the `secrets` context to store and retrieve the API Evolution Management Service access token securely. Create a secret in your repository (e.g., named `API_EVOLUTION_ACCESS_TOKEN`) and store the access token there. + +## Inputs + +| Name | Description | Required | +|---------------|------------------------------------------------------|----------| +| `file_path` | Path to the API specification file you want to compare | Yes | +| `access_token`| API Evolution Management Service access token | Yes | + +## Example + +This example demonstrates how to use the action in a workflow: + +```yaml +name: API Evolution Check + +on: + push: + branches: + - main + - '*' # This will match any branch + +jobs: + api_evolution_check: + runs-on: ubuntu-latest + + steps: + - name: Run API Evolution Check + uses: /gh-action-test-tostones@v1 + with: + file_path: api/openapi.yaml + access_token: ${{ secrets.API_EVOLUTION_ACCESS_TOKEN }} +``` + +Replace `` with the actual GitHub username and `v1` with the desired version of the action. \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..87bf891 --- /dev/null +++ b/action.yml @@ -0,0 +1,49 @@ +name: gh-action-test-tostones +description: "Check for breaking changes in API specifications" + +inputs: + file_path: + description: "Path to the API specification that you want to compare" + required: true + access_token: + description: "API Evolution Management Service access token" + required: true + +runs: + using: "composite" + steps: + - name: Checkout main branch + uses: actions/checkout@v2 + with: + ref: main + path: main + + - name: Checkout current branch + uses: actions/checkout@v2 + with: + path: current + + - name: Debug + run: | + cat "${GITHUB_WORKSPACE}/main/${{ inputs.file_path }}" + cat "${GITHUB_WORKSPACE}/current/${{ inputs.file_path }}" + + - name: Check for breaking changes + run: | + before_file_path="${GITHUB_WORKSPACE}/main/${{ inputs.file_path }}" + after_file_path="${GITHUB_WORKSPACE}/current/${{ inputs.file_path }}" + api_url="https://qlq2x2wbi74vc4h6hvjgc5szky0phost.lambda-url.us-east-2.on.aws/" + + if [ -f "${before_file_path}" ] && [ -f "${after_file_path}" ]; then + response=$(curl -X POST \ + "${api_url}" \ + -H "Content-Type: multipart/form-data" \ + -H "Authorization: Bearer ${{ inputs.access_token }}" \ + -F "before=@${before_file_path}" \ + -F "after=@${after_file_path}") + + echo "Upload response: ${response}" + else + echo "File not found in either main or current branch." + fi + shell: bash