Create main.yml #2
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
name: 'Blender Addon Build' | |
description: 'Action to automatically build the Blender add-on and store the resulting .zip artifact.' | |
author: 'Andreas Gajdosik, BlenderKit' | |
branding: | |
icon: 'box' | |
color: 'orange' | |
inputs: | |
name: | |
description: 'Name of the add-on. Used for the name of the build. If left empty, repository name will be used automatically.' | |
default: '' | |
name-suffix: | |
description: 'Name suffix. None (name.zip), commit hash (name-abc123.zip), PR number with datetime (name-PR123-date_time.zip).' | |
choices: [ 'none', 'commit-hash', 'PR-time'] | |
default: 'none' | |
build-command: | |
description: 'Command to build the add-on.' | |
default: '' | |
build-location: | |
description: 'Path to directory, which will be zipped.' | |
default: './' | |
do-checkout: | |
decsription: 'Should the action checkout the repository?' | |
choices: [ 'true', 'false' ] | |
default: 'true' | |
exclude-files: | |
description: 'List of file paths (relative to build-location) to exclude from the build. Use semicolon as separator e.g. "file1;dir/file2;dir2/file3".' | |
default: '.git' | |
runs: | |
using: "composite" | |
steps: | |
- name: Checkout Repository | |
if: ${{ inputs.do-checkout == 'true' }} | |
uses: actions/checkout@v3 | |
- name: get-date | |
run: echo "date=$(date +'%Y-%m-%d--%H-%M-%S')" >> $GITHUB_ENV | |
shell: bash | |
# PREPARE NAME | |
- name: Use name from input | |
if: ${{ inputs.name != '' }} | |
run: echo "artifact_name=${{ inputs.name }}" >> $GITHUB_ENV | |
shell: bash | |
- name: Use repository name | |
if: ${{ inputs.name == '' }} | |
run: echo "artifact_name=${{ github.event.repository.name }}" >> $GITHUB_ENV | |
shell: bash | |
# PREPARE NAME SUFFIXES | |
- name: Prepare artifact name without suffix | |
if: ${{ inputs.name-suffix == 'none' }} | |
run: echo "artifact_name=${{ env.artifact_name }}" >> $GITHUB_ENV | |
shell: bash | |
- name: Prepare artifact name with PR-time suffix | |
if: ${{ inputs.name-suffix == 'PR-time' }} | |
run: echo "artifact_name=${{ env.artifact_name }}-PR${{ github.event.number }}-${{ env.date }}" >> $GITHUB_ENV | |
shell: bash | |
- name: Prepare artifact name with commit-hash suffix | |
if: ${{ inputs.name-suffix == 'commit-hash' }} | |
run: echo "artifact_name=${{ env.artifact_name }}-${{ github.sha }}" >> $GITHUB_ENV | |
shell: bash | |
# BUILD IF PROVIDED | |
- name: Build the add-on | |
if: ${{ inputs.build-command != '' }} | |
run: | | |
${{ inputs.build-command }} | |
shell: bash | |
# REMOVE EXCLUDED FILES | |
- name: Remove excluded files | |
run: | | |
IFS=';' read -ra FILE_ARRAY <<< "${{ inputs.exclude-files }}" | |
for file in "${FILE_ARRAY[@]}"; do | |
rm -rf .//$file | |
done | |
shell: bash | |
# STORE THE BUILD | |
- name: Store the build | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.artifact_name }} | |
path: ${{ inputs.build-location }} |