Skip to content

.github/workflows/generate.yml #485

.github/workflows/generate.yml

.github/workflows/generate.yml #485

Workflow file for this run

on:
schedule:
- cron: '0 19 * * *'
workflow_dispatch:
jobs:
generate:
runs-on: ubuntu-22.04
strategy:
matrix:
source:
- url: https://api.mittwald.de/v2/openapi.json
branch: master
tag: "true"
- url: https://developer.mittwald.de/specs/openapi-v2-dev.json
branch: next
tag: "false"
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Checkout client to subdirectory
uses: actions/checkout@v3
with:
repository: 'mittwald/api-client-php'
ref: ${{ matrix.source.branch }}
path: '.work'
token: ${{ secrets.MACHINE_USER_TOKEN }}
fetch-tags: true
fetch-depth: "0"
- name: Purge previous generated code
run: rm -rf .work/src/Generated
- name: Generate client
run: php ./cmd/generate.php generate ${{ matrix.source.url }} ./.work -v
- name: Run code formatting on generated client
working-directory: .work
run: |
composer install --prefer-dist --no-progress --no-suggest
composer run format
composer run check
- run: git status
working-directory: .work
- name: Create and push commit
working-directory: .work
env:
GH_TOKEN: ${{ secrets.MACHINE_USER_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
set -ex
if [[ $(git status --porcelain | wc -l) -eq 0 ]]; then
echo "No changes detected, skipping commit."
exit 0
fi
git config --global user.name "mittwald-machine"
git config --global user.email "[email protected]"
../cmd/generate.php generate-commit-message --from-uncommitted > commit-message.txt
git add src
git commit -F commit-message.txt
git remote add publish "https://mittwald-machine:${{ secrets.MACHINE_USER_TOKEN }}@github.com/mittwald/api-client-php.git"
if [[ "${{ matrix.source.tag }}" == "true" ]] ; then
last_tag=$(git describe --abbrev=0 --tags)
new_tag=$(php ../cmd/generate.php version "${last_tag}")
git tag -m "Release ${new_tag}" ${new_tag}
git push publish
git push --tags publish
../cmd/generate.php generate-release-notes > release-notes.md
gh release create --verify-tag --notes-file release-notes.md --latest -R mittwald/api-client-php "${new_tag}"
else
git push publish
fi