|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + required: true |
| 8 | + default: 'x.y.z' |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + checks: |
| 16 | + name: Version check |
| 17 | + runs-on: ubuntu-24.04 |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + id: repo |
| 21 | + uses: actions/checkout@v5.0.0 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5.6.0 |
| 25 | + with: |
| 26 | + python-version: 3.13 |
| 27 | + |
| 28 | + - name: Get latest release from pip |
| 29 | + id: latestreleased |
| 30 | + run: | |
| 31 | + PREVIOUS_VERSION=$(python -m pip index versions CodeEntropy | grep "CodeEntropy" | cut -d "(" -f2 | cut -d ")" -f1) |
| 32 | + echo "pip_tag=$PREVIOUS_VERSION" >> "$GITHUB_OUTPUT" |
| 33 | + echo $PREVIOUS_VERSION |
| 34 | +
|
| 35 | + - name: version comparison |
| 36 | + id: compare |
| 37 | + run: | |
| 38 | + pip3 install semver |
| 39 | + output=$(pysemver compare ${{ steps.latestreleased.outputs.pip_tag }} ${{ github.event.inputs.version }}) |
| 40 | + if [ $output -ge 0 ]; then exit 1; fi |
| 41 | +
|
| 42 | + version: |
| 43 | + name: prepare ${{ github.event.inputs.version }} |
| 44 | + needs: checks |
| 45 | + runs-on: ubuntu-24.04 |
| 46 | + steps: |
| 47 | + |
| 48 | + - name: checkout |
| 49 | + uses: actions/checkout@v5.0.0 |
| 50 | + |
| 51 | + - name: Change version in repo |
| 52 | + run: sed -i "s/__version__ =.*/__version__ = \"${{ github.event.inputs.version }}\"/g" CodeEntropy/__init__.py |
| 53 | + |
| 54 | + - name: send PR |
| 55 | + id: pr_id |
| 56 | + uses: peter-evans/create-pull-request@v7.0.8 |
| 57 | + with: |
| 58 | + commit-message: Update version to ${{ github.event.inputs.version }} |
| 59 | + branch: version-update |
| 60 | + title: "Update to version ${{ github.event.inputs.version }}" |
| 61 | + body: | |
| 62 | + Update version |
| 63 | + - Update the __init__.py with new release |
| 64 | + - Auto-generated by [CI] |
| 65 | + base: main |
| 66 | + signoff: false |
| 67 | + draft: false |
| 68 | + |
| 69 | + - name: merge PR |
| 70 | + run: gh pr merge --merge --delete-branch --auto "${{ steps.pr_id.outputs.pull-request-number }}" |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + |
| 74 | + tag: |
| 75 | + name: tag release |
| 76 | + needs: version |
| 77 | + runs-on: ubuntu-24.04 |
| 78 | + steps: |
| 79 | + - name: Checkout repository |
| 80 | + uses: actions/checkout@v5.0.0 |
| 81 | + with: |
| 82 | + ref: main |
| 83 | + |
| 84 | + - name: tag v${{ github.event.inputs.version }} |
| 85 | + run: | |
| 86 | + git config user.name github-actions |
| 87 | + git config user.email github-actions@github.com |
| 88 | + git tag ${{ github.event.inputs.version }} |
| 89 | + git push origin tag ${{ github.event.inputs.version }} |
| 90 | +
|
| 91 | + release: |
| 92 | + name: make github release |
| 93 | + needs: tag |
| 94 | + runs-on: ubuntu-24.04 |
| 95 | + steps: |
| 96 | + |
| 97 | + - name: create release |
| 98 | + uses: softprops/action-gh-release@v2.3.2 |
| 99 | + with: |
| 100 | + name: v${{ github.event.inputs.version }} |
| 101 | + generate_release_notes: true |
| 102 | + tag_name: ${{ github.event.inputs.version }} |
| 103 | + |
| 104 | + pypi: |
| 105 | + name: make pypi release |
| 106 | + needs: [tag, release] |
| 107 | + runs-on: ubuntu-24.04 |
| 108 | + steps: |
| 109 | + |
| 110 | + - name: checkout |
| 111 | + uses: actions/checkout@v5.0.0 |
| 112 | + with: |
| 113 | + ref: main |
| 114 | + |
| 115 | + - name: Set up Python |
| 116 | + uses: actions/setup-python@v5.6.0 |
| 117 | + with: |
| 118 | + python-version: 3.13 |
| 119 | + |
| 120 | + - name: Install flit |
| 121 | + run: | |
| 122 | + python -m pip install --upgrade pip |
| 123 | + python -m pip install flit~=3.9 |
| 124 | +
|
| 125 | + - name: Build and publish |
| 126 | + run: | |
| 127 | + flit publish |
| 128 | + env: |
| 129 | + FLIT_USERNAME: __token__ |
| 130 | + FLIT_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 131 | + |
0 commit comments