Check Open API Framework Version #46
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: open-api-workflow oaf-check | |
on: | |
workflow_call: | |
inputs: | |
python-version: | |
type: string | |
required: true | |
workflow_dispatch: | |
inputs: | |
python-version: | |
type: string | |
default: "3.11" | |
description: Python Version | |
jobs: | |
oaf-up-to-date: | |
name: Check for new OAF version | |
runs-on: ubuntu-latest | |
outputs: | |
OAF_VERSION: ${{ steps.save-oaf-version.outputs.OAF_VERSION }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ inputs.python-version }} | |
cache: 'pip' | |
cache-dependency-path: 'requirements/*.txt' | |
- name: Install dependencies | |
run: pip install $(grep "pip-tools==" requirements/dev.txt) | |
- name: Run compile dependencies | |
run: ./bin/compile_dependencies.sh --upgrade-package open-api-framework | |
- name: Check git diff | |
run: git diff --exit-code -- requirements/*.txt | |
- name: Save OAF Version | |
id: save-oaf-version | |
run: echo "OAF_VERSION=$(grep -Po '(?<=open-api-framework==)[^\n]*' requirements/dev.txt)" >> $GITHUB_OUTPUT | |
create-oaf-update-pr: | |
name: Create a pull requests to update OAF | |
runs-on: ubuntu-latest | |
needs: [oaf-up-to-date] | |
if: failure() | |
env: | |
OAF_VERSION: ${{needs.oaf-up-to-date.outputs.OAF_VERSION}} | |
OAF_BRANCH: update/open-api-framework-$OAF_VERSION | |
ACTION_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
steps: | |
# Setup Git | |
- uses: actions/checkout@v4 | |
- name: Set up Git credentials | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
- name: Checker or Create Branch | |
# Checkout of create new branch if it already exists | |
run: | | |
git switch $OAF_BRANCH | \ | |
git switch -c $OAF_BRANCH | |
- name: Rebase onto main branch | |
# Rebase onto latest target branch. Step fails if conflicts exist | |
run: git rebase --onto ${{github.base_ref}} | |
- name: Reset to target branch if merge conflicts | |
# Reset branch to target branch if rebase fails | |
if: failure() | |
run: | | |
git rebase --abort | |
git reset --hard ${{github.base_ref}} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ inputs.python-version }} | |
cache: 'pip' | |
cache-dependency-path: 'requirements/*.txt' | |
- name: Install dependencies | |
run: pip install $(grep "pip-tools==" requirements/dev.txt) | |
- name: Run compile dependencies | |
run: ./bin/compile_dependencies.sh --upgrade-package open-api-framework | |
- name: Detect if changes need to be made | |
# Negate gif diff - returns 1 if changes, 0 if none ==> 0, 1 | |
run: "! git diff --exit-code -- requirements/*.txt" | |
- name: Commit Changes | |
run: "git commit -i requirements/*.txt -m ':arrow_up: Update Open-API-Framework to ${{env.OAF_VERSION}}'" | |
- name: Push Changes | |
run: git push -f --set-upstream origin $OAF_BRANCH | |
# GitHub | |
- name: Check for Existing PR | |
id: existing-pr | |
run: | | |
gh pr view $OAF_BRANCH >> /dev/null | |
echo "EXISTS=$?" >> $GITHUB_ENV | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Create New PR | |
if: ${{!env.EXISTS}} | |
run: | | |
gh pr create -B ${{github.base_ref}} \ | |
--title "Update Open API Framework to ${{env.OAF_VERSION}}" \ | |
--body "[Auto generated with github action.]($ACTION_URL)" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Update Existing PR | |
if: ${{env.EXISTS}} | |
run: echo "test" | |
env: | |
GH_TOKEN: ${{ github.token }} |