Skip to content

Commit b768ee2

Browse files
committed
simplify packaging and publishing
1 parent fe5d1b8 commit b768ee2

File tree

11 files changed

+100
-152
lines changed

11 files changed

+100
-152
lines changed

.github/workflows/build.yml

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
if: always()
100100

101101
package:
102-
#needs: test
102+
needs: test
103103
runs-on: ubuntu-latest
104104

105105
steps:
@@ -129,7 +129,7 @@ jobs:
129129
run: npm install --also=dev
130130

131131
- name: package
132-
run: poetry run npm-package
132+
run: poetry run npm package
133133

134134
- name: Upload VSCode package
135135
uses: actions/upload-artifact@v2
@@ -151,9 +151,8 @@ jobs:
151151

152152
publish:
153153
runs-on: ubuntu-latest
154-
environment: publish
155154
needs: package
156-
if: success() && startsWith( github.ref, 'refs/tags')
155+
if: success() && startsWith( github.ref, 'refs/tags/v')
157156
steps:
158157
- uses: actions/checkout@v2
159158
with:
@@ -193,26 +192,23 @@ jobs:
193192
name: wheel-package
194193
path: dist
195194

196-
- name: publish
197-
run: poetry run npm-publish
198-
env:
199-
VSCE_PAT: ${{ secrets.VSCE_PAT }}
200-
OVSX_PAT: ${{ secrets.OVSX_PAT }}
201-
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
202-
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
203-
204195
- name: get release notes
205196
id: get_release_notes
206-
run: echo "::set-output name=release_notes::$(poetry run extract-release-notes)"
197+
run: echo "::set-output name=release_notes::$(poetry run npm extract-release-notes)"
207198

208-
- name: find vsix
209-
id: find_vsix
199+
- name: find assets
200+
id: find_assets
210201
run: |
211202
echo "::set-output name=vsix_file::$(find dist -iname '*.vsix')"
212203
echo "::set-output name=vsix_name::$(find dist -iname '*.vsix' -printf '%f\n')"
213204
205+
echo "::set-output name=whl_file::$(find dist -iname '*.whl')"
206+
echo "::set-output name=whl_name::$(find dist -iname '*.whl' -printf '%f\n')"
214207
215-
- name: create release
208+
echo "::set-output name=tar_gz_file::$(find dist -iname '*.tar.gz')"
209+
echo "::set-output name=tar_gz_name::$(find dist -iname '*.tar.gz' -printf '%f\n')"
210+
211+
- name: create github release
216212
id: create_release
217213
uses: actions/create-release@v1
218214
env:
@@ -224,13 +220,44 @@ jobs:
224220
draft: true
225221
prerelease: true
226222

227-
- name: upload release vsix
228-
id: upload-release-asset
223+
- name: upload vsix asset to github release
224+
id: upload-vsix-asset
229225
uses: actions/upload-release-asset@v1
230226
env:
231227
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
232228
with:
233229
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
234-
asset_path: ${{ steps.find_vsix.outputs.vsix_file }}
235-
asset_name: ${{ steps.find_vsix.outputs.vsix_name }}
230+
asset_path: ${{ steps.find_assets.outputs.vsix_file }}
231+
asset_name: ${{ steps.find_assets.outputs.vsix_name }}
236232
asset_content_type: application/vsix
233+
234+
- name: upload whl asset to github release
235+
id: upload-whl-asset
236+
uses: actions/upload-release-asset@v1
237+
env:
238+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
239+
with:
240+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
241+
asset_path: ${{ steps.find_assets.outputs.whl_file }}
242+
asset_name: ${{ steps.find_assets.outputs.whl_name }}
243+
asset_content_type: application/whl
244+
245+
- name: upload tar.gz asset to github release
246+
id: upload-tar-gz-asset
247+
uses: actions/upload-release-asset@v1
248+
env:
249+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
250+
with:
251+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
252+
asset_path: ${{ steps.find_assets.outputs.tar_gz_file }}
253+
asset_name: ${{ steps.find_assets.outputs.tar_gz_name }}
254+
asset_content_type: application/whl
255+
256+
- name: publish vsix and python packages
257+
run: poetry run npm publish
258+
env:
259+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
260+
OVSX_PAT: ${{ secrets.OVSX_PAT }}
261+
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
262+
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
263+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Autocompletion supports all supported variables types
6666
- Resources
6767
- Variables
6868
- Errors and Warnings
69+
6970
### Diagnostics and Linting
7071

