Ci pipeline config branching #321
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: API Contracts CI | |
'on': | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
detect-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
openapi_changed: '${{ steps.changed-files-specific.outputs.any_changed }}' | |
graphql_changed: '${{ steps.changed-graphqls-files.outputs.any_changed }}' | |
examples_changed: '${{ steps.changed-examples.outputs.any_changed }}' | |
changed_graphql_files: '${{ steps.changed-graphqls-files.outputs.all_changed_files }}' | |
changed_openapi_files: '${{steps.changed-files-specific.outputs.all_changed_files}}' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Detect OpenAPI Changes | |
id: changed-files-specific | |
uses: tj-actions/changed-files@v34 | |
with: | |
files: | | |
io/**/*.yaml | |
io/**/*.yml | |
io/**/*.json | |
files_ignore: | | |
kafka.yaml | |
**/*_examples/**/*.json | |
**/*_examples/**/*.yaml | |
- name: Detect GraphQL Changes | |
id: changed-graphqls-files | |
uses: tj-actions/changed-files@v34 | |
with: | |
files: | | |
io/**/*.graphqls | |
- name: Detect Examples Changes | |
id: changed-examples | |
uses: tj-actions/changed-files@v34 | |
with: | |
files: | | |
**/*_examples/**/*.json | |
**/*_examples/**/*.yaml | |
setup-environment: | |
needs: detect-changes | |
if: >- | |
needs.detect-changes.outputs.openapi_changed == 'true' || | |
needs.detect-changes.outputs.graphql_changed == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create Environment File | |
run: echo "Environment variables are set" | |
env: | |
GITHUB_SHA: ${{ github.sha }} | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
GITHUB_ACTOR: ${{ github.actor }} | |
GITHUB_WORKFLOW: ${{ github.workflow }} | |
GITHUB_HEAD_REF: ${{ github.head_ref }} | |
GITHUB_BASE_REF: ${{ github.base_ref || github.ref }} | |
linting-openAPI: | |
needs: detect-changes | |
if: 'needs.detect-changes.outputs.openapi_changed == ''true'' ' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install Spectral | |
run: npm install -g @stoplight/spectral-cli | |
- name: Run Spectral Linter for OpenAPI | |
run: | | |
echo "Running Spectral linter on changed OpenAPI files" | |
for file in ${{ needs.detect-changes.outputs.changed_openapi_files }}; | |
do | |
echo "Linting $file..." | |
spectral lint "$file" | |
done | |
linting-graphQL: | |
needs: detect-changes | |
if: needs.detect-changes.outputs.graphql_changed == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install GraphQL Schema Linter | |
run: npm install -g graphql-schema-linter | |
- name: Run GraphQL Schema Linter | |
run: > | |
echo "Running GraphQL schema linter on changed files" | |
for file in ${{ needs.detect-changes.outputs.changed_graphql_files }}; | |
do | |
echo "Linting $file..." | |
graphql-schema-linter "$file" | |
done | |
specmatic-examples-validation-openAPI: | |
needs: detect-changes | |
runs-on: ubuntu-latest | |
if: >- | |
needs.detect-changes.outputs.examples_changed == 'true' || | |
needs.detect-changes.outputs.openapi_changed == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Validate Specmatic OpenAPI examples | |
run: > | |
docker run -v "$(pwd):/central-contract-repo:rw" znsio/specmatic | |
examples validate \ | |
--contract-file /central-contract-repo/io/specmatic/examples/store/openapi/product_search_bff_v4.yaml | |
specmatic-examples-validation-graphQL: | |
needs: detect-changes | |
runs-on: ubuntu-latest | |
if: >- | |
needs.detect-changes.outputs.examples_changed == 'true' || | |
needs.detect-changes.outputs.graphql_changed == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Validate Specmatic GraphQL examples | |
run: | | |
docker run -v "$(pwd):/central-contract-repo:rw" \ | |
--entrypoint /bin/sh \ | |
znsio/specmatic-graphql-trial \ | |
-c "cd /central-contract-repo && java -jar /usr/src/app/specmatic-graphql.jar examples validate --spec-file io/specmatic/examples/store/graphql/products_bff.graphqls" | |
specmatic-backward-compatibility-openAPI: | |
needs: setup-environment | |
runs-on: ubuntu-latest | |
if: needs.detect-changes.outputs.openapi_changed == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Specmatic OpenAPI Backward Compatibility Check | |
run: | | |
docker run -v "$(pwd):/central-contract-repo:rw" \ | |
--env GITHUB_SHA=${{ env.GITHUB_SHA }} \ | |
--env GITHUB_REPOSITORY=${{ env.GITHUB_REPOSITORY }} \ | |
--env GITHUB_ACTOR=${{ env.GITHUB_ACTOR }} \ | |
--env GITHUB_WORKFLOW=${{ env.GITHUB_WORKFLOW }} \ | |
--env GITHUB_HEAD_REF=${{ env.GITHUB_HEAD_REF }} \ | |
--env GITHUB_BASE_REF=${{ env.GITHUB_BASE_REF }} \ | |
--entrypoint /bin/sh znsio/specmatic \ | |
-c "git config --global --add safe.directory /central-contract-repo && cd /central-contract-repo && java -jar /usr/src/app/specmatic.jar backward-compatibility-check --base-branch origin/main" | |
specmatic-backward-compatibility-graphQL: | |
needs: setup-environment | |
runs-on: ubuntu-latest | |
if: needs.detect-changes.outputs.graphql_changed == 'true' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Specmatic GraphQL Backward Compatibility Check | |
run: | | |
docker run -v "$(pwd):/central-contract-repo:rw" \ | |
--env GITHUB_SHA=${{ env.GITHUB_SHA }} \ | |
--env GITHUB_REPOSITORY=${{ env.GITHUB_REPOSITORY }} \ | |
--env GITHUB_ACTOR=${{ env.GITHUB_ACTOR }} \ | |
--env GITHUB_WORKFLOW=${{ env.GITHUB_WORKFLOW }} \ | |
--env GITHUB_HEAD_REF=${{ env.GITHUB_HEAD_REF }} \ | |
--env GITHUB_BASE_REF=${{ env.GITHUB_BASE_REF }} \ | |
--entrypoint /bin/sh \ | |
znsio/specmatic-graphql-trial \ | |
-c "git config --global --add safe.directory /central-contract-repo && cd /central-contract-repo && java -jar /usr/bin/specmatic-graphql.jar backwardCompatibilityCheck" | |
build-summary-openAPI: | |
needs: | |
- linting-openAPI | |
- specmatic-examples-validation-openAPI | |
- specmatic-backward-compatibility-openAPI | |
if: always() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Pipeline Status | |
run: > | |
if [[ "${{ needs.linting-openAPI.result }}" == "failure" ]]; | |
then | |
echo "linting-openAPI failed!" | |
exit 1 | |
fi | |
if [[ "${{ needs.specmatic-examples-validation-openAPI.result }}" == | |
"failure" ]]; then | |
echo "specmatic-examples-validation-openAPI failed!" | |
exit 1 | |
fi | |
if [[ "${{ needs.specmatic-backward-compatibility-openAPI.result }}" | |
== "failure" ]]; then | |
echo "specmatic-backward-compatibility-openAPI failed!" | |
exit 1 | |
fi | |
echo "All OpenAPI build jobs completed successfully!" | |
build-summary-graphQL: | |
needs: | |
- linting-graphQL | |
- specmatic-examples-validation-graphQL | |
- specmatic-backward-compatibility-graphQL | |
if: always() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Pipeline Status | |
run: > | |
if [[ "${{ needs.linting-graphQL.result }}" == "failure" ]]; | |
then | |
echo "linting-graphQL failed!" | |
exit 1 | |
fi | |
if [[ "${{ needs.specmatic-examples-validation-graphQL.result }}" == | |
"failure" ]]; then | |
echo "specmatic-examples-validation-graphQL failed!" | |
exit 1 | |
fi | |
if [[ "${{ needs.specmatic-backward-compatibility-graphQL.result }}" | |
== "failure" ]]; then | |
echo "specmatic-backward-compatibility-graphQL failed!" | |
exit 1 | |
fi | |
echo "All GraphQL build jobs completed successfully!" | |
overall-build-summary: | |
needs: | |
- build-summary-graphQL | |
- build-summary-openAPI | |
if: always() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Check OpenAPI and GraphQL Summary | |
run: | | |
if [[ "${{ needs.build-summary-openAPI.result }}" == "failure" ]]; then | |
echo "OpenAPI related jobs failed!" | |
exit 1 | |
fi | |
if [[ "${{ needs.build-summary-graphQL.result }}" == "failure" ]]; then | |
echo "GraphQL related jobs failed!" | |
exit 1 | |
fi | |
echo "All build jobs completed successfully!" | |