|
1 |
| -name: Publish Release |
2 |
| -# From |
3 |
| -# https://github.com/pdxjohnny/httptest/blob/master/.github/workflows/release.yml |
| 1 | +name: Release |
4 | 2 |
|
5 | 3 | on:
|
6 |
| - push: |
7 |
| - tags: |
8 |
| - - '*' |
9 |
| - workflow_dispatch: {} |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
10 | 7 |
|
11 | 8 | jobs:
|
12 |
| - build: |
13 |
| - name: Build |
| 9 | + release: |
14 | 10 | runs-on: ubuntu-latest
|
15 | 11 | strategy:
|
16 | 12 | matrix:
|
17 | 13 | python-version:
|
18 | 14 | - "3.10"
|
19 | 15 | steps:
|
20 |
| - - uses: actions/checkout@v2 |
| 16 | + - uses: actions/checkout@v3 |
21 | 17 | - name: Set up Python ${{ matrix.python-version }}
|
22 |
| - uses: actions/setup-python@v2 |
| 18 | + uses: actions/setup-python@v4 |
23 | 19 | with:
|
24 | 20 | python-version: ${{ matrix.python-version }}
|
25 |
| - - name: Get pip cache |
26 |
| - id: pip-cache |
| 21 | + - name: Install PyPi Release Dependencies |
27 | 22 | run: |
|
28 |
| - python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)" |
29 |
| - - name: pip cache |
30 |
| - uses: actions/cache@v1 |
31 |
| - with: |
32 |
| - path: ${{ steps.pip-cache.outputs.dir }} |
33 |
| - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} |
34 |
| - restore-keys: | |
35 |
| - ${{ runner.os }}-pip- |
36 |
| - - name: Install dependencies |
37 |
| - run: | |
38 |
| - python -m pip install -U pip setuptools wheel |
39 |
| - python -m pip install -U build |
40 |
| - - name: Build |
| 23 | + pip install -U pip setuptools wheel twine build |
| 24 | + - name: Build Package |
41 | 25 | run: |
|
42 |
| - python -m build . |
43 |
| - - uses: actions/upload-artifact@v2 |
44 |
| - with: |
45 |
| - name: dist |
46 |
| - path: dist |
47 |
| - |
48 |
| - pypi: |
49 |
| - name: PyPi |
50 |
| - runs-on: ubuntu-latest |
51 |
| - needs: build |
52 |
| - steps: |
53 |
| - - uses: actions/download-artifact@v2 |
54 |
| - with: |
55 |
| - name: dist |
56 |
| - path: dist |
57 |
| - - name: Get pip cache |
58 |
| - id: pip-cache |
59 |
| - run: | |
60 |
| - python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)" |
61 |
| - - name: pip cache |
62 |
| - uses: actions/cache@v1 |
63 |
| - with: |
64 |
| - path: ${{ steps.pip-cache.outputs.dir }} |
65 |
| - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} |
66 |
| - restore-keys: | |
67 |
| - ${{ runner.os }}-pip- |
68 |
| - - name: Install dependencies |
| 26 | + python -m build |
| 27 | + - name: Get tag |
| 28 | + id: get-tag |
69 | 29 | run: |
|
70 |
| - python -m pip install -U pip setuptools wheel |
71 |
| - python -m pip install -U twine |
72 |
| - - name: Release |
73 |
| - env: |
74 |
| - TWINE_USERNAME: __token__ |
75 |
| - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 30 | + echo "tag=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT |
| 31 | + if [ "x${{ secrets.PYPI_TOKEN }}" == "x" ]; then |
| 32 | + echo "has_pypi_token=no" >> $GITHUB_OUTPUT |
| 33 | + else |
| 34 | + echo "has_pypi_token=yes" >> $GITHUB_OUTPUT |
| 35 | + fi |
| 36 | + - name: PyPi Release |
| 37 | + id: pypi-release |
| 38 | + if: ${{ steps.get-tag.outputs.has_pypi_token == 'yes' }} |
76 | 39 | run: |
|
| 40 | + export TWINE_USERNAME=__token__ |
| 41 | + export TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }} |
77 | 42 | python -m twine upload dist/*
|
78 |
| -
|
79 |
| - github: |
80 |
| - name: GitHub |
81 |
| - runs-on: ubuntu-latest |
82 |
| - needs: build |
83 |
| - steps: |
84 |
| - - uses: actions/checkout@v2 |
85 |
| - - uses: actions/download-artifact@v2 |
| 43 | + - name: GitHub Release |
| 44 | + uses: "marvinpinto/action-automatic-releases@4edd7a5aabb1bc62e6dc99b3302d587bf3134e20" |
86 | 45 | with:
|
87 |
| - name: dist |
88 |
| - path: dist |
89 |
| - - name: Upload wheel |
90 |
| - env: |
91 |
| - GH_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
92 |
| - run: | |
93 |
| - set -x |
94 |
| -
|
95 |
| - tag=$(echo "${{ github.ref }}" | sed -e 's/.*\///g') |
96 |
| -
|
97 |
| - cd dist |
98 |
| - wheel=$(echo *.whl) |
99 |
| -
|
100 |
| - notes=$(curl \ |
101 |
| - --header "Accept: application/vnd.github.v3+json" \ |
102 |
| - --header "Authorization: Bearer ${GH_ACCESS_TOKEN}" \ |
103 |
| - --url "https://api.github.com/repos/${{ github.repository }}/releases/generate-notes" \ |
104 |
| - --data "{\"tag_name\": \"${tag}\"}") |
105 |
| - echo "${notes}" |
106 |
| - # TODO Update release body with notes, need to JSON escape |
107 |
| - # https://docs.github.com/en/rest/reference/releases#update-a-release |
108 |
| -
|
109 |
| - id=$(curl \ |
110 |
| - --header "Accept: application/vnd.github.v3+json" \ |
111 |
| - --header "Authorization: Bearer ${GH_ACCESS_TOKEN}" \ |
112 |
| - --url "https://api.github.com/repos/${{ github.repository }}/releases/tags/${tag}" | |
113 |
| - grep '"id"' | |
114 |
| - head -n 1 | |
115 |
| - sed -e 's/.*"id": //' -e 's/,//') |
116 |
| - echo "release id: ${id}" |
117 |
| -
|
118 |
| - curl --request POST \ |
119 |
| - --url "https://uploads.github.com/repos/${{ github.repository }}/releases/${id}/assets?name=${wheel}&access_token=${GH_ACCESS_TOKEN}" \ |
120 |
| - --header "Authorization: Bearer ${GH_ACCESS_TOKEN}" \ |
121 |
| - --header "Content-Type: application/octet-stream" \ |
122 |
| - --data-binary @"${wheel}" \ |
123 |
| - --fail |
| 46 | + repo_token: "${{ secrets.GITHUB_TOKEN }}" |
| 47 | + automatic_release_tag: "${{ steps.get-tag.outputs.tag }}" |
| 48 | + prerelease: false |
| 49 | + title: "${{ steps.pypi-release.outputs.tag }}" |
| 50 | + files: | |
| 51 | + dist/* |
0 commit comments