7172
RobotCode analyse your code and show diagnostics for:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,8 @@
648648
"version": "python scripts/update_versions.py && git add .",
649649
"package": "python scripts/package.py",
650650
"publish": "python scripts/publish.py",
651-
"package-publish": "npm run package && python scripts/publish.py"
651+
"package-publish": "npm run package && python scripts/publish.py",
652+
"extract-release-notes": "python scripts/extract_release_notes.py"
652653
},
653654
"extensionDependencies": [
654655
"ms-python.python"

pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "robotcode"
7-
version = "0.7.4-preview"
7+
version = "0.7.4dev"
88
description = "Language server, debugger and tools for RobotFramework"
99
authors = ["Daniel Biehl <[email protected]>"]
1010
homepage = 'https://github.com/d-biehl/robotcode'
1111
repository = 'https://github.com/d-biehl/robotcode'
1212
readme = "README.md"
1313
license = "Apache-2.0"
14-
include = ["robotcode/py.typed", "README.md"]
14+
include = ["robotcode/py.typed", "README.md", "CHANGELOG.md"]
1515
exclude = ["robotcode/external"]
1616
keywords = [
1717
"Test",
@@ -49,9 +49,7 @@ classifiers = [
4949
]
5050

5151
[tool.poetry.scripts]
52-
npm-package = 'scripts.npm_package:main'
53-
npm-publish = 'scripts.npm_publish:main'
54-
extract-release-notes='scripts.extract_release_notes:main'
52+
npm='scripts.npm:main'
5553

5654
[tool.poetry.dependencies]
5755
python = "^3.8"

scripts/extract_release_notes.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,11 @@
1-
import os
21
import re
32
from pathlib import Path
43

5-
from git.repo import Repo
6-
from semantic_version import Version
7-
8-
9-
def get_current_version_from_git() -> Version:
10-
repo = Repo(Path.cwd())
11-
12-
result = None
13-
for tag in repo.tags:
14-
v = tag.name
15-
if v.startswith("v."):
16-
v = v[2:]
17-
elif v.startswith("v"):
18-
v = v[1:]
19-
20-
try:
21-
v = Version(v)
22-
except ValueError:
23-
continue
24-
25-
if not result or v > result:
26-
result = v
27-
28-
return result
4+
from scripts.tools import get_version
295

306

317
def main() -> None:
32-
if "npm_package_version" in os.environ:
33-
version = Version(os.environ["npm_package_version"])
34-
else:
35-
version = get_current_version_from_git()
8+
version = get_version()
369

3710
changelog = Path("CHANGELOG.md").read_text()
3811

scripts/npm_package.py renamed to scripts/npm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import sys
12
from subprocess import run
23

34

45
def main() -> None:
5-
run("npm run package", shell=True).check_returncode()
6+
run(f"npm run {' '.join(sys.argv[1:])}", shell=True).check_returncode()
67

78

89
if __name__ == "__main__":

scripts/npm_publish.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/package.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
1-
import os
21
from pathlib import Path
32
from subprocess import run
43

5-
from git.repo import Repo
6-
from semantic_version import Version
7-
8-
9-
def get_current_version_from_git() -> Version:
10-
repo = Repo(Path.cwd())
11-
12-
result = None
13-
for tag in repo.tags:
14-
v = tag.name
15-
if v.startswith("v."):
16-
v = v[2:]
17-
elif v.startswith("v"):
18-
v = v[1:]
19-
20-
try:
21-
v = Version(v)
22-
except ValueError:
23-
continue
24-
25-
if not result or v > result:
26-
result = v
27-
28-
return result
4+
from scripts.tools import get_version
295

306

317
def main() -> None:
328
dist_path = Path("./dist")
339
if not dist_path.exists():
3410
dist_path.mkdir()
3511

36-
if "npm_package_version" in os.environ:
37-
current_version = Version(os.environ["npm_package_version"])
38-
else:
39-
current_version = get_current_version_from_git()
12+
version = get_version()
4013

41-
pre_release = current_version.minor % 2 != 0
14+
pre_release = version.minor % 2 != 0
4215

4316
run(f"npx vsce package {'--pre-release' if pre_release else ''} -o ./dist", shell=True).check_returncode()
4417

scripts/publish.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,7 @@
22
from pathlib import Path
33
from subprocess import run
44

5-
from git.repo import Repo
6-
from semantic_version import Version
7-
8-
9-
def get_current_version_from_git() -> Version:
10-
repo = Repo(Path.cwd())
11-
12-
result = None
13-
for tag in repo.tags:
14-
v = tag.name
15-
if v.startswith("v."):
16-
v = v[2:]
17-
elif v.startswith("v"):
18-
v = v[1:]
19-
20-
try:
21-
v = Version(v)
22-
except ValueError:
23-
continue
24-
25-
if not result or v > result:
26-
result = v
27-
28-
return result
5+
from scripts.tools import get_version
296

307

318
def main() -> None:
@@ -34,10 +11,7 @@ def main() -> None:
3411
if not dist_path.exists():
3512
raise FileNotFoundError(f"dist folder '{dist_path}' not exists")
3613

37-
if "npm_package_version" in os.environ:
38-
current_version = Version(os.environ["npm_package_version"])
39-
else:
40-
current_version = get_current_version_from_git()
14+
current_version = get_version()
4115

4216
vsix_path = Path(dist_path, f"robotcode-{current_version}.vsix")
4317

scripts/tools.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
from pathlib import Path
3+
4+
from git.repo import Repo
5+
from semantic_version import Version
6+
7+
8+
def get_current_version_from_git() -> Version:
9+
repo = Repo(Path.cwd())
10+
11+
result = None
12+
for tag in repo.tags:
13+
v = tag.name
14+
if v.startswith("v."):
15+
v = v[2:]
16+
elif v.startswith("v"):
17+
v = v[1:]
18+
19+
try:
20+
v = Version(v)
21+
except ValueError:
22+
continue
23+
24+
if not result or v > result:
25+
result = v
26+
27+
return result
28+
29+
30+
def get_version() -> Version:
31+
if "npm_package_version" in os.environ:
32+
return Version(os.environ["npm_package_version"])
33+
else:
34+
return get_current_version_from_git()

0 commit comments

Comments
 (0)