openapi-diff action #1
Workflow file for this run
This file contains hidden or 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: CI for changelog | ||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| CODEARTIFACT_AWS_ACCESS_KEY_ID: | ||
| required: false | ||
| CODEARTIFACT_AWS_SECRET_ACCESS_KEY: | ||
| required: false | ||
| inputs: | ||
| use_codeartifact: | ||
| type: boolean | ||
| default: false | ||
| AWS_CODEARTIFACT_REGION: | ||
| type: string | ||
| default: 'ap-southeast-1' | ||
| python-version: | ||
| type: string | ||
| default: '3.12' | ||
| poetry-version: | ||
| type: string | ||
| default: '1.8.2' | ||
| package-manager: | ||
| type: string | ||
| default: poetry | ||
| modules: | ||
| type: string | ||
| AWS_CODEARTIFACT_DOMAIN: | ||
| type: string | ||
| diff-tool: | ||
| type: string | ||
| default: oasdiff | ||
| jobs: | ||
| changelog: | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'pull_request' && (github.actor != 'dependabot[bot]' || github.actor != 'dependabot-preview[bot]') | ||
| steps: | ||
| - name: Configure AWS Credentials | ||
| if: ${{ inputs.use_codeartifact }} | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.CODEARTIFACT_AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.CODEARTIFACT_AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: ${{ inputs.AWS_CODEARTIFACT_REGION }} | ||
| - name: Get AWS Code Artifact token | ||
| if: ${{ inputs.use_codeartifact }} | ||
| run: | | ||
| echo "AWS_CODEARTIFACT_TOKEN=$(aws codeartifact get-authorization-token \ | ||
| --domain ${{ inputs.AWS_CODEARTIFACT_DOMAIN }} \ | ||
| --region ${{ inputs.AWS_CODEARTIFACT_REGION }} \ | ||
| --query authorizationToken \ | ||
| --output text)" >> $GITHUB_ENV | ||
| - name: Set Poetry Code Artifact token | ||
| if: ${{ inputs.use_codeartifact && inputs.package-manager == 'poetry' }} | ||
| run: echo "POETRY_HTTP_BASIC_ARTIFACT_PASSWORD=$AWS_CODEARTIFACT_TOKEN" >> $GITHUB_ENV | ||
| - name: Set uv Code Artifact token | ||
| if: ${{ inputs.use_codeartifact && inputs.package-manager == 'uv' }} | ||
| run: echo "UV_INDEX=https://aws:$AWS_CODEARTIFACT_TOKEN@${{ inputs.AWS_CODEARTIFACT_DOMAIN }}.d.codeartifact.${{ inputs.AWS_CODEARTIFACT_REGION }}.amazonaws.com/pypi/simple/" >> $GITHUB_ENV | ||
| - run: sudo apt-get install -y gettext | ||
| if: ${{ inputs.use_codeartifact }} | ||
| - name: Set up python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| - name: Install and configure Poetry | ||
| uses: snok/install-poetry@v1.4 | ||
| if: ${{ inputs.package-manager == 'poetry' }} | ||
| with: | ||
| version: ${{ inputs.poetry-version }} | ||
| - name: Install uv | ||
| if: ${{ inputs.package-manager == 'uv' }} | ||
| uses: astral-sh/setup-uv@v5 | ||
| - name: Check out current branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| path: current | ||
| - name: Install dependencies | ||
| run: poetry install | ||
| if: ${{ inputs.package-manager == 'poetry' }} | ||
| working-directory: current | ||
| - name: Install dependencies | ||
| run: uv sync --frozen | ||
| if: ${{ inputs.package-manager == 'uv' }} | ||
| working-directory: current | ||
| - name: Compile locales | ||
| if: ${{ inputs.use_codeartifact }} | ||
| run: poetry run python -m ${{ inputs.modules }} compile | ||
| working-directory: current | ||
| - name: Generate specification | ||
| run: make generate-spec | ||
| working-directory: current | ||
| - name: Check out main branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| path: base | ||
| - name: Install dependencies | ||
| run: poetry install | ||
| if: ${{ inputs.package-manager == 'poetry' }} | ||
| working-directory: base | ||
| - name: Install dependencies | ||
| run: uv sync --frozen | ||
| if: ${{ inputs.package-manager == 'uv' }} | ||
| working-directory: base | ||
| - name: Compile locales | ||
| if: ${{ inputs.use_codeartifact && inputs.package-manager == 'poetry' }} | ||
| run: poetry run python -m ${{ inputs.modules }} compile | ||
| working-directory: base | ||
| - name: Compile locales | ||
| if: ${{ inputs.use_codeartifact && inputs.package-manager == 'uv' }} | ||
| run: uv run python -m ${{ inputs.modules }} compile | ||
| working-directory: base | ||
| - name: Generate specification | ||
| run: make generate-spec | ||
| working-directory: base | ||
| - name: Running OpenAPI Spec diff action | ||
| id: spec_diff | ||
| uses: oasdiff/oasdiff-action/changelog@main | ||
| if: ${{ inputs.diff-tool == 'oasdiff' }} | ||
| with: | ||
| base: base/artefacts/spec.yaml | ||
| revision: current/artefacts/spec.yaml | ||
| - name: Running OpenAPI Diff action | ||
| id: spec_diff | ||
| uses: Pentusha/openapi-diff-action@v0.0.1 | ||
| if: ${{ inputs.diff-tool == 'openapi-diff' }} | ||
| with: | ||
| old-spec: base/artefacts/spec.yaml | ||
| new-spec: current/artefacts/spec.yaml | ||
| markdown: openapi-diff.md | ||
| - name: Update pull request | ||
| uses: nefrob/pr-description@v1.1.2 | ||
| if: ${{ inputs.diff-tool == 'oasdiff' }} | ||
| with: | ||
| content: "<!-- spec_changelog -->\n${{join(steps.spec_diff.outputs.*, '\n')}}\n<!-- spec_changelog -->" | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| regex: "<!-- spec_changelog -->.*?<!-- spec_changelog -->" | ||
| regexFlags: ims | ||
| - name: Read openapi-diff.md file | ||
| if: ${{ inputs.diff-tool == 'openapi-diff' }} | ||
| id: read_diff | ||
| run: | | ||
| CONTENT=$(cat openapi-diff.md) | ||
| echo "diff_content=$CONTENT" >> $GITHUB_OUTPUT | ||
| - name: Update pull request | ||
| uses: nefrob/pr-description@v1.1.2 | ||
| if: ${{ inputs.diff-tool == 'openapi-diff' }} | ||
| with: | ||
| content: "<!-- spec_changelog -->\n${{ steps.read_diff.outputs.diff_content }}\n<!-- spec_changelog -->" | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| regex: "<!-- spec_changelog -->.*?<!-- spec_changelog -->" | ||
| regexFlags: ims | ||
| - name: Add label to PR | ||
| if: inputs.diff-tool == 'oasdiff' && contains(steps.spec_diff.outputs.changelog, 'error [') | ||
| run: | | ||
| gh pr edit ${{ github.event.pull_request.number }} --add-label breaking-changes | ||
| working-directory: current | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Add label to PR | ||
| if: inputs.diff-tool == 'openapi-diff' && !steps.spec_diff.outputs.state.compatible | ||
| run: | | ||
| gh pr edit ${{ github.event.pull_request.number }} --add-label breaking-changes | ||
| working-directory: current | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Labeler | ||
| uses: actions/labeler@v5 | ||
| with: | ||
| sync-labels: true | ||