Skip to content

Commit

Permalink
Merge pull request #34 from num0005/build_script
Browse files Browse the repository at this point in the history
Create and release a zip file ready for extraction using Github Actions.
  • Loading branch information
num0005 authored Aug 30, 2021
2 parents 18d196b + cd52206 commit 82e286e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: release

on:
push:
paths-ignore:
- '*.md'
jobs:
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x # Version range or exact version of a Python version to use, using SemVer's version range syntax
- name: Do package
run: python build/create_zip.py
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: toolkit
path: output/
- name: Release to Github
uses: ncipollo/release-action@v1
with:
prerelease: false
token: '${{ secrets.GITHUB_TOKEN }}'
artifacts: output/*
tag: '${{ github.run_number }}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/__pycache__/
*.patch
output/
41 changes: 41 additions & 0 deletions build/create_zip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Helper script to create a zip file that can just be extracted to the blender addon folder
SPDX-License-Identifier: MIT
"""

from zipfile import ZipFile, ZIP_DEFLATED
import io
import os
import subprocess
from pathlib import Path

# grab the version from git
git_version = subprocess.check_output(["git", "describe", "--always"]).strip().decode()
print(f"version: {git_version}")

# create the output directory
Path("output").mkdir(exist_ok=True)

# create zip name from git hash/version
zip_name = "halo-asset-blender-toolset-v@" + git_version + ".zip"

print(f"zip name: {zip_name}")

def write_file(zip: ZipFile, path_fs, path_zip = None):
if path_zip is None:
path_zip = path_fs
zip.write(path_fs, os.path.join("io_scene_halo", path_zip))

# Add files to zip
zip: ZipFile = ZipFile(os.path.join("output", zip_name), mode='w', compression=ZIP_DEFLATED, compresslevel=9)
write_file(zip, "LICENSE")
write_file(zip, "README.md")
for dir, subdirs, files in os.walk("io_scene_halo"):
for file in files:
fs_path = os.path.join(dir, file)
zip.write(fs_path)

zip.printdir()
zip.close()
print("done!")

0 comments on commit 82e286e

Please sign in to comment.