Skip to content

[Dispatch] Create Plugin Template #23

[Dispatch] Create Plugin Template

[Dispatch] Create Plugin Template #23

name: "[Dispatch] Create Plugin Template"
on:
workflow_dispatch:
inputs:
resource_type:
description: 'plugin type ex) (inventory.Collector, cost-analysis.DataSource, monitoring.Webhook, notification.Notification ...)'
required: true
default: 'inventory.Collector'
core-version:
description: 'core version'
required: true
default: '2.0'
jobs:
owner_check:
if: github.repository_owner == 'forest-extension'
runs-on: ubuntu-latest
steps:
- run: echo ${{ github.repository_owner }}
template:
needs: owner_check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: set git user
run: git config --global user.email admin@forest-extension
- name: set python
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: git clone actions repository
run: |
git clone https://github.com/forest-extension/actions.git
cd actions
- name: install requirements
run: pip install --upgrade -r pkg/pip_requirements.txt
- name: set PAT_TOKEN env
run: echo "PAT_TOKEN=$(echo ${{ secrets.PAT_TOKEN }})" >> $GITHUB_ENV
- name: create template with topics
run: |
python src/main.py template --dest ${{ github.repository }} --resource-type ${{ github.event.inputs.resource_type }} --core-version ${{ github.event.inputs.core-version }}
- name: extract service from resource type to lower case
run: |
echo "PLUGIN_PACKAGE=$(echo ${{ github.event.inputs.resource_type }} | cut -d '.' -f1 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: extract resource from resource type to lower case
run: |
echo "SPACEONE_RESOURCE=$(echo ${{ github.event.inputs.resource_type }} | cut -d '.' -f2 | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g'| tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: install spaceone package
run: |
pip install --upgrade pip
pip install --upgrade spaceone-core
pip install --upgrade --pre spaceone-$PLUGIN_PACKAGE
- name: Use Environment Variable
# Replace '-' with '_' in the SERVICE environment variable
run: echo "SPACEONE_SERVICE=${PLUGIN_PACKAGE//-/_}" >> $GITHUB_ENV
- name: change directory to original repository
run: cd ..
- name: create plugin template
run: |
spaceone create-project -s spaceone.$SPACEONE_SERVICE.plugin.$SPACEONE_RESOURCE.skeleton src/plugin
- name: commit changes
uses: EndBug/add-and-commit@v7
with:
add: '.'
author_name: github-actions
- name: push changes
uses: ad-m/github-push-action@master
with:
repository: forest-extension/${{ github.event.inputs.dest }}
github_token: ${{ secrets.PAT_TOKEN }}
branch: master