Publish new version #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish new version | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'The version to release' | |
| required: false | |
| default: "" | |
| mfd-tag: | |
| description: 'The MFD tag to use for API docs' | |
| required: false | |
| default: "" | |
| permissions: | |
| contents: write | |
| jobs: | |
| generate-api-docs: | |
| name: Update version and build python module | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: arn:aws:iam::048781935247:role/GH-APP-OIDC-CBMyFrontDesk | |
| aws-region: us-west-2 | |
| - name: Get app private key from SSM and apply mask | |
| id: app-private-key | |
| shell: bash | |
| run: | | |
| aws ssm get-parameter --name /github/app/CBMyFrontDesk/private-key --output text --with-decryption --query Parameter.Value > private.key | |
| { | |
| echo "key<<EOF" | |
| cat private.key | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| while read -r line; | |
| do | |
| if [[ -n "${line}" ]]; then | |
| echo "::add-mask::${line}" | |
| fi | |
| done < private.key | |
| rm private.key | |
| - name: Generate token | |
| id: generate-token | |
| uses: tibdex/github-app-token@v2 | |
| with: | |
| app_id: 391670 | |
| private_key: ${{ steps.app-private-key.outputs.key }} | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.generate-token.outputs.token }} | |
| - name: Get API docs | |
| env: | |
| GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} | |
| run: | | |
| MFD_TAG='${{ inputs.mfd-tag }}' | |
| if [[ -z "${MFD_TAG}" ]]; then | |
| MFD_TAG=$(gh api /repos/cloudbeds/mfd/releases/latest | jq -r '.tag_name') | |
| fi | |
| echo "Latest MFD tag: $MFD_TAG" | |
| gh api /repos/cloudbeds/mfd/tarball/$MFD_TAG | tar --strip-components=1 --wildcards -zxf - '*/public_accessa/api' | |
| - name: Get next version | |
| run: | | |
| if [ -n "${{ inputs.version }}" ]; then | |
| echo "next_version=${{ inputs.version }}" >> $GITHUB_ENV | |
| echo "Version provided: ${{ inputs.version }}" | |
| else | |
| current_version=$(cat VERSION) | |
| echo "Current version: $current_version" | |
| IFS='.' read -r major minor patch <<< "$current_version" | |
| minor=$((minor + 1)) | |
| next_version="$major.$minor.$patch" | |
| echo "Next version: $next_version" | |
| echo "next_version=$next_version" >> $GITHUB_ENV | |
| fi | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 23 | |
| distribution: corretto | |
| - name: Install OpenAPI generator | |
| run: | | |
| OPENAPI_GENERATOR_VERSION=$(cat .openapi-generator/VERSION) | |
| curl -s https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/$OPENAPI_GENERATOR_VERSION/openapi-generator-cli-$OPENAPI_GENERATOR_VERSION.jar -o openapi-generator-cli.jar | |
| - name: Bump version in VERSION and openapitools.json | |
| run: | | |
| echo ${{ env.next_version }} > VERSION | |
| sed -i 's/"packageVersion": "[0-9]*\.[0-9]*\.[0-9]*"/"packageVersion": "${{ env.next_version }}"/' openapitools.json | |
| - name: Generate API docs | |
| run: | | |
| find $(cat PACKAGE) -mindepth 1 ! -name 'py.typed' -delete | |
| java -jar openapi-generator-cli.jar generate -c openapitools.json | |
| - name: Git Setup | |
| if: inputs.version == '' | |
| run: | | |
| git config --global user.name "github-actions" | |
| git config --global user.email "[email protected]" | |
| - name: Update repository with new version | |
| if: inputs.version == '' | |
| run: | | |
| git add VERSION openapitools.json $(cat PACKAGE) README.md .openapi-generator/FILES | |
| git commit -m "Bump version to ${{ env.next_version }}" | |
| git push | |
| build-release: | |
| name: Build release distribution | |
| runs-on: ubuntu-latest | |
| needs: generate-api-docs | |
| env: | |
| UV_VERSION: 0.5.21 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version-file: .python-version | |
| - name: Build release distributions | |
| run: | | |
| pip install "uv==${{ env.UV_VERSION }}" | |
| uv sync --locked --no-dev | |
| uv build | |
| - name: Upload distributions | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-dists | |
| path: dist/ | |
| - name: Create Release | |
| if: inputs.version == '' | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: >- | |
| gh release create $(cat VERSION) | |
| --notes $(cat VERSION) | |
| --target ${{ github.ref_name }} | |
| --title $(cat VERSION) | |
| pypi-publish: | |
| name: Publish to PyPI | |
| runs-on: ubuntu-latest | |
| needs: build-release | |
| environment: | |
| name: pypi | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Retrieve release distributions | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: release-dists | |
| path: dist/ | |
| - name: Publish release distributions to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ |