77 workflow_dispatch :
88 inputs :
99 version :
10- description : ' Version to release'
10+ description : ' Version to release (e.g., 1.0.0) '
1111 required : true
1212 publish_to_pypi :
1313 description : ' Publish to PyPI'
@@ -19,191 +19,219 @@ on:
1919 - ' false'
2020
2121jobs :
22- create-release :
23- name : Create GitHub Release
22+
23+ prepare-release :
24+ name : Prepare and Create GitHub Release
2425 runs-on : ubuntu-latest
26+ outputs :
27+ version : ${{ steps.set_outputs.outputs.version }}
28+ tag_name : ${{ steps.set_outputs.outputs.tag_name }}
29+ upload_url : ${{ steps.create_release.outputs.upload_url }}
30+ release_id : ${{ steps.create_release.outputs.id }}
2531 steps :
2632 - name : Checkout Code
27- uses : actions/checkout@v3
33+ uses : actions/checkout@v4
2834
2935 - name : Set up Python
30- uses : actions/setup-python@v4
36+ uses : actions/setup-python@v5
3137 with :
3238 python-version : ' 3.11'
3339
34- - name : Install Dependencies
35- run : |
36- python -m pip install --upgrade pip
37- pip install -r requirements.txt
38- pip install -e .
39-
40- - name : Set version (Unix)
41- if : matrix.os != 'windows-latest'
40+
41+
42+ - name : Set version in version.py
4243 run : |
43- python -c "import re; content = open('src/treemapper/version.py', 'r').read(); open('src/treemapper/version.py', 'w').write(re.sub('__version__ = \".*\"', '__version__ = \"${{ github.event.inputs.version }}\"', content))"
44-
45- - name : Set version (Windows)
46- if : matrix.os == 'windows-latest'
47- shell : pwsh
44+ VERSION="${{ github.event.inputs.version }}"
45+ echo "Setting version to $VERSION"
46+
47+ sed -i -E "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" src/treemapper/version.py
48+ echo "version.py content after change:"
49+ cat src/treemapper/version.py
50+
51+
52+ - name : Commit and Tag version bump
4853 run : |
49- $content = Get-Content src/treemapper/version.py -Raw
50- $newContent = $content -replace '__version__ = ".*"', '__version__ = "${{ github.event.inputs.version }}"'
51- Set-Content src/treemapper/version.py -Value $newContent
52-
53- - name : Create Release
54+ git config user.name github-actions
55+ git config user.email github-actions@github.com
56+ git add src/treemapper/version.py
57+
58+ git diff --staged --quiet || git commit -m "Release version ${{ github.event.inputs.version }}"
59+ git tag v${{ github.event.inputs.version }}
60+ git push origin v${{ github.event.inputs.version }}
61+
62+
63+
64+ - name : Create GitHub Release
5465 id : create_release
5566 uses : actions/create-release@v1
5667 env :
5768 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5869 with :
5970 tag_name : v${{ github.event.inputs.version }}
6071 release_name : Release ${{ github.event.inputs.version }}
72+ commitish : v${{ github.event.inputs.version }}
6173 draft : false
6274 prerelease : false
6375
64- outputs :
65- upload_url : ${{ steps.create_release.outputs.upload_url }}
66- version : ${{ github.event.inputs.version }}
67- release_id : ${{ steps.create_release.outputs.id }}
76+
77+ - name : Set outputs for subsequent jobs
78+ id : set_outputs
79+ run : |
80+ echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
81+ echo "tag_name=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
6882
83+
6984 build-and-upload :
7085 name : Build and Upload Assets
71- needs : create-release
72- runs-on : ${{ matrix.os }}
86+ needs : prepare-release
7387 strategy :
88+ fail-fast : false
7489 matrix :
7590 include :
76- - os : ubuntu-20.04
91+ - os : ubuntu-latest
7792 asset_name : linux
93+ python-version : ' 3.11'
7894 - os : macos-latest
7995 asset_name : macos
96+ python-version : ' 3.11'
8097 - os : windows-latest
8198 asset_name : windows
99+ python-version : ' 3.11'
100+ runs-on : ${{ matrix.os }}
82101 steps :
83- - name : Checkout Code
84- uses : actions/checkout@v3
102+ - name : Checkout Code at release tag
103+ uses : actions/checkout@v4
104+ with :
105+ ref : ${{ needs.prepare-release.outputs.tag_name }}
85106
86107 - name : Set up Python
87- uses : actions/setup-python@v4
108+ uses : actions/setup-python@v5
88109 with :
89- python-version : ' 3.11 '
110+ python-version : ${{ matrix.python-version }}
90111
91112 - name : Cache pip Dependencies
92- uses : actions/cache@v3
113+ uses : actions/cache@v4
114+ id : cache-pip
93115 with :
94116 path : ~/.cache/pip
95- key : ${{ runner.os }}-pip-${{ hashFiles('**/setup.cfg') }}
117+ key : ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.cfg') }}
96118 restore-keys : |
119+ ${{ runner.os }}-pip-${{ matrix.python-version }}-
97120 ${{ runner.os }}-pip-
98121
99- - name : Install Dependencies
122+ - name : Install Dependencies (including PyInstaller)
100123 run : |
101124 python -m pip install --upgrade pip
102- pip install -r requirements.txt
103- pip install -e .
125+
126+ pip install .[dev]
104127
105- - name : Set version (Unix)
106- if : matrix.os != 'windows-latest'
107- run : |
108- python -c "import re; content = open('src/treemapper/version.py', 'r').read(); open('src/treemapper/version.py', 'w').write(re.sub('__version__ = \".*\"', '__version__ = \"${{ github.event.inputs.version }}\"', content))"
109-
110- - name : Set version (Windows)
111- if : matrix.os == 'windows-latest'
112- shell : pwsh
113- run : |
114- $content = Get-Content src/treemapper/version.py -Raw
115- $newContent = $content -replace '__version__ = ".*"', '__version__ = "${{ github.event.inputs.version }}"'
116- Set-Content src/treemapper/version.py -Value $newContent
128+
117129
118130 - name : Build with PyInstaller
119131 run : |
120- python -m PyInstaller --clean -y --dist ./dist/${{ matrix.asset_name }} --workpath /tmp treemapper.spec
132+
133+ python -m PyInstaller --clean -y --dist ./dist/${{ matrix.asset_name }} treemapper.spec
121134
122135 - name : Determine architecture
123136 id : arch
124137 shell : bash
125138 run : |
126- if [ "${{ matrix.os }}" = "macos-latest" ]; then
127- echo "ARCH=$(uname -m)" >> $GITHUB_OUTPUT
128- elif [ "${{ matrix.os }}" = "ubuntu-20.04" ]; then
129- echo "ARCH=$(uname -m)" >> $GITHUB_OUTPUT
130- else
131- echo "ARCH=x86_64" >> $GITHUB_OUTPUT
139+ ARCH=$(uname -m)
140+
141+ if [[ "${{ runner.os }}" == "Windows" ]]; then
142+
143+ if [[ "${{ runner.arch }}" == "X64" ]]; then
144+ ARCH="x86_64"
145+ elif [[ "${{ runner.arch }}" == "ARM64" ]]; then
146+ ARCH="arm64"
147+ else
148+ ARCH="unknown"
149+ fi
150+ elif [[ "${{ runner.os }}" == "macOS" ]] && [[ "$ARCH" == "arm64" ]]; then
151+
152+ echo "Detected ARM on macOS"
132153 fi
154+ echo "Determined ARCH: $ARCH"
155+ echo "arch=$ARCH" >> $GITHUB_OUTPUT
156+
133157
134158 - name : Upload Release Asset
135159 uses : actions/upload-release-asset@v1
136160 env :
137161 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
138162 with :
139- upload_url : ${{ needs.create-release.outputs.upload_url }}
140- asset_path : ./dist/${{ matrix.asset_name }}/treemapper${{ matrix.os == 'windows-latest' && '.exe' || '' }}
141- asset_name : treemapper-${{ matrix.asset_name }}-${{ steps.arch.outputs.ARCH }}-v${{ needs.create-release.outputs.version }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}
163+ upload_url : ${{ needs.prepare-release.outputs.upload_url }}
164+
165+ asset_path : ./dist/${{ matrix.asset_name }}/treemapper/${{ matrix.os == 'windows-latest' && 'treemapper.exe' || 'treemapper' }}
166+ asset_name : treemapper-${{ matrix.asset_name }}-${{ steps.arch.outputs.arch }}-v${{ needs.prepare-release.outputs.version }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}
142167 asset_content_type : application/octet-stream
143168
169+
144170 publish-to-pypi :
145171 name : Publish to PyPI
146- needs : [ create -release, build-and-upload ]
172+ needs : [prepare -release, build-and-upload]
147173 if : github.event.inputs.publish_to_pypi == 'true'
148174 runs-on : ubuntu-latest
175+ environment :
176+ name : pypi
177+ url : https://pypi.org/p/treemapper
178+ permissions :
179+ id-token : write
149180 steps :
150- - name : Checkout Code
151- uses : actions/checkout@v3
181+ - name : Checkout Code at release tag
182+ uses : actions/checkout@v4
183+ with :
184+ ref : ${{ needs.prepare-release.outputs.tag_name }}
152185
153186 - name : Set up Python
154- uses : actions/setup-python@v4
187+ uses : actions/setup-python@v5
155188 with :
156189 python-version : ' 3.11'
157190
158- - name : Cache pip Dependencies
159- uses : actions/cache@v3
160- with :
161- path : ~/.cache/pip
162- key : ${{ runner.os }}-pip-${{ hashFiles('**/setup.cfg') }}
163- restore-keys : |
164- ${{ runner.os }}-pip-
165-
166- - name : Install Dependencies
191+ - name : Install build tools
167192 run : |
168193 python -m pip install --upgrade pip
169- pip install -r requirements.txt
194+ pip install build
170195
171- - name : Set version (Unix)
172- if : matrix.os != 'windows-latest'
173- run : |
174- python -c "import re; content = open('src/treemapper/version.py', 'r').read(); open('src/treemapper/version.py', 'w').write(re.sub('__version__ = \".*\"', '__version__ = \"${{ github.event.inputs.version }}\"', content))"
196+
175197
176- - name : Set version (Windows)
177- if : matrix.os == 'windows-latest'
178- shell : pwsh
179- run : |
180- $content = Get-Content src/treemapper/version.py -Raw
181- $newContent = $content -replace '__version__ = ".*"', '__version__ = "${{ github.event.inputs.version }}"'
182- Set-Content src/treemapper/version.py -Value $newContent
198+ - name : Build sdist and wheel
199+ run : python -m build
183200
184- - name : Build and Publish to PyPI
185- env :
186- TWINE_USERNAME : __token__
187- TWINE_PASSWORD : ${{ secrets.PYPI_TOKEN }}
188- run : |
189- python -m build
190- python -m twine upload dist/* --verbose
201+
202+ - name : Publish package distributions to PyPI
203+ uses : pypa/gh-action-pypi-publish@release/v1
204+
205+
206+
207+
208+
209+
210+
191211
192212
213+
193214 update-main-branch :
194- name : Update main branch
195- needs : [ publish-to-pypi ]
215+ name : Update main branch (Merge Tag)
216+
217+
218+ needs : [prepare-release, build-and-upload]
196219 runs-on : ubuntu-latest
220+
221+
197222 steps :
223+
198224 - name : Checkout main branch
199- uses : actions/checkout@v3
225+ uses : actions/checkout@v4
200226 with :
201227 ref : main
202228 fetch-depth : 0
203229
204230 - name : Merge tag into main
205231 run : |
206- git config user.name github-actions
207- git config user.email github-actions@github.com
208- git merge ${{ github.ref }} --no-ff -m "Merge tag ${{ github.ref_name }} into main"
209- git push origin main
232+ git config user.name github-actions[bot]
233+ git config user.email 41898282+github-actions[bot]@users.noreply.github.com
234+ echo "Attempting to merge tag ${{ needs.prepare-release.outputs.tag_name }} into main"
235+
236+ git merge ${{ needs.prepare-release.outputs.tag_name }} --no-ff -m "Merge tag ${{ needs.prepare-release.outputs.tag_name }} into main"
237+ git push origin main
0 commit comments