Skip to content

.github/workflows/generate.yml #129

.github/workflows/generate.yml

.github/workflows/generate.yml #129

Workflow file for this run

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
generate:
runs-on: ubuntu-22.04
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'
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 https://api.mittwald.de/openapi ./.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 }}
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]"
git add src
git commit -m "Update generated client"
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 remote add publish "https://mittwald-macine:${{ secrets.MACHINE_USER_TOKEN }}@github.com/mittwald/api-client-php.git"
git push publish
git push --tags publish
gh release create --verify-tag --generate-notes --latest -R mittwald/api-client-php "${new_tag}"