|
| 1 | +name: Publish new version |
| 2 | + |
| 3 | +env: |
| 4 | + UV_VERSION: 0.5.20 |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'The version to release' |
| 11 | + required: false |
| 12 | + default: "" |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + release-build: |
| 19 | + name: Update version and build python module |
| 20 | + runs-on: default |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Get API docs |
| 26 | + env: |
| 27 | + GITHUB_TOKEN: ${{ github.token }} |
| 28 | + run: | |
| 29 | + MFD_TAG=$(gh api /repos/cloudbeds/mfd/releases/latest | jq -r '.tag_name') |
| 30 | + echo "Latest MFD tag: $MFD_TAG" |
| 31 | + gh api /repos/cloudbeds/mfd/tarball/$MFD_TAG | tar --strip-components=1 --wildcards -zxf - '*/public_accessa' |
| 32 | +
|
| 33 | + - name: Setup NPM |
| 34 | + uses: actions/setup-node@v2 |
| 35 | + with: |
| 36 | + node-version: '22' |
| 37 | + |
| 38 | + - name: Generate API docs |
| 39 | + run: | |
| 40 | + npm install @openapitools/openapi-generator-cli -g |
| 41 | + openapi-generator-cli version-manager $(cat .openapi-generator/VERSION) |
| 42 | + # TODO - change file name based on branch (main or release/v1) |
| 43 | + openapi-generator-cli generate -i public_accessa/api/v2/docs/cb-v2-openapi-3.0.0.yaml -c openapitools.json |
| 44 | + rm -rf public_accessa |
| 45 | +
|
| 46 | + - name: Get next version |
| 47 | + id: get_next_version |
| 48 | + run: | |
| 49 | + if [ -n "${{ github.event.inputs.version }}" ]; then |
| 50 | + echo "next_version=${{ github.event.inputs.version }}" >> $GITHUB_ENV |
| 51 | + echo "Version provided: ${{ github.event.inputs.version }}" |
| 52 | + else |
| 53 | + current_version=$(cat VERSION) |
| 54 | + echo "Current version: $current_version" |
| 55 | + |
| 56 | + IFS='.' read -r major minor patch <<< "$current_version" |
| 57 | + minor=$((minor + 1)) |
| 58 | + next_version="$major.$minor.$patch" |
| 59 | + echo "Next version: $next_version" |
| 60 | + |
| 61 | + echo "next_version=$next_version" >> $GITHUB_ENV |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Bump version in files |
| 65 | + if: github.event.inputs.version == '' |
| 66 | + run: | |
| 67 | + echo ${{ env.next_version }} > VERSION |
| 68 | + sed -i 's/"packageVersion": "[0-9]*\.[0-9]*\.[0-9]*"/"packageVersion": "${{ env.next_version }}"/' openapitools.json |
| 69 | + git config --global user.name "github-actions" |
| 70 | + git config --global user.email "[email protected]" |
| 71 | + git add VERSION openapitools.json |
| 72 | + git commit -m "Bump version to ${{ env.next_version }}" |
| 73 | + git push |
| 74 | +
|
| 75 | + - name: Setup Python |
| 76 | + uses: actions/setup-python@v5 |
| 77 | + with: |
| 78 | + python-version-file: .python-version |
| 79 | + |
| 80 | + - name: Build release distributions |
| 81 | + run: | |
| 82 | + pip install "uv==$UV_VERSION" |
| 83 | + uv sync --locked --no-dev |
| 84 | + uv build |
| 85 | +
|
| 86 | + - name: Upload distributions |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: release-dists |
| 90 | + path: dist/ |
| 91 | + |
| 92 | + - name: Create Release |
| 93 | + id: create_release |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ github.token }} |
| 96 | + run: >- |
| 97 | + gh release create '${{ env.next_version }}' |
| 98 | + --notes '${{ env.next_version }}' |
| 99 | + --target '${{ github.ref_name }}' |
| 100 | + --title '${{ env.next_version }}' |
| 101 | +
|
| 102 | + pypi-publish: |
| 103 | + name: Publish to PyPI |
| 104 | + runs-on: default |
| 105 | + needs: |
| 106 | + - release-build |
| 107 | + environment: |
| 108 | + name: pypi |
| 109 | + permissions: |
| 110 | + id-token: write |
| 111 | + steps: |
| 112 | + - name: Retrieve release distributions |
| 113 | + uses: actions/download-artifact@v4 |
| 114 | + with: |
| 115 | + name: release-dists |
| 116 | + path: dist/ |
| 117 | + |
| 118 | + - name: Publish release distributions to PyPI |
| 119 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 120 | + with: |
| 121 | + packages-dir: dist/ |
0 commit comments