name: Move new Scripts to Main Repository on: workflow_dispatch: issues: types: - labeled permissions: contents: write issues: write pull-requests: write jobs: move-to-main-repo: runs-on: ubuntu-latest if: github.event.label.name == 'Migration To ProxmoxVE' && github.repository == 'community-scripts/ProxmoxVED' steps: - name: Generate a token id: app-token uses: actions/create-github-app-token@v2 with: app-id: ${{ vars.PUSH_MAIN_APP_ID }} private-key: ${{ secrets.PUSH_MAIN_APP_SECRET }} owner: community-scripts repositories: | ProxmoxVE ProxmoxVED - name: Checkout ProxmoxVED (Source Repo) uses: actions/checkout@v4 with: ref: main repository: community-scripts/ProxmoxVED token: ${{ secrets.GH_MERGE_PAT }} - name: List Issues and Extract Script Type id: list_issues env: GH_TOKEN: ${{ github.token }} ISSUE_JSON: ${{ toJson(github.event.issue) }} run: | echo "Resolving issue with label Migration To ProxmoxVE" if [[ "${{ github.event_name }}" == "issues" ]]; then # For labeled issue events, use the exact issue from event payload. filtered_issue="$ISSUE_JSON" else # Fallback for workflow_dispatch: query explicitly by label and raise limit. raw_output=$(gh issue list \ --label "Migration To ProxmoxVE" \ --state open \ --limit 500 \ --json title,labels,number,body) filtered_issue=$(echo "$raw_output" | jq -c '.[0]') fi if [[ "$filtered_issue" == "null" ]] || [[ -z "$filtered_issue" ]]; then echo "No issues found with label 'Migration To ProxmoxVE'." exit 1 fi issue_title=$(echo "$filtered_issue" | jq -r '.title') issue_nr=$(echo "$filtered_issue" | jq -r '.number') issue_body=$(echo "$filtered_issue" | jq -r '.body') # script_name (slug): from the "Name of the Script" field in the issue body, # normalized to the repo's lowercase + spaces->dashes convention # (e.g. "Alpine Cinny" -> "alpine-cinny"). Falls back to the title if absent. name_raw=$(printf '%s\n' "$issue_body" \ | sed -n '/^###[[:space:]]*Name of the Script/,/^###/p' \ | sed '1d;/^###/d;/^[[:space:]]*$/d' | head -n1) if [ -z "$name_raw" ]; then name_raw="$issue_title" fi script_name=$(echo "$name_raw" | tr -d '\r' | tr '[:upper:]' '[:lower:]' | sed 's/[[:space:]]\+/-/g') echo "Script Name: $script_name" echo "Issue Title: $issue_title" echo "Issue Number: $issue_nr" # Detect script type from issue body if echo "$issue_body" | grep -qi "CT (LXC Container)"; then script_type="ct" elif echo "$issue_body" | grep -qi "VM (Virtual Machine)"; then script_type="vm" elif echo "$issue_body" | grep -qi "Addon (tools/addon)"; then script_type="addon" elif echo "$issue_body" | grep -qi "PVE Tool (tools/pve)"; then script_type="pve" else # Fallback detection by filename pattern if [[ "$script_name" == *"-vm"* ]]; then script_type="vm" else script_type="ct" fi fi echo "Script Type: $script_type" echo "script_name=$script_name" >> $GITHUB_OUTPUT echo "issue_nr=$issue_nr" >> $GITHUB_OUTPUT echo "script_type=$script_type" >> $GITHUB_OUTPUT echo "issue_title=$issue_title" >> $GITHUB_OUTPUT { echo "issue_body<> $GITHUB_OUTPUT - name: Check if script files exist id: check_files run: | script_name="${{ steps.list_issues.outputs.script_name }}" script_type="${{ steps.list_issues.outputs.script_type }}" files_found="true" missing_files="" # Check files based on script type case "$script_type" in ct) if [[ ! -f "ct/${script_name}.sh" ]]; then echo "ct file not found: ct/${script_name}.sh" files_found="false" missing_files+="ct/${script_name}.sh " fi if [[ ! -f "install/${script_name}-install.sh" ]]; then echo "install file not found: install/${script_name}-install.sh" files_found="false" missing_files+="install/${script_name}-install.sh " fi ;; vm) if [[ ! -f "vm/${script_name}.sh" ]]; then echo "vm file not found: vm/${script_name}.sh" files_found="false" missing_files+="vm/${script_name}.sh " fi ;; addon) if [[ ! -f "tools/addon/${script_name}.sh" ]]; then echo "addon file not found: tools/addon/${script_name}.sh" files_found="false" missing_files+="tools/addon/${script_name}.sh " fi ;; pve) if [[ ! -f "tools/pve/${script_name}.sh" ]]; then echo "pve tool file not found: tools/pve/${script_name}.sh" files_found="false" missing_files+="tools/pve/${script_name}.sh " fi ;; esac echo "files_found=$files_found" >> $GITHUB_OUTPUT echo "missing=$missing_files" >> $GITHUB_OUTPUT - name: Comment if not all Files found if: steps.check_files.outputs.files_found == 'false' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | script_name="${{ steps.list_issues.outputs.script_name }}" script_type="${{ steps.list_issues.outputs.script_type }}" gh issue comment ${{ steps.list_issues.outputs.issue_nr }} --body "Not all required files were found for **$script_name** (type: $script_type). Please check the files and try again. Missing: ${{ steps.check_files.outputs.missing }}" exit 1 - name: Get GitHub App User ID id: get-user-id run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ steps.app-token.outputs.token }} - name: Configure Git User run: | git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' - name: Prepare branch name run: | script_name="${{ steps.list_issues.outputs.script_name }}" timestamp=$(date +%s) branch_name="add-script-${script_name//[^a-zA-Z0-9_-]/}-${timestamp}" echo "Using branch: $branch_name" echo "branch_name=$branch_name" >> $GITHUB_ENV - name: Clone ProxmoxVE and Copy Files run: | script_name="${{ steps.list_issues.outputs.script_name }}" script_type="${{ steps.list_issues.outputs.script_type }}" git clone https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/community-scripts/ProxmoxVE.git ProxmoxVE cd ProxmoxVE # Check if branch already exists remotely and delete it if git ls-remote --exit-code --heads origin "$branch_name" >/dev/null 2>&1; then echo "Branch $branch_name already exists remotely, deleting it..." git push origin --delete "$branch_name" || true fi # Check if files already exist in target repo case "$script_type" in ct) [[ -f "ct/${script_name}.sh" ]] && echo "ct file already exists in ProxmoxVE" && exit 1 [[ -f "install/${script_name}-install.sh" ]] && echo "install file already exists in ProxmoxVE" && exit 1 ;; vm) [[ -f "vm/${script_name}.sh" ]] && echo "vm file already exists in ProxmoxVE" && exit 1 ;; addon) [[ -f "tools/addon/${script_name}.sh" ]] && echo "addon file already exists in ProxmoxVE" && exit 1 ;; pve) [[ -f "tools/pve/${script_name}.sh" ]] && echo "pve tool file already exists in ProxmoxVE" && exit 1 ;; esac git checkout -b "$branch_name" # Copy files based on script type case "$script_type" in ct) cp ../ct/${script_name}.sh ct/ cp ../ct/headers/${script_name} ct/headers/ 2>/dev/null || true cp ../install/${script_name}-install.sh install/ # Update URLs in ct script sed -i "s|https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func|" ct/${script_name}.sh sed -i "s|https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/build.func|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func|" ct/${script_name}.sh sed -i "s|community-scripts/ProxmoxVED|community-scripts/ProxmoxVE|g" ct/${script_name}.sh sed -i "s|community-scripts/ProxmoxVED|community-scripts/ProxmoxVE|g" install/${script_name}-install.sh ;; vm) cp ../vm/${script_name}.sh vm/ # Update URLs in vm script sed -i "s|https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func|" vm/${script_name}.sh sed -i "s|community-scripts/ProxmoxVED|community-scripts/ProxmoxVE|g" vm/${script_name}.sh ;; addon) mkdir -p tools/addon cp ../tools/addon/${script_name}.sh tools/addon/ # Update URLs in addon script sed -i "s|community-scripts/ProxmoxVED|community-scripts/ProxmoxVE|g" tools/addon/${script_name}.sh ;; pve) mkdir -p tools/pve cp ../tools/pve/${script_name}.sh tools/pve/ # Update URLs in pve script sed -i "s|community-scripts/ProxmoxVED|community-scripts/ProxmoxVE|g" tools/pve/${script_name}.sh ;; esac git add . > /dev/null 2>&1 if git diff --cached --exit-code; then echo "No changes detected, skipping commit." exit 0 fi git commit -m "Add ${script_name} (${script_type})" - name: Push to ProxmoxVE run: | cd ProxmoxVE git push --no-thin origin "$branch_name" - name: Create Pull Request in ProxmoxVE id: create_pull_request env: GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} ISSUE_TITLE: ${{ steps.list_issues.outputs.issue_title }} ISSUE_BODY: ${{ steps.list_issues.outputs.issue_body }} ISSUE_NR: ${{ steps.list_issues.outputs.issue_nr }} run: | # PR body = original issue content + automated-migration footer printf '%s\n' "$ISSUE_BODY" > pr_body.md { echo "" echo "---" echo "Automated migration from ProxmoxVED (community-scripts/ProxmoxVED#${ISSUE_NR})." } >> pr_body.md gh pr create \ --repo community-scripts/ProxmoxVE \ --head "$branch_name" \ --base main \ --title "$ISSUE_TITLE" \ --body-file pr_body.md PR_NUMBER=$(gh pr list --repo community-scripts/ProxmoxVE --head "$branch_name" --json number --jq '.[].number') echo "PR_NUMBER=$PR_NUMBER" echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT - name: Comment on Issue if: steps.create_pull_request.outputs.pr_number env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh issue comment ${{ steps.list_issues.outputs.issue_nr }} --body "A PR has been created for ${{ steps.list_issues.outputs.script_name }}: community-scripts/ProxmoxVE#${{ steps.create_pull_request.outputs.pr_number }}" gh issue edit ${{ steps.list_issues.outputs.issue_nr }} --remove-label "Migration To ProxmoxVE" --add-label "Started Migration To ProxmoxVE"