Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷 add job to update open-api-framework #4

Merged
merged 14 commits into from
Jan 3, 2025
Merged
16 changes: 13 additions & 3 deletions .github/workflows/oaf-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ jobs:
oaf-up-to-date:
name: Check for new OAF version
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: 'requirements/dev.txt'
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
# save the package version for branch names and commit messages
if: failure()
id: save-oaf-version
run: echo "OAF_VERSION=$(grep --perl-regexp --only-matching '(?<=open-api-framework==)[^\n]*' requirements/dev.txt)" >> $GITHUB_ENV
- name: Create Update PR
if: ${{ failure() && steps.save-oaf-version.conclusion == 'success' }}
uses: maykinmedia/open-api-workflows/actions/create-update-pr@v4-a
with:
branch-name: update/open-api-framework-${{env.OAF_VERSION}}
commit-message: ':arrow_up: Update Open-API-Framework to ${{env.OAF_VERSION}}'
pr-title: Update Open API Framework to ${{env.OAF_VERSION}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

env
.idea
39 changes: 39 additions & 0 deletions actions/create-update-pr/action.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this file being called? Is it defined in the down stream project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called in check .github/workflows/oaf-check.yml in this PR which is then called for exam le here: https://github.com/Coperh/objects-api/blob/master/.github/workflows/oaf-check.yml

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Create or Update PR"
description: "Create or Update a from one branch to another."
author: "Maykin Media"

inputs:
branch-name:
description: 'Name of the Update Branch'
required: true
commit-message:
description: 'Message of the update commit'
required: true
pr-title:
description: 'Title of the PR'
required: true

runs:
using: "composite"
steps:
- name: Set up Git credentials
shell: bash
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Set GitHub Path
run: echo "$GITHUB_ACTION_PATH/bin" >> $GITHUB_PATH
shell: bash
env:
GITHUB_ACTION_PATH: ${{ github.action_path }} # location of action.yml
- name: Run Script
shell: bash
run: create-update-pr.sh
env:
BRANCH_NAME: ${{ inputs.branch-name }}
BASE_BRANCH: ${{github.ref_name}}
COMMIT_MESSAGE: ${{ inputs.commit-message }}
PR_TITLE: ${{ inputs.pr-title }}
ACTION_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
RUN_ID: ${{ github.run_id }}
GH_TOKEN: ${{ github.token }}
75 changes: 75 additions & 0 deletions actions/create-update-pr/bin/create-update-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

if ! [[ $BRANCH_NAME ]]; then
echo "BRANCH_NAME variable is required"
exit 1
fi
if ! [[ $BASE_BRANCH ]]; then
echo "BASE_BRANCH variable is required"
exit 1
fi
if ! [[ $COMMIT_MESSAGE ]]; then
echo "COMMIT_MESSAGE variable is required"
exit 1
fi
if ! [[ $PR_TITLE ]]; then
echo "PR_TITLE variable is required"
exit 1
fi
if ! [[ $ACTION_URL ]]; then
echo "ACTION_URL variable is required"
exit 1
fi
if ! [[ $RUN_ID ]]; then
echo "RUN_ID variable is required"
exit 1
fi

# Fetch
git fetch

# Force Create Branch
git switch --force-create "$BRANCH_NAME"

printf "\nShow Status:"
git status


printf "\nCommit Any Changes"
if ! git diff --exit-code --quiet
then
echo "Commiting Files"
git add --all
git commit --message="$COMMIT_MESSAGE"
else
echo "No files to commit"
fi

printf "\nCheck if Changes have been made"
if ! git ls-remote --exit-code --quiet --heads origin refs/heads/"$BRANCH_NAME"
then
echo "No Remote Found, creating"
git push --set-upstream origin "$BRANCH_NAME"

elif ! git diff --exit-code --quiet "$BRANCH_NAME"..origin/"$BRANCH_NAME"
then
echo "Changes detected between local and remote. Pushing changes."
git push --force-with-lease --set-upstream origin "$BRANCH_NAME"
else
echo "No Changes detected"
fi

# Create or Update PR
printf "\nCreate or Update PR"
if gh pr list --head "$BRANCH_NAME" --json title | grep -q '\"title\"'
then
echo "PR found. Adding comment."
gh pr comment "$BRANCH_NAME" --body "Updated by github action [$RUN_ID]($ACTION_URL)"
else
echo "Creating new PR"
gh pr create --base "$BASE_BRANCH" \
--title "$PR_TITLE" \
--body "Generated with github action [$RUN_ID]($ACTION_URL)"
fi

exit 0