Skip to content

Update Mistral's openapi-original.yaml #35

Update Mistral's openapi-original.yaml

Update Mistral's openapi-original.yaml #35

name: Update Mistral's openapi-original.yaml
on:
schedule:
# every Sunday at 21:00 (9 PM) UTC
- cron: "0 21 * * 0"
# This allows manual triggering of the workflow
workflow_dispatch:
jobs:
run:
runs-on: ubuntu-latest
env:
BRANCH_NAME: "bot/update-openapi-specs" # Define the branch name as an environment variable
steps:
- name: Checkout
uses: actions/checkout@v4
- name: ⚙️ Setup Dart
uses: dart-lang/setup-dart@v1
with:
sdk: "3.2.3"
- name: Install dependencies
run: dart pub get
- name: Configure Git User (Bot)
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
- name: Update Branch
run: |
# Fetch latest references from the remote
git fetch --prune origin
# Check if the branch already exists in the remote
if git show-ref --verify --quiet "refs/remotes/origin/$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME already exists in the remote repository."
git checkout $BRANCH_NAME
else
echo "Branch $BRANCH_NAME does not exist in the remote repository. Creating a new branch..."
git checkout -b $BRANCH_NAME
fi
- name: Update openapi_specs/openapi-original.yaml
run: dart run openapi_specs/update_openapi_spec.dart
- name: Check openapi_specs/openapi-original.yaml has changed
id: check_changes
run: |
if git diff --exit-code openapi_specs/openapi-original.yaml; then
echo "No changes detected in openapi-original.yaml"
echo "SPEC_CHANGED=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in openapi-original.yaml"
echo "SPEC_CHANGED=true" >> $GITHUB_OUTPUT
fi
- name: Debug SPEC_CHANGED value
run: echo "SPEC_CHANGED is set to ${{ steps.check_changes.outputs.SPEC_CHANGED }}"
- name: No changes detected
if: ${{ steps.check_changes.outputs.SPEC_CHANGED == 'false' }}
run: echo "No changes detected in openapi-original.yaml"
- name: Commit Changes
if: ${{ steps.check_changes.outputs.SPEC_CHANGED == 'true' }}
run: |
# Commit changes
git add openapi_specs/openapi-original.yaml
git commit -m "Update OpenAPI Specs for Run ${{ github.run_id }}"
- name: Push Changes
if: ${{ steps.check_changes.outputs.SPEC_CHANGED == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub Actions
run: |
# Push the branch to the repository
git push -u origin $BRANCH_NAME
# Get the PR number if it exists
PR_NUMBER=$(gh pr list --head $BRANCH_NAME --state open --json number --jq '.[].number')
JOB_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
PR_TITLE="Automatic OpenAPI Specs update"
PR_BODY="Automatic openapi-original.yaml change detected. This PR updates the OpenAPI specs triggered by job [${{ github.run_id }}]($JOB_URL)."
# If PR exists, update it, otherwise create a new one
if [ -n "$PR_NUMBER" ]; then
echo "Pull request $PR_NUMBER already exists for branch $BRANCH_NAME. Updating the PR..."
gh pr edit "$PR_NUMBER" --title "$PR_TITLE" --body "$PR_BODY"
else
echo "Creating a new pull request for branch $BRANCH_NAME..."
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head $BRANCH_NAME
fi