Skip to content

Create generate-and-release.yaml #9

Create generate-and-release.yaml

Create generate-and-release.yaml #9

Workflow file for this run

name: Update SDK and release
on:
push:
branches:
- test-workflow
workflow_dispatch:
schedule:
- cron: '0 * * * *' # At :00 every hour
jobs:
check-and-update-sdk:
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.check_changes.outputs.changes }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch latest OpenAPI definition
run: |
curl https://openapi-v2.exoscale.com/source.yaml > sdk/api/openapi.yaml
- name: Check for changes in OpenAPI definition
id: check_changes
run: |
if ! git diff --exit-code sdk/api/openapi.yaml; then
echo "changes=true" >> $GITHUB_ENV
else
echo "changes=false" >> $GITHUB_ENV
fi
shell: bash
update-version:
runs-on: ubuntu-latest
needs: check-and-update-sdk
if: needs.check-and-update-sdk.outputs.changes == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Increment artifactVersion
id: version
run: |
current_version=$(xmlstarlet sel -t -v "//artifactVersion" pom.xml)
IFS='.-' read -r -a parts <<< "$current_version"
new_patch=$((parts[2] + 1))
new_version="${parts[0]}.${parts[1]}.$new_patch-${parts[3]}"
xmlstarlet ed --inplace --update "//artifactVersion" --value "$new_version" pom.xml
echo "new_version=$new_version" >> $GITHUB_ENV
shell: bash
- name: Generate SDK sources
run: mvn generate-sources
- name: Compile and install SDK
run: |
cd sdk
mvn install
- name: Commit changes
run: |
git config user.name "Automated"
git config user.email "[email protected]"
git add sdk/api/openapi.yaml pom.xml
git commit -m "Update SDK to version ${new_version}"
git push origin main
shell: bash
- name: Create release tag
run: |
git tag -a v${new_version} -m "Release ${new_version}"
git push origin v${new_version}
shell: bash