Skip to content

Commit de86c72

Browse files
committed
Initial Attempt at CI
1 parent 9e1cce8 commit de86c72

File tree

5 files changed

+250
-1
lines changed

5 files changed

+250
-1
lines changed

.github/scripts/generate_tag.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# Copyright 2020 Efabless Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
import os
17+
import sys
18+
19+
from gh import gh
20+
21+
sys.path.insert(0, os.getcwd())
22+
23+
import volare # noqa: E402
24+
25+
print("Getting tags…")
26+
27+
latest_tag = None
28+
latest_tag_commit = None
29+
tags = [pair[1] for pair in gh.volare.tags]
30+
31+
tag_exists = volare.__version__ in tags
32+
33+
if tag_exists:
34+
print("Tag already exists. Leaving NEW_TAG unaltered.")
35+
else:
36+
new_tag = volare.__version__
37+
38+
print("Found new tag %s." % new_tag)
39+
gh.export_env("NEW_TAG", new_tag)

.github/scripts/gh.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2020 Efabless Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
import os
16+
import subprocess
17+
from types import SimpleNamespace
18+
19+
20+
def export_env_default(key, value):
21+
with open(os.getenv("GITHUB_ENV"), "a") as f:
22+
f.write("%s=%s\n" % (key, value))
23+
24+
25+
export_env = export_env_default
26+
27+
28+
class Repo(object):
29+
def __init__(self, name, url, branch_rx=None, extraction_rx=None):
30+
print("[Repo Object] Initializing repo %s with URL %s…" % (name, url))
31+
self.name = name
32+
self.url = url
33+
self.commit = None
34+
self.branch_rx = branch_rx
35+
self.extraction_rx = extraction_rx
36+
37+
self._latest_commit = None
38+
self._branches = None
39+
self._tags = None
40+
41+
@property
42+
def latest_commit(self):
43+
if self._latest_commit is None:
44+
print("[Repo Object] Fetching latest commit for %s…" % self.name)
45+
p = subprocess.check_output(["git", "ls-remote", self.url]).decode("utf8")
46+
for line in p.split("\n"):
47+
if "HEAD" in line:
48+
self._latest_commit = line[:40]
49+
return self._latest_commit
50+
51+
@property
52+
def branches(self):
53+
if self._branches is None:
54+
print("[Repo Object] Fetching branches for %s…" % self.name)
55+
p = subprocess.check_output(
56+
["git", "ls-remote", "--heads", self.url]
57+
).decode("utf8")
58+
branches = []
59+
for line in p.split("\n"):
60+
if line.strip() == "":
61+
continue
62+
63+
match = line.split()
64+
65+
hash = match[0]
66+
name = match[1]
67+
68+
branches.append((hash, name))
69+
self._branches = branches
70+
return self._branches
71+
72+
@property
73+
def tags(self):
74+
if self._tags is None:
75+
print("[Repo Object] Fetching tags for %s…" % self.name)
76+
p = subprocess.check_output(
77+
["git", "ls-remote", "--tags", "--sort=creatordate", self.url]
78+
).decode("utf8")
79+
80+
tags = []
81+
for line in p.split("\n"):
82+
if line.strip() == "":
83+
continue
84+
85+
match = line.split()
86+
87+
hash = match[0]
88+
name = match[1].split("/")[2]
89+
90+
tags.append((hash, name))
91+
self._tags = tags
92+
return self._tags
93+
94+
def out_of_date(self):
95+
return self.commit != self.latest_commit
96+
97+
98+
if os.getenv("GITHUB_ACTIONS") != "true":
99+
dn = os.path.dirname
100+
git_directory = dn(dn(dn(os.path.realpath(__file__))))
101+
102+
def git_command(*args):
103+
return subprocess.check_output(["git"] + list(args), cwd=git_directory).decode(
104+
"utf-8"
105+
)[:-1]
106+
107+
repo_url = git_command("remote", "get-url", "origin")
108+
branch = git_command("branch", "--show-current")
109+
110+
os.environ["REPO_URL"] = repo_url
111+
os.environ["BRANCH_NAME"] = branch
112+
os.environ["GITHUB_WORKSPACE"] = git_directory
113+
os.environ["GITHUB_EVENT_NAME"] = "workspace_dispatch"
114+
os.environ["GITHUB_RUN_ID"] = "mock_gha_run"
115+
116+
def export_env_alt(key, value):
117+
os.environ[key] = value
118+
print("Setting ENV[%s] to %s..." % (key, value))
119+
120+
export_env = export_env_alt
121+
122+
origin = os.getenv("REPO_URL")
123+
repo = Repo("parselib", origin)
124+
125+
# public
126+
gh = SimpleNamespace(
127+
**{
128+
"run_id": os.getenv("GITHUB_RUN_ID"),
129+
"origin": origin,
130+
"branch": os.getenv("BRANCH_NAME"),
131+
"root": os.getenv("GITHUB_WORKSPACE"),
132+
"pdk": os.getenv("PDK_ROOT"),
133+
"tool": os.getenv("TOOL"),
134+
"event": SimpleNamespace(**{"name": os.getenv("GITHUB_EVENT_NAME")}),
135+
"export_env": export_env,
136+
"Repo": Repo,
137+
"parselib": repo,
138+
}
139+
)

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
# Events that trigger workflow
4+
on:
5+
push:
6+
branches:
7+
- "*"
8+
pull_request:
9+
10+
jobs:
11+
build_wheels:
12+
name: Build Wheels ( ${{matrix.os}} )
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: [ubuntu-20.04, windows-2019, macos-11]
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
recursive: True
22+
- uses: actions/setup-python@v3
23+
- name: Install cibuildwheel
24+
run: python -m pip install cibuildwheel==2.15.0
25+
- name: Build wheels
26+
run: python -m cibuildwheel --archs x86_64,aarch64 --output-dir dist
27+
- uses: actions/upload-artifact@v3
28+
with:
29+
path: ./dist/*.whl
30+
push_to_pypi:
31+
name: Build (and publish, if applicable)
32+
runs-on: ubuntu-20.04
33+
needs: build_wheels
34+
steps:
35+
- name: Check out Git repository
36+
uses: actions/checkout@v3
37+
with:
38+
fetch-depth: 0
39+
recursive: True
40+
- name: Export Repo URL
41+
run: echo "REPO_URL=https://github.com/${{ github.repository }}" >> $GITHUB_ENV
42+
- name: Export Branch Name
43+
run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
44+
- name: Set Up Python
45+
uses: actions/setup-python@v4
46+
with:
47+
python-version: "3.6"
48+
- name: Build Distribution
49+
run: |
50+
python3 ./build.py sdist
51+
- uses: actions/download-artifact@v3
52+
with:
53+
path: ./dist/*.whl
54+
- name: Set default for env.NEW_TAG
55+
run: echo "NEW_TAG=NO_NEW_TAG" >> $GITHUB_ENV
56+
- name: Check for new version
57+
if: ${{ env.BRANCH_NAME == 'main' }}
58+
run: |
59+
cd ${GITHUB_WORKSPACE}/ && python3 .github/scripts/generate_tag.py
60+
- name: Tag Commit
61+
if: ${{ env.NEW_TAG != 'NO_NEW_TAG' }}
62+
uses: tvdias/[email protected]
63+
with:
64+
tag: "${{ env.NEW_TAG }}"
65+
repo-token: "${{ secrets.MY_TOKEN }}"
66+
- name: Publish
67+
if: ${{ env.NEW_TAG != 'NO_NEW_TAG' }}
68+
uses: pypa/gh-action-pypi-publish@release/v1
69+
with:
70+
password: ${{ secrets.PYPI_API_TOKEN }}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def run(self) -> None:
2929
setup(
3030
name=module_name,
3131
packages=["libparse"],
32-
version="0.1.5",
32+
version="0.2.0",
3333
description="Python wrapper around Yosys' libparse module",
3434
long_description=open("Readme.md").read(),
3535
long_description_content_type="text/markdown",

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ with pkgs; mkShell {
77
clang
88
python3Full
99
valgrind
10+
twine
1011
];
1112
}

0 commit comments

Comments
 (0)