|
7 | 7 | from setuptools.command.build import build
|
8 | 8 | from setuptools.command.install import install
|
9 | 9 |
|
| 10 | +PACKAGE_NAME = "work" |
| 11 | + |
10 | 12 | class BuildGoBinary(build):
|
11 | 13 | def run(self):
|
12 |
| - if not os.path.exists("work"): |
| 14 | + if not os.path.exists(PACKAGE_NAME): |
13 | 15 | print("Building Go binary...")
|
14 |
| - tag = os.environ["GITHUB_REF_NAME"] |
15 |
| - commit = os.environ["GITHUB_SHA"] |
| 16 | + tag = os.getenv("GITHUB_REF_NAME", "dev") |
| 17 | + commit = os.getenv("GITHUB_SHA", "none") |
16 | 18 | subprocess.check_call(
|
17 |
| - ["go", "build", f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w", "-o", "work", "main.go"], |
| 19 | + ["go", "build", f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w", "-o", PACKAGE_NAME, "main.go"], |
18 | 20 | env={"GOOS": "linux", "GOARCH": "amd64", **os.environ},
|
19 | 21 | )
|
20 | 22 | build.run(self)
|
21 | 23 |
|
22 | 24 | class PostInstallCommand(install):
|
23 | 25 | def run(self):
|
24 |
| - binary_source = os.path.join(os.path.dirname(__file__), "work") |
25 |
| - binary_dest = os.path.join(self.install_scripts, "work") |
| 26 | + binary_source = os.path.join(os.path.dirname(__file__), PACKAGE_NAME) |
| 27 | + binary_dest = os.path.join(self.install_scripts, PACKAGE_NAME) |
26 | 28 |
|
27 | 29 | os.makedirs(self.install_scripts, exist_ok=True)
|
28 | 30 | shutil.move(binary_source, binary_dest)
|
29 | 31 |
|
30 | 32 | install.run(self)
|
31 | 33 |
|
32 | 34 | setup(
|
33 |
| - name="work-bin", |
34 |
| - packages=[], |
35 |
| - include_package_data=True, |
36 | 35 | cmdclass={
|
37 | 36 | "build": BuildGoBinary,
|
38 | 37 | "install": PostInstallCommand,
|
39 | 38 | },
|
40 |
| - description="A stupid simple time tracker", |
41 |
| - long_description=open("README.md").read(), |
42 |
| - long_description_content_type="text/markdown", |
43 |
| - classifiers=[ |
44 |
| - "Programming Language :: Go", |
45 |
| - "License :: OSI Approved :: MIT License", |
46 |
| - "Operating System :: OS Independent", |
47 |
| - ], |
48 |
| - python_requires=">=3.6", |
49 | 39 | )
|
0 commit comments