|
1 | 1 | name: Release |
| 2 | + |
2 | 3 | on: |
3 | 4 | push: |
4 | 5 | branches: |
5 | | - - workflow_release |
| 6 | + - workflow_release |
6 | 7 | tags: |
7 | | - - 'v[0-9]+.[0-9]+.[0-9]+' |
| 8 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 9 | + - 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+' |
| 10 | + - 'v[0-9]+.[0-9]+.[0-9]+-alpha' |
| 11 | + - 'v[0-9]+.[0-9]+.[0-9]+-beta' |
8 | 12 |
|
9 | 13 | jobs: |
10 | | - build: |
11 | | - name: build |
| 14 | + build_release: |
| 15 | + name: build_release |
12 | 16 | runs-on: macos-latest |
13 | 17 | strategy: |
14 | 18 | matrix: |
15 | 19 | python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] |
16 | 20 |
|
| 21 | + env: |
| 22 | + MACOSX_DEPLOYMENT_TARGET: '11.0' |
| 23 | + |
17 | 24 | steps: |
18 | | - - uses: actions/checkout@v4 |
19 | | - - name: Set up Python ${{ matrix.python-version }} |
20 | | - uses: actions/setup-python@v4 |
21 | | - with: |
22 | | - python-version: ${{ matrix.python-version }} |
23 | | - - name: Install pypa/build |
24 | | - run: >- |
25 | | - python3 -m |
26 | | - pip install |
27 | | - build |
28 | | - --user |
29 | | -
|
30 | | - - name: Build a binary wheel and a source tarball |
31 | | - run: python3 -m build |
32 | | - - name: Store the distribution packages |
33 | | - uses: actions/upload-artifact@v3 |
34 | | - with: |
35 | | - name: python-package-distributions |
36 | | - path: dist/ |
37 | | - |
38 | | - publish-to-pypi: |
39 | | - name: Publish Python 🐍 distribution 📦 to PyPI |
40 | | - if: startsWith(github.ref, 'refs/tags/') |
41 | | - needs: |
42 | | - - build |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Python ${{ matrix.python-version }} |
| 29 | + uses: actions/setup-python@v4 |
| 30 | + with: |
| 31 | + python-version: ${{ matrix.python-version }} |
| 32 | + |
| 33 | + - name: Install pypa/build |
| 34 | + run: python3 -m pip install build |
| 35 | + shell: bash |
| 36 | + |
| 37 | + - name: Build a binary wheel and a source tarball |
| 38 | + id: build |
| 39 | + run: python3 -m build |
| 40 | + shell: bash |
| 41 | + |
| 42 | + - name: Upload the distribution packages |
| 43 | + uses: actions/upload-artifact@v3 |
| 44 | + with: |
| 45 | + name: python-package-distributions |
| 46 | + path: dist/ |
| 47 | + |
| 48 | + create_release: |
| 49 | + name: create_release |
| 50 | + needs: ['build_release'] |
43 | 51 | runs-on: ubuntu-latest |
44 | | - environment: |
45 | | - name: pypi |
46 | | - url: https://pypi.org/project/pasteboard/ |
47 | 52 | permissions: |
48 | | - id-token: write |
| 53 | + # IMPORTANT: mandatory for making GitHub Releases |
| 54 | + # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#overview |
| 55 | + contents: write |
49 | 56 |
|
50 | 57 | steps: |
51 | | - - name: Download all the dists |
| 58 | + - name: Download the distribution packages |
52 | 59 | uses: actions/download-artifact@v3 |
53 | 60 | with: |
54 | 61 | name: python-package-distributions |
55 | 62 | path: dist/ |
56 | | - - name: Publish distribution 📦 to PyPI |
57 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
58 | 63 |
|
| 64 | + - name: List the distribution packages |
| 65 | + run: ls -1 dist/* |
| 66 | + shell: bash |
| 67 | + |
| 68 | + - name: Create release |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ github.token }} |
| 71 | + run: | |
| 72 | + ref_name='${{ github.ref_name }}' |
| 73 | + echo "ref_name: $ref_name" |
| 74 | +
|
| 75 | + # empty arguments |
| 76 | + set -- |
| 77 | +
|
| 78 | + # is this a test release, or a real release? |
| 79 | + if [[ "$ref_name" == 'workflow_release' ]]; then |
| 80 | + version='v0.0.0-test' |
| 81 | + set -- "$@" --target '${{ github.sha }}' |
| 82 | + else |
| 83 | + version="$ref_name" |
| 84 | + fi |
| 85 | + echo "version: $version" |
59 | 86 |
|
60 | | - github-release: |
61 | | - name: >- |
62 | | - Sign the Python 🐍 distribution 📦 with Sigstore |
63 | | - and upload them to GitHub Release |
64 | | - needs: |
65 | | - - publish-to-pypi |
| 87 | + # is this a pre-release (-rc*, -alpha, -beta, -test)? |
| 88 | + if [[ "$version" == *"-"* ]]; then |
| 89 | + set -- "$@" --prerelease |
| 90 | + fi |
| 91 | +
|
| 92 | + date=$(env TZ=':America/Los_Angeles' date +'%Y-%m-%d') |
| 93 | + echo "date: $date" |
| 94 | +
|
| 95 | + echo "args: $@" |
| 96 | +
|
| 97 | + set -x |
| 98 | + gh release create \ |
| 99 | + "$version" \ |
| 100 | + dist/* \ |
| 101 | + --title "$version ($date)" \ |
| 102 | + --draft \ |
| 103 | + --repo '${{ github.repository }}' \ |
| 104 | + "$@" |
| 105 | + shell: bash |
| 106 | + |
| 107 | + publish_release_test: |
| 108 | + name: publish_release_test |
| 109 | + needs: ['build_release', 'create_release'] |
66 | 110 | runs-on: ubuntu-latest |
67 | 111 |
|
| 112 | + environment: |
| 113 | + name: testpypi |
| 114 | + url: https://pypi.org/project/pasteboard/ |
| 115 | + |
68 | 116 | permissions: |
69 | | - contents: write # IMPORTANT: mandatory for making GitHub Releases |
70 | | - id-token: write # IMPORTANT: mandatory for sigstore |
| 117 | + # IMPORTANT: mandatory for trusted publishing |
| 118 | + # https://docs.pypi.org/trusted-publishers/ |
| 119 | + id-token: write |
71 | 120 |
|
72 | 121 | steps: |
73 | | - - name: Download all the dists |
74 | | - uses: actions/download-artifact@v3 |
75 | | - with: |
76 | | - name: python-package-distributions |
77 | | - path: dist/ |
78 | | - - name: Sign the dists with Sigstore |
79 | | - |
80 | | - with: |
81 | | - inputs: >- |
82 | | - ./dist/*.tar.gz |
83 | | - ./dist/*.whl |
84 | | - - name: Create GitHub Release |
85 | | - env: |
86 | | - GITHUB_TOKEN: ${{ github.token }} |
87 | | - run: >- |
88 | | - gh release create |
89 | | - '${{ github.ref_name }}' |
90 | | - --repo '${{ github.repository }}' |
91 | | - --notes "" |
92 | | - - name: Upload artifact signatures to GitHub Release |
93 | | - env: |
94 | | - GITHUB_TOKEN: ${{ github.token }} |
95 | | - # Upload to GitHub Release using the `gh` CLI. |
96 | | - # `dist/` contains the built packages, and the |
97 | | - # sigstore-produced signatures and certificates. |
98 | | - run: >- |
99 | | - gh release upload |
100 | | - '${{ github.ref_name }}' dist/** |
101 | | - --repo '${{ github.repository }}' |
102 | | -
|
103 | | - publish-to-testpypi: |
104 | | - name: Publish Python 🐍 distribution 📦 to TestPyPI |
105 | | - needs: |
106 | | - - build |
| 122 | + - name: Download the distribution packages |
| 123 | + uses: actions/download-artifact@v3 |
| 124 | + with: |
| 125 | + name: python-package-distributions |
| 126 | + path: dist/ |
| 127 | + |
| 128 | + - name: List the distribution packages |
| 129 | + run: ls -1 dist/* |
| 130 | + shell: bash |
| 131 | + |
| 132 | + - name: Publish distribution packages to Test PyPI |
| 133 | + uses: pypa/gh-action-pypi-publish@release/v1.8 |
| 134 | + with: |
| 135 | + print-hash: true |
| 136 | + repository-url: https://test.pypi.org/legacy/ |
| 137 | + |
| 138 | + publish_release_real: |
| 139 | + name: publish_release_real |
| 140 | + needs: ['build_release', 'create_release', 'publish_release_test'] |
107 | 141 | runs-on: ubuntu-latest |
108 | 142 |
|
109 | 143 | environment: |
110 | | - name: testpypi |
| 144 | + name: pypi |
111 | 145 | url: https://pypi.org/project/pasteboard/ |
112 | 146 |
|
113 | 147 | permissions: |
114 | | - id-token: write # IMPORTANT: mandatory for trusted publishing |
| 148 | + # IMPORTANT: mandatory for trusted publishing |
| 149 | + # https://docs.pypi.org/trusted-publishers/ |
| 150 | + id-token: write |
115 | 151 |
|
116 | 152 | steps: |
117 | | - - name: Download all the dists |
118 | | - uses: actions/download-artifact@v3 |
119 | | - with: |
120 | | - name: python-package-distributions |
121 | | - path: dist/ |
122 | | - - name: Publish distribution 📦 to TestPyPI |
123 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
124 | | - with: |
125 | | - repository-url: https://test.pypi.org/legacy/ |
| 153 | + - name: Download the distribution packages |
| 154 | + uses: actions/download-artifact@v3 |
| 155 | + with: |
| 156 | + name: python-package-distributions |
| 157 | + path: dist/ |
| 158 | + |
| 159 | + - name: List the distribution packages |
| 160 | + run: ls -1 dist/* |
| 161 | + shell: bash |
| 162 | + |
| 163 | + - name: Publish distribution packages to PyPI |
| 164 | + uses: pypa/gh-action-pypi-publish@release/v1.8 |
| 165 | + with: |
| 166 | + print-hash: true |
0 commit comments