-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub actions, compiling CoilSnake for Windows on pushes and PRs (…
…#287) * First test of github actions * Apparently the action needs requirements.txt? * Action failed because PyInstaller was missing - install requirements * Add support for writing Git commit during setup.py and displaying it * Add git_commit.py to gitignore and fix setup.py * Add more error handling, and change format of version number * Update GitHub action to set BUILD_GIT_COMMIT env var * Separate writing the Git commit into its own script * Rename output executable to contain the version * Update policy on when a build occurs
- Loading branch information
Showing
7 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Build CoilSnake with Win32 Py3.8 | ||
|
||
on: | ||
push: # by vote, we'll only build on pushes to master | ||
branches: [ master ] | ||
pull_request: # build on pull request against any branch | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.8' | ||
cache: 'pip' # caching pip dependencies | ||
architecture: 'x86' | ||
- name: Install requirements | ||
run: pip install -r requirements.txt | ||
- name: Write build Git commit info | ||
run: python set_git_commit.py --write | ||
- name: Build CoilSnake | ||
run: python setup.py install | ||
- name: Build .exe | ||
run: python setup_exe.py | ||
- name: Rename .exe | ||
run: python rename_exe_with_version.py | ||
- name: Upload .exe | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: CoilSnake (Py3.8-win32) | ||
path: dist/CoilSnake*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
/coilsnake/assets/ccc/ccc | ||
/coilsnake/assets/ccc/lib/*.ccs | ||
.DS_store | ||
git_commit.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python | ||
import glob | ||
import os | ||
from coilsnake.ui.information import VERSION | ||
|
||
def rename_exe(): | ||
exe_paths = glob.glob('dist/CoilSnake*') | ||
if not exe_paths: | ||
print("Couldn't locate CoilSnake executable. Doing nothing...") | ||
return | ||
for exe_path in exe_paths: | ||
new_exe_path = exe_path.replace('CoilSnake', f'CoilSnake-{VERSION}') | ||
if exe_path != new_exe_path: | ||
os.rename(exe_path, new_exe_path) | ||
|
||
if __name__ == '__main__': | ||
rename_exe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pip>=19.0 | ||
pyinstaller>=6.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
GITHUB_SHA_ENV_VAR_NAME = 'GITHUB_SHA' | ||
COILSNAKE_GIT_COMMIT_PY_PATH = 'coilsnake/ui/git_commit.py' | ||
|
||
def get_git_commit(): | ||
# Try looking at the GitHub variable | ||
revision = os.environ.get(GITHUB_SHA_ENV_VAR_NAME) | ||
# If it wasn't set, run against head | ||
if not revision: | ||
revision = "HEAD" | ||
# Try to run git rev-parse to get the short hash | ||
try: | ||
print('Getting short hash for Git revision:', revision) | ||
git_commit = subprocess.check_output(['git', 'rev-parse', '--short', revision]) | ||
return git_commit.strip().decode() | ||
except Exception as e: | ||
print('Error when running rev-parse:', e, sep='\n') | ||
# In case of error, return None | ||
return None | ||
|
||
def write_git_commit(git_commit): | ||
# Force git_commit to be a value, or None | ||
git_commit = git_commit or None | ||
git_commit_file_text = f'GIT_COMMIT = {git_commit!r}' | ||
print(f"Writing '{COILSNAKE_GIT_COMMIT_PY_PATH}' with: {git_commit_file_text}") | ||
with open(COILSNAKE_GIT_COMMIT_PY_PATH, 'w') as f: | ||
print(git_commit_file_text, file=f) | ||
|
||
if __name__ == '__main__': | ||
git_commit = get_git_commit() | ||
print('Found Git commit short hash:', git_commit) | ||
if '--write' in sys.argv[1:]: | ||
write_git_commit(git_commit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters