|
| 1 | +name: Publish new version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'The version to release' |
| 8 | + required: false |
| 9 | + default: "" |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + generate-api-docs: |
| 16 | + name: Update version and build python module |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + id-token: write |
| 20 | + contents: read |
| 21 | + steps: |
| 22 | + - name: Configure AWS credentials |
| 23 | + uses: aws-actions/configure-aws-credentials@v4 |
| 24 | + with: |
| 25 | + role-to-assume: arn:aws:iam::048781935247:role/GH-APP-OIDC-CBMyFrontDesk |
| 26 | + aws-region: us-west-2 |
| 27 | + |
| 28 | + - name: Get app private key from SSM and apply mask |
| 29 | + id: app-private-key |
| 30 | + shell: bash |
| 31 | + run: | |
| 32 | + aws ssm get-parameter --name /github/app/CBMyFrontDesk/private-key --output text --with-decryption --query Parameter.Value > private.key |
| 33 | + { |
| 34 | + echo "key<<EOF" |
| 35 | + cat private.key |
| 36 | + echo "EOF" |
| 37 | + } >> $GITHUB_OUTPUT |
| 38 | + while read -r line; |
| 39 | + do |
| 40 | + if [[ -n "${line}" ]]; then |
| 41 | + echo "::add-mask::${line}" |
| 42 | + fi |
| 43 | + done < private.key |
| 44 | + rm private.key |
| 45 | +
|
| 46 | + - name: Generate token |
| 47 | + id: generate-token |
| 48 | + uses: tibdex/github-app-token@v2 |
| 49 | + with: |
| 50 | + app_id: 391670 |
| 51 | + private_key: ${{ steps.app-private-key.outputs.key }} |
| 52 | + |
| 53 | + - name: Checkout code |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + token: ${{ steps.generate-token.outputs.token }} |
| 57 | + |
| 58 | + - name: Get API docs |
| 59 | + run: | |
| 60 | + curl -sL -o accounting-openapi.yaml https://api.us1.cloudbeds.com/accounting/accounting-openapi.yaml |
| 61 | +
|
| 62 | + - name: Get next version |
| 63 | + run: | |
| 64 | + if [ -n "${{ inputs.version }}" ]; then |
| 65 | + echo "next_version=${{ inputs.version }}" >> $GITHUB_ENV |
| 66 | + echo "Version provided: ${{ inputs.version }}" |
| 67 | + else |
| 68 | + current_version=$(cat VERSION) |
| 69 | + echo "Current version: $current_version" |
| 70 | +
|
| 71 | + IFS='.' read -r major minor patch <<< "$current_version" |
| 72 | + minor=$((minor + 1)) |
| 73 | + next_version="$major.$minor.$patch" |
| 74 | + echo "Next version: $next_version" |
| 75 | +
|
| 76 | + echo "next_version=$next_version" >> $GITHUB_ENV |
| 77 | + fi |
| 78 | +
|
| 79 | + - name: Setup Java |
| 80 | + uses: actions/setup-java@v4 |
| 81 | + with: |
| 82 | + java-version: 23 |
| 83 | + distribution: corretto |
| 84 | + |
| 85 | + - name: Install OpenAPI generator |
| 86 | + run: | |
| 87 | + OPENAPI_GENERATOR_VERSION=$(cat .openapi-generator/VERSION) |
| 88 | + 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 |
| 89 | +
|
| 90 | + - name: Bump version in VERSION and openapitools.json |
| 91 | + run: | |
| 92 | + echo ${{ env.next_version }} > VERSION |
| 93 | + sed -i 's/"packageVersion": "[0-9]*\.[0-9]*\.[0-9]*"/"packageVersion": "${{ env.next_version }}"/' openapitools.json |
| 94 | +
|
| 95 | + - name: Generate API docs |
| 96 | + run: | |
| 97 | + find $(cat PACKAGE) -mindepth 1 ! -name 'py.typed' -delete |
| 98 | + java -jar openapi-generator-cli.jar generate -c openapitools.json |
| 99 | +
|
| 100 | + - name: Git Setup |
| 101 | + if: inputs.version == '' |
| 102 | + run: | |
| 103 | + git config --global user.name "github-actions" |
| 104 | + git config --global user.email "[email protected]" |
| 105 | +
|
| 106 | + - name: Update repository with new version |
| 107 | + if: inputs.version == '' |
| 108 | + run: | |
| 109 | + git add VERSION openapitools.json $(cat PACKAGE) README.md .openapi-generator/FILES |
| 110 | + git commit -m "Bump version to ${{ env.next_version }}" |
| 111 | + git push |
| 112 | +
|
| 113 | + build-release: |
| 114 | + name: Build release distribution |
| 115 | + runs-on: ubuntu-latest |
| 116 | + needs: generate-api-docs |
| 117 | + env: |
| 118 | + UV_VERSION: 0.5.31 |
| 119 | + steps: |
| 120 | + - name: Checkout code |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + ref: ${{ github.ref_name }} |
| 124 | + |
| 125 | + - name: Setup Python |
| 126 | + uses: actions/setup-python@v5 |
| 127 | + with: |
| 128 | + python-version-file: .python-version |
| 129 | + |
| 130 | + - name: Build release distributions |
| 131 | + run: | |
| 132 | + pip install "uv==${{ env.UV_VERSION }}" |
| 133 | + uv sync --locked --no-dev |
| 134 | + uv build |
| 135 | +
|
| 136 | + - name: Upload distributions |
| 137 | + uses: actions/upload-artifact@v4 |
| 138 | + with: |
| 139 | + name: release-dists |
| 140 | + path: dist/ |
| 141 | + |
| 142 | + - name: Create Release |
| 143 | + if: inputs.version == '' |
| 144 | + env: |
| 145 | + GITHUB_TOKEN: ${{ github.token }} |
| 146 | + run: >- |
| 147 | + gh release create $(cat VERSION) |
| 148 | + --notes $(cat VERSION) |
| 149 | + --target ${{ github.ref_name }} |
| 150 | + --title $(cat VERSION) |
| 151 | +
|
| 152 | + pypi-publish: |
| 153 | + name: Publish to PyPI |
| 154 | + runs-on: ubuntu-latest |
| 155 | + needs: build-release |
| 156 | + environment: |
| 157 | + name: pypi |
| 158 | + permissions: |
| 159 | + id-token: write |
| 160 | + steps: |
| 161 | + - name: Retrieve release distributions |
| 162 | + uses: actions/download-artifact@v4 |
| 163 | + with: |
| 164 | + name: release-dists |
| 165 | + path: dist/ |
| 166 | + |
| 167 | + - name: Publish release distributions to PyPI |
| 168 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 169 | + with: |
| 170 | + packages-dir: dist/ |
0 commit comments