Skip to content

Weekly autoupdate OAS for Preview #48

Weekly autoupdate OAS for Preview

Weekly autoupdate OAS for Preview #48

name: Weekly autoupdate OAS for Preview
on:
schedule:
- cron: "0 16 * * 1" # At 16:00 on every Monday
workflow_dispatch:
permissions:
actions: write
contents: write
pull-requests: write
jobs:
update-oas:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.9"
- name: Update OAS
run: python scripts/update_specification_files.py -s api-specifications -g https://api.criteo.com -r Preview
- name: Check for changes
id: check_changes
run: |
git add *
if git diff --cached --exit-code; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Close any existing pull request opened by "update-oas-bot"
run: gh pr list --state=open --label="oas auto-update" --json=number --jq '.[] | join("")' | xargs -I{} gh pr close --delete-branch {}
env:
GH_TOKEN: ${{ github.token }}
- name: Create new branch and commit files
if: steps.check_changes.outputs.has_changes == 'true'
run: |
git config --global user.name "update-oas-bot"
git config --global user.email "update-oas-bot]@users.noreply.github.com"
git checkout -b update-oas-$(date --rfc-3339=date)
git commit -m "Update OAS for Preview"
git push origin update-oas-$(date --rfc-3339=date)
- name: Create pull request on main
if: steps.check_changes.outputs.has_changes == 'true'
run: gh pr create --base main --head update-oas-$(date --rfc-3339=date) --title "Update OAS for Preview" --body "Auto-update of OAS for Preview. This PR will be automatically closed during the next automatic update" --label "oas auto-update"
env:
GH_TOKEN: ${{ github.token }}
- name: Send success notification
if: ${{ success() && steps.check_changes.outputs.has_changes == 'true' }}
uses: slackapi/[email protected]
with:
webhook: ${{ secrets.SLACK_WEBHOOK }}
webhook-type: incoming-webhook
payload: |
status: "${{ job.status }}"
channel: "C02J0CWR789"
username: "sdk-generation-bot"
text: "Autoupdate of OAS in Preview. Please check <https://github.com/criteo/criteo-api-sdk-generator/pulls|opened PRs> to validate the change, and publish the artifacts <!subteam^S07BSM1MDN2>. Autoupdate of OAS in preview runs weekly on Monday."
icon_emoji: ":bell:"
- name: Send failure notification
if: ${{ failure() }}
uses: slackapi/[email protected]
with:
webhook: ${{ secrets.SLACK_WEBHOOK }}
webhook-type: incoming-webhook
payload: |
status: "${{ job.status }}"
channel: "C02J0CWR789"
username: "sdk-generation-bot"
text: "Autoupdate of OAS in Preview failure, check <https://github.com/criteo/criteo-api-sdk-generator/actions|action results>."
icon_emoji: ":x:"