Add the CI github workflow
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class SetupVersion:
|
||||||
|
def __init__(self, version: str, folder: str):
|
||||||
|
self.addon_file = Path(os.getcwd(), folder, '__init__.py')
|
||||||
|
self.tag = self.conform_tag_to_blender(version)
|
||||||
|
self.update_addon_init()
|
||||||
|
|
||||||
|
def update_addon_init(self):
|
||||||
|
"""Simple function to update the bl_info to set the Git tag release"""
|
||||||
|
regex, update = r'[0-9]{1,2}\, [0-9]{1,2}\, [0-9{1,2}]', ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(self.addon_file, "r") as f:
|
||||||
|
i = 0
|
||||||
|
lines = f.readlines()
|
||||||
|
for line in lines:
|
||||||
|
if ' \'version\':' in line:
|
||||||
|
print('Actual set : ', line)
|
||||||
|
line = re.sub(regex, self.tag, line)
|
||||||
|
lines[i] = line
|
||||||
|
update = lines
|
||||||
|
print('Update version : ', line)
|
||||||
|
break
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
with open(self.addon_file, 'w') as f:
|
||||||
|
f.writelines(update)
|
||||||
|
|
||||||
|
except FileNotFoundError as exception:
|
||||||
|
print(f'Can\'t find a file :\n\t{exception}')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def conform_tag_to_blender(version):
|
||||||
|
"""This function convert all '.' with a coma and remove the alphabetic entry, to be ready with blender 'bl
|
||||||
|
info' value """
|
||||||
|
version = re.sub(r'\.', ', ', version)
|
||||||
|
version = version.replace('v', '')
|
||||||
|
|
||||||
|
return version
|
||||||
|
|
||||||
|
|
||||||
|
class SetupError(Exception):
|
||||||
|
"""No tag or folder name valid"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
tag, name = '', ''
|
||||||
|
|
||||||
|
for value in sys.argv:
|
||||||
|
if '--tag' in value:
|
||||||
|
tag = value.replace('--tag=', '')
|
||||||
|
print(f'[UpdateVersion] Set the tag {tag}')
|
||||||
|
|
||||||
|
if 'name' in value:
|
||||||
|
name = value.replace('--name=', '')
|
||||||
|
print(f'[UpdateVersion] Set the folder {name}')
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not tag or not name:
|
||||||
|
raise SetupError
|
||||||
|
else:
|
||||||
|
print(f'[UpdateVersion] Set the tag {tag}, for "{name}"')
|
||||||
|
bump = SetupVersion(tag, name)
|
||||||
|
|
||||||
|
except SetupError:
|
||||||
|
print(SetupError.__doc__)
|
||||||
|
sys.exit(1)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
name: Test and Package feature branchs
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
[main, develop]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-test:
|
||||||
|
uses: Moderlab-Production/BlenderObjectType/.github/workflows/unit_test.yml@develop
|
||||||
|
|
||||||
|
generate-package:
|
||||||
|
uses: Moderlab-Production/BlenderObjectType/.github/workflows/package.yml@develop
|
||||||
|
with:
|
||||||
|
num_version: '0.0.0'
|
||||||
|
name_version: 'v0.0.0'
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
name: Create base release
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
[main]
|
||||||
|
types:
|
||||||
|
[opened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create-release:
|
||||||
|
name: Create a new release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
version_type: ${{ steps.bump_setup.outputs.type }}
|
||||||
|
steps:
|
||||||
|
- name: Setup bump release
|
||||||
|
id: bump_setup
|
||||||
|
run: |
|
||||||
|
if [ ${{ contains(github.event.pull_request.labels.*.name, 'release:major') }} == true ]; then
|
||||||
|
echo "::set-output name=type::major"
|
||||||
|
elif [ ${{ contains(github.event.pull_request.labels.*.name, 'release:minor') }} == true ]; then
|
||||||
|
echo "::set-output name=type::minor"
|
||||||
|
else
|
||||||
|
echo "::set-output name=type::patch"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Setup a new Semantic Version
|
||||||
|
id: semantic_setup
|
||||||
|
uses: zwaldowski/semver-release-action@v2
|
||||||
|
with:
|
||||||
|
bump: ${{ steps.bump_setup.outputs.type }}
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
dry_run: true
|
||||||
|
|
||||||
|
- name: Prepare the release
|
||||||
|
uses: ncipollo/release-action@v1.8.10
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
prerelease: true
|
||||||
|
tag: 'v${{ steps.semantic_setup.outputs.version }}'
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
name: Package Blender Plugin
|
||||||
|
|
||||||
|
# How to start the Github Action
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
num_version:
|
||||||
|
description: 'Get the desired number version'
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
default: '0.0.0'
|
||||||
|
name_version:
|
||||||
|
description: 'The release name used'
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
default: 'v0.0.0'
|
||||||
|
|
||||||
|
env:
|
||||||
|
APP_NAME: 'moderlab_type'
|
||||||
|
NAME_PACKAGE: 'moderlab_type.zip'
|
||||||
|
PATH_RELEASE: ${{ github.workspace }}\releases
|
||||||
|
|
||||||
|
|
||||||
|
# Execute this command
|
||||||
|
jobs:
|
||||||
|
make-archive:
|
||||||
|
name: Make Addon Package
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@main
|
||||||
|
|
||||||
|
# Update the bl info version
|
||||||
|
- name: Change version number in the bl info addon data
|
||||||
|
run: |
|
||||||
|
echo set this tag "${{ steps.release.outputs.tag_name }}"
|
||||||
|
python '.github/version.py' --tag=${{ inputs.num_version }} --name=${{ env.APP_NAME }}
|
||||||
|
|
||||||
|
# Make an archive with the plugin source only
|
||||||
|
- name: Create zip archive release
|
||||||
|
run: |
|
||||||
|
cd '${{ github.workspace }}/${{ env.APP_NAME }}'
|
||||||
|
zip -r '${{ github.workspace }}/releases/${{ env.NAME_PACKAGE }}' *
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: ${{ env.NAME_PACKAGE }}
|
||||||
|
path: ${{ github.workspace }}/releases/${{ env.NAME_PACKAGE }}
|
||||||
|
|
||||||
|
- name: Update the github release
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
uses: johnwbyrd/update-release@v1.0.0
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
files: '${{ github.workspace }}/releases/${{ env.NAME_PACKAGE }}'
|
||||||
|
release: ${{ inputs.name_version }}
|
||||||
|
tag: ${{ inputs.name_version }}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
name: Create addon release
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
[main]
|
||||||
|
types:
|
||||||
|
[edited, synchronize, closed]
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
init-release-data:
|
||||||
|
name: Initialize all data about the package
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
version_type: ${{ steps.bump_setup.outputs.type }}
|
||||||
|
version_number: ${{ steps.semantic_setup.outputs.version }}
|
||||||
|
version_draft: ${{ steps.semantic_setup.outputs.draft }}
|
||||||
|
version_name: v${{ steps.semantic_setup.outputs.version }}
|
||||||
|
steps:
|
||||||
|
- name: Setup bump release
|
||||||
|
id: bump_setup
|
||||||
|
run: |
|
||||||
|
if [ ${{ contains(github.event.pull_request.labels.*.name, 'release:major') }} == true ]; then
|
||||||
|
echo "::set-output name=type::major"
|
||||||
|
elif [ ${{ contains(github.event.pull_request.labels.*.name, 'release:minor') }} == true ]; then
|
||||||
|
echo "::set-output name=type::minor"
|
||||||
|
else
|
||||||
|
echo "::set-output name=type::patch"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Config the release number
|
||||||
|
# - get tag with sync PR
|
||||||
|
# - publish the release if the PR is closed
|
||||||
|
- name: Get the Semantic tag Version
|
||||||
|
id: get_semantic_setup
|
||||||
|
uses: oprypin/find-latest-tag@v1.1.0
|
||||||
|
with:
|
||||||
|
repository: Moderlab-Production/BlenderObjectType
|
||||||
|
releases-only: true
|
||||||
|
prefix: 'v'
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: From all use case, get the Tag version
|
||||||
|
id: semantic_setup
|
||||||
|
run: |
|
||||||
|
tag=${{ steps.get_semantic_setup.outputs.tag }}
|
||||||
|
if [ "${{ github.event.action }}" == "closed" ]; then
|
||||||
|
echo "::set-output name=version::${tag:1}"
|
||||||
|
echo "::set-output name=draft::false"
|
||||||
|
else
|
||||||
|
echo "::set-output name=version::${tag:1}"
|
||||||
|
echo "::set-output name=draft::true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
unit-test:
|
||||||
|
uses: Moderlab-Production/BlenderObjectType/.github/workflows/unit_test.yml@develop
|
||||||
|
|
||||||
|
release-package:
|
||||||
|
needs:
|
||||||
|
- init-release-data
|
||||||
|
uses: Moderlab-Production/BlenderObjectType/.github/workflows/package.yml@develop
|
||||||
|
with:
|
||||||
|
num_version: ${{ needs.init-release-data.outputs.version_number }}
|
||||||
|
name_version: ${{ needs.init-release-data.outputs.version_name }}
|
||||||
|
|
||||||
|
publish-release:
|
||||||
|
name: Publish the Github Release
|
||||||
|
needs:
|
||||||
|
- unit-test
|
||||||
|
- init-release-data
|
||||||
|
- release-package
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Debug the release
|
||||||
|
uses: tubone24/update_release@v1.3.1
|
||||||
|
if: ${{ needs.init-release-data.outputs.version_draft == 'true' }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
TAG_NAME: ${{ needs.init-release-data.outputs.version_name }}
|
||||||
|
with:
|
||||||
|
release_name: ${{ needs.init-release-data.outputs.version_name }}
|
||||||
|
body: ''
|
||||||
|
prerelease: ${{ needs.init-release-data.outputs.version_draft }}
|
||||||
|
|
||||||
|
- name: Publish the release
|
||||||
|
uses: tubone24/update_release@v1.3.1
|
||||||
|
if: ${{ needs.init-release-data.outputs.version_draft == 'false' }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
TAG_NAME: ${{ needs.init-release-data.outputs.version_name }}
|
||||||
|
with:
|
||||||
|
release_name: ${{ needs.init-release-data.outputs.version_name }}
|
||||||
|
body: ''
|
||||||
|
prerelease: ${{ needs.init-release-data.outputs.version_draft }}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
name: Unit Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-test:
|
||||||
|
name: Unit Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@main
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.9
|
||||||
|
- name: Setup python to execute all Unit Test
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install -r tests/requirements.txt
|
||||||
|
|
||||||
|
- name: Start all Unit Test
|
||||||
|
run: |
|
||||||
|
cd ${{ github.workspace }}
|
||||||
|
python tests/main.py
|
||||||
Reference in New Issue
Block a user