Skip to content

Code generation

Code generation #15

Workflow file for this run

name: Code generation
on:
workflow_dispatch: {}
schedule:
- cron: '0 19 * * *'
permissions:
contents: write
jobs:
generate:
runs-on: ubuntu-24.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@v4
with:
ref: ${{ matrix.source.branch }}
fetch-depth: 0
fetch-tags: true
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Install dependencies
run: |
go install github.com/mittwald/api-client-go-builder/cmd/mittwald-go-client-builder@latest
go install golang.org/x/tools/cmd/goimports@latest
- name: Generate code for v2 API
run: |
rm -rf mittwaldv2/generated
mittwald-go-client-builder generate ${{ matrix.source.url }} ./mittwaldv2/generated mittwaldv2
goimports -w mittwaldv2/generated
- name: Summarise git status
run: git status
- name: Verify generated code
run: |
go vet -v ./...
go test -v ./...
- name: Create and push commit
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 mittwaldv2
git commit -m 'chore: update auto-generated code'
if [[ "${{ matrix.source.tag }}" == "true" ]] ; then
last_tag=$(git describe --abbrev=0 --tags)
new_tag=$(mittwald-go-client-builder next-version "${last_tag}")
git tag -m "Release ${new_tag}" ${new_tag}
git push
git push --tags
else
git push
fi