|
1 | | -name: Reusable Setup |
| 1 | +name: Bump version |
| 2 | + |
2 | 3 | on: |
3 | | - workflow_call: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - main |
| 8 | + workflow_dispatch: |
4 | 9 | inputs: |
5 | | - python-version: |
6 | | - required: false |
7 | | - type: string |
8 | | - default: "3.12" |
9 | | - install-deps: |
10 | | - required: false |
11 | | - type: string |
12 | | - default: "dev" # dev, docs, or none |
13 | | - secrets: |
14 | | - OP_SERVICE_ACCOUNT_TOKEN: |
15 | | - required: false |
16 | | - PERSONAL_ACCESS_TOKEN: |
| 10 | + increment: |
| 11 | + description: 'Version increment (major, minor, patch)' |
17 | 12 | required: false |
18 | | - outputs: |
19 | | - python-version: |
20 | | - description: "The Python version that was set up" |
21 | | - value: ${{ jobs.setup.outputs.python-version }} |
22 | | - PERSONAL_ACCESS_TOKEN: |
23 | | - description: "The personal access token" |
24 | | - value: ${{ jobs.setup.outputs.PERSONAL_ACCESS_TOKEN }} |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - major |
| 16 | + - minor |
| 17 | + - patch |
| 18 | + default: patch |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write # 用于创建和推送标签 |
| 22 | + pull-requests: write # 用于创建 PR |
25 | 23 |
|
26 | 24 | jobs: |
27 | 25 | setup: |
| 26 | + uses: ./.github/workflows/setup.yaml |
| 27 | + secrets: inherit |
| 28 | + |
| 29 | + bump-version: |
| 30 | + if: "!startsWith(github.event.head_commit.message, 'bump:')" |
| 31 | + needs: setup |
28 | 32 | runs-on: ubuntu-latest |
29 | | - outputs: |
30 | | - python-version: ${{ steps.setup-python.outputs.python-version }} |
31 | | - PERSONAL_ACCESS_TOKEN: ${{ steps.set-token.outputs.PERSONAL_ACCESS_TOKEN }} |
| 33 | + name: "Bump version and create changelog with commitizen" |
32 | 34 | steps: |
33 | | - - name: Load secret |
34 | | - id: load-secret |
35 | | - if: ${{ inputs.install-deps != 'none' }} |
36 | | - uses: 1password/load-secrets-action@v2 |
37 | | - with: |
38 | | - export-env: true |
39 | | - env: |
40 | | - OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} |
41 | | - PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential |
42 | | - |
43 | | - - name: Set token output |
44 | | - id: set-token |
45 | | - if: ${{ inputs.install-deps != 'none' }} |
46 | | - run: echo "PERSONAL_ACCESS_TOKEN=${PERSONAL_ACCESS_TOKEN}" >> $GITHUB_OUTPUT |
47 | | - |
48 | 35 | - name: Check out |
49 | 36 | uses: actions/checkout@v4 |
50 | 37 | with: |
51 | 38 | fetch-depth: 0 |
52 | | - token: ${{ env.PERSONAL_ACCESS_TOKEN || github.token }} |
| 39 | + token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} |
53 | 40 |
|
54 | | - - name: Setup Python |
55 | | - id: setup-python |
56 | | - uses: actions/setup-python@v5 |
| 41 | + - id: cz |
| 42 | + name: Create bump and changelog |
| 43 | + uses: commitizen-tools/commitizen-action@master |
57 | 44 | with: |
58 | | - python-version: ${{ inputs.python-version }} |
| 45 | + github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} |
| 46 | + changelog_increment_filename: body.md |
| 47 | + increment: ${{ github.event.inputs.increment }} |
59 | 48 |
|
60 | | - - name: Install uv |
61 | | - uses: astral-sh/setup-uv@v5 |
| 49 | + - name: Create Release |
| 50 | + uses: softprops/action-gh-release@v2 |
62 | 51 | with: |
63 | | - version: ">=0.4.0" |
64 | | - |
65 | | - - name: Get uv cache dir |
66 | | - id: get-uv-cache |
67 | | - run: echo "UV_CACHE_DIR=$(uv cache dir)" >> $GITHUB_OUTPUT |
68 | | - |
69 | | - - name: Install dependencies |
70 | | - if: ${{ inputs.install-deps != 'none' }} |
71 | | - run: uv sync --extra ${{ inputs.install-deps }} |
72 | | - |
73 | | - - name: Cache uv packages |
74 | | - uses: actions/cache@v4 |
75 | | - with: |
76 | | - path: ${{ steps.get-uv-cache.outputs.UV_CACHE_DIR }} |
77 | | - key: ${{ runner.os }}-uv-${{ hashFiles('**/pyproject.toml', '**/requirements*.txt') }} |
78 | | - restore-keys: | |
79 | | - ${{ runner.os }}-uv- |
| 52 | + body_path: body.md |
| 53 | + tag_name: ${{ env.REVISION }} |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} |
0 commit comments