Skip to content

Commit

Permalink
🚧 big updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Coperh committed Nov 11, 2024
1 parent 64243ff commit c03a557
Showing 1 changed file with 48 additions and 14 deletions.
62 changes: 48 additions & 14 deletions .github/workflows/oaf-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ 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: 3.11
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: 'requirements/*.txt'
- name: Install dependencies
Expand All @@ -21,55 +32,78 @@ jobs:
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
- 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: 3.11
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: Get OAF Version
run: echo "OAF_VERSION=$(grep -Po '(?<=open-api-framework==)[^\n]*' requirements/dev.txt)" >> $GITHUB_ENV
# Git
- name: Create and Checkout Branch
run: git checkout -q -B update/open-api-framework-${{env.OAF_VERSION}}

- 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 update/open-api-framework-${{env.OAF_VERSION}}
run: git push -f --set-upstream origin $OAF_BRANCH

# GitHub
- name: Check for Existing PR
id: existing-pr
run: |
gh pr view update/open-api-framework-${{env.OAF_VERSION}} >> /dev/null
echo "EXISTS=$?" >> $GITHUB_ENV
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 --title "Update Open API Framework to ${{env.OAF_VERSION}}" \
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 }}
ACTION_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Update Existing PR
if: ${{env.EXISTS}}
run: echo "test"
env:
GH_TOKEN: ${{ github.token }}
ACTION_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

0 comments on commit c03a557

Please sign in to comment.