Add pack action (#420)

* Create pack.py
* Create pack-plugins.yml
* Delete .github/workflows/release.yml
This commit is contained in:
Alexander Trofimov
2025-07-07 20:35:33 +03:00
committed by GitHub
parent 57a885b2d3
commit 1d3b26cd00
3 changed files with 90 additions and 38 deletions

58
.github/workflows/pack-plugins.yml vendored Normal file
View File

@ -0,0 +1,58 @@
name: Pack Plugins and Create Release
on:
push:
branches: [ master ]
jobs:
pack-plugins:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get latest tag
id: get_tag
run: |
git fetch --tags
latest=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n1)
echo "Latest tag: $latest"
if [[ -z "$latest" ]]; then
echo "tag=v0.0.0" >> "$GITHUB_OUTPUT"
else
echo "tag=$latest" >> "$GITHUB_OUTPUT"
fi
- name: Bump patch version
id: bump_tag
run: |
old="${{ steps.get_tag.outputs.tag }}"
IFS='.' read -r major minor patch <<< "${old#v}"
new="v$major.$minor.$((patch+1))"
echo "New tag: $new"
echo "new_tag=$new" >> "$GITHUB_OUTPUT"
- name: Create Git tag
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag ${{ steps.bump_tag.outputs.new_tag }}
git push origin ${{ steps.bump_tag.outputs.new_tag }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Pack plugins
run: |
python packer/pack.py
- name: Upload GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.bump_tag.outputs.new_tag }}
name: Release ${{ steps.bump_tag.outputs.new_tag }}
body: Auto-generated release from push to `${{ github.ref_name }}`
files: artifacts/*.plugin

View File

@ -1,38 +0,0 @@
### This workflow release plugin after tag was pushed ###
name: Plugins release
on:
workflow_call:
push:
tags:
- "v*"
env:
REPO_NAME: ${{ github.event.repository.name }}
jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get Tag Name
id: tag_name
run: |
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
- name: Zip up files
run: |
PLUGIN=$(echo ${{ env.REPO_NAME }} | sed 's/plugin-//')
zip -r $PLUGIN-${{ steps.tag_name.outputs.SOURCE_TAG }}.plugin . -x *.git*
- name: Release plugin
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ steps.tag_name.outputs.SOURCE_TAG }}"
title: "${{ steps.tag_name.outputs.SOURCE_TAG }}"
prerelease: false
files: "*.plugin"

32
packer/pack.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
import os
import shutil
from pathlib import Path
def pack_plugins():
content_dir = "sdkjs-plugins/content/"
if not os.path.exists(content_dir):
print(f"Content directory {content_dir} does not exist")
return
artifacts_dir = f"artifacts"
os.makedirs(artifacts_dir, exist_ok=True)
for plugin_name in os.listdir(content_dir):
plugin_path = os.path.join(content_dir, plugin_name)
zip_file = os.path.join(artifacts_dir, f"{plugin_name}")
# Create zip
zip_path = shutil.make_archive(zip_file, 'zip', plugin_path)
# Rename to plugin
plugin_path = Path(zip_path).with_suffix(".plugin")
Path(zip_path).rename(plugin_path)
print(f"Created: {plugin_name}")
return
if __name__ == "__main__":
pack_plugins()