ProxmoxVED/.github/workflows/move-to-main-repo.yaml
2025-03-10 20:58:48 +01:00

96 lines
3.0 KiB
YAML

name: Move new Scripts to Main Repository
on:
workflow_dispatch:
jobs:
move-to-main-repo:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
- name: List Issues in Repository
id: list_issues
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Filtering Issues with Label MigrationTest"
raw_output=$(gh issue list --json title,labels)
echo "$raw_output"
filtered_issues=$(echo "$raw_output" | jq -r '.[] | select(.labels[]?.name == "MigrationTest") | .title')
if [ -z "$filtered_issues" ]; then
echo "No issues found with label 'MigrationTest'."
else
echo "Found script names with 'MigrationTest' label:"
echo "$filtered_issues"
for script_name in $filtered_issues; do
echo "Processing: $script_name"
script_name_lowercase=$(echo "$script_name" | tr '[:upper:]' '[:lower:]')
echo "Lowercase script name: $script_name_lowercase"
echo "script_name=$script_name_lowercase" >> $GITHUB_ENV
done
fi
- name: Check if script files exist
id: check_files
run: |
ct_file="ct/${script_name}.sh"
install_file="install/${script_name}-install.sh"
json_file="json/${script_name}.json"
if [[ -f "$ct_file" && -f "$install_file" && -f "$json_file" ]]; then
echo "All required files found."
echo "files_found=true" >> $GITHUB_ENV
else
echo "Not all required files were found."
echo "files_found=false" >> $GITHUB_ENV
fi
- name: Configure Git user
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
- name: Create PR if files found
if: env.files_found == 'true'
env:
GITHUB_TOKEN: ${{ secrets.REPO_PR_WF }}
run: |
script_name="wf-test"
target_repo="community-scripts/ProxmoxVE"
branch_name="add-script-$script_name"
commit_message="Add script files for $script_name"
git remote add upstream https://github.com/${target_repo}.git
git fetch upstream
git checkout -b "$branch_name" upstream/main
git checkout origin/main ct/$script_name.sh
git checkout origin/main install/$script_name-install.sh
git checkout origin/main json/$script_name.json
git add .
git commit -m "$commit_message"
git push origin "$branch_name"
git status
gh pr create --title "Add script files for $script_name" --body "This PR adds the $script_name script files." --base main --head "community-scripts/ProxmoxVED:$branch_name" --repo "${target_repo}"