|
| 1 | +name: Release GQLAlchemy |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version to release" |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + build_docs: |
| 11 | + description: "Build docs" |
| 12 | + required: false |
| 13 | + type: boolean |
| 14 | + default: false |
| 15 | + publish_packages: |
| 16 | + description: "Publish packages" |
| 17 | + required: false |
| 18 | + type: boolean |
| 19 | + default: false |
| 20 | + test: |
| 21 | + description: "Test" |
| 22 | + required: false |
| 23 | + type: boolean |
| 24 | + default: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + create-release-branch: |
| 28 | + name: Create Release Branch |
| 29 | + runs-on: ["ubuntu-latest"] |
| 30 | + outputs: |
| 31 | + release_branch: ${{ steps.create_release_branch.outputs.RELEASE_BRANCH }} |
| 32 | + steps: |
| 33 | + - name: Checkout Code |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 # Fetch all history for changelog generation |
| 37 | + |
| 38 | + - name: Configure Git |
| 39 | + run: | |
| 40 | + git config user.name "github-actions" |
| 41 | + git config user.email "[email protected]" |
| 42 | +
|
| 43 | + - name: Create Release Branch |
| 44 | + id: create_release_branch |
| 45 | + run: | |
| 46 | + # Parse version and create branch name |
| 47 | + if [[ "${{ inputs.version }}" =~ ^([0-9]+\.[0-9]+)\.0$ ]]; then |
| 48 | + # If version ends in .0, use shortened form (e.g., 1.2.0 -> release/1.2) |
| 49 | + BRANCH_NAME="release/${BASH_REMATCH[1]}" |
| 50 | + else |
| 51 | + # Otherwise use full version (e.g., 1.2.1 -> release/1.2.1) |
| 52 | + BRANCH_NAME="release/${{ inputs.version }}" |
| 53 | + fi |
| 54 | + |
| 55 | + # Check if branch exists |
| 56 | + if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME" || git show-ref --verify --quiet "refs/remotes/origin/$BRANCH_NAME"; then |
| 57 | + echo "::error::Branch $BRANCH_NAME already exists!" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + git checkout -b "$BRANCH_NAME" |
| 61 | + |
| 62 | + # Export branch name for later steps |
| 63 | + echo "RELEASE_BRANCH=$BRANCH_NAME" >> $GITHUB_ENV |
| 64 | + echo "RELEASE_BRANCH=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 65 | +
|
| 66 | + - name: Set version |
| 67 | + run: | |
| 68 | + sed -i "s/^version = .*/version = \"${{ inputs.version }}\"/" pyproject.toml |
| 69 | +
|
| 70 | + - name: Commit version |
| 71 | + run: | |
| 72 | + git add pyproject.toml |
| 73 | + git commit -m "Release v${{ inputs.version }}" |
| 74 | + git push origin "$RELEASE_BRANCH" |
| 75 | +
|
| 76 | + - name: Create Release Tag |
| 77 | + run: | |
| 78 | + git tag -a v${{ inputs.version }} -m "Release v${{ inputs.version }}" |
| 79 | + git push origin v${{ inputs.version }} |
| 80 | +
|
| 81 | + - name: Create Release Pull Request |
| 82 | + run: | |
| 83 | + gh pr create --base main --head "$RELEASE_BRANCH" --title "Release v${{ inputs.version }}" --body "Release v${{ inputs.version }}" |
| 84 | +
|
| 85 | + build-packages: |
| 86 | + needs: create-release-branch |
| 87 | + name: Build Packages |
| 88 | + uses: ./.github/workflows/build-packages.yml |
| 89 | + with: |
| 90 | + version: ${{ inputs.version }} |
| 91 | + branch: ${{ needs.create-release-branch.outputs.RELEASE_BRANCH }} |
| 92 | + secrets: inherit |
| 93 | + |
| 94 | + publish-packages: |
| 95 | + needs: [create-release-branch, build-packages] |
| 96 | + name: Publish Packages |
| 97 | + if: ${{ inputs.publish_packages == true }} |
| 98 | + runs-on: ["ubuntu-latest"] |
| 99 | + steps: |
| 100 | + - name: Checkout Code |
| 101 | + uses: actions/checkout@v4 |
| 102 | + with: |
| 103 | + ref: ${{ needs.create-release-branch.outputs.RELEASE_BRANCH }} |
| 104 | + fetch-depth: 0 # Fetch all history for changelog generation |
| 105 | + |
| 106 | + - name: Download packages |
| 107 | + uses: actions/download-artifact@v4 |
| 108 | + with: |
| 109 | + name: packages |
| 110 | + path: dist |
| 111 | + |
| 112 | + - name: Publish packages |
| 113 | + if: ${{ inputs.test == false }} |
| 114 | + run: | |
| 115 | + poetry publish --username ${{ secrets.PYPI_USERNAME }} --password ${{ secrets.PYPI_PASSWORD }} |
| 116 | + |
| 117 | + - name: Publish Packages (Test PyPI) |
| 118 | + if: ${{ inputs.test == true }} |
| 119 | + run: | |
| 120 | + poetry config repositories.testpypi https://test.pypi.org/legacy/ |
| 121 | + poetry publish --username ${{ secrets.TESTPYPI_USERNAME }} --password ${{ secrets.TESTPYPI_PASSWORD }} --repository testpypi |
| 122 | +
|
| 123 | + build-docs: |
| 124 | + needs: [create-release-branch, build-packages, publish-packages] |
| 125 | + name: Build Docs |
| 126 | + uses: ./.github/workflows/build-docs.yml |
| 127 | + if: ${{ inputs.build_docs == true }} |
| 128 | + with: |
| 129 | + publish: ${{ inputs.test == false }} |
| 130 | + branch: ${{ needs.create-release-branch.outputs.RELEASE_BRANCH }} |
| 131 | + secrets: inherit |
| 132 | + |
| 133 | + create-github-release: |
| 134 | + needs: [create-release-branch, build-packages, publish-packages, build-docs] |
| 135 | + name: Create GitHub Release |
| 136 | + uses: ./.github/workflows/create-github-release.yml |
| 137 | + with: |
| 138 | + version: ${{ inputs.version }} |
| 139 | + branch: ${{ needs.create-release-branch.outputs.RELEASE_BRANCH }} |
| 140 | + secrets: inherit |
0 commit comments