ProxmoxVED/.github/workflows/move-to-main-repo.yaml
2025-03-11 15:58:23 +01:00

138 lines
4.5 KiB
YAML

name: Move new Scripts to Main Repository
on:
workflow_dispatch:
permissions:
deployments: write
contents: write
statuses: write
actions: write
checks: write
issues: write
pull-requests: write
jobs:
move-to-main-repo:
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: community-scripts
repositories: |
ProxmoxVE
ProxmoxVED
- name: Check GitHub authentication
run: gh auth status
env:
GH_TOKEN: ${{ secrets.GH_MERGE_PAT }}
- name: Checkout ProxmoxVED (Source Repo)
uses: actions/checkout@v4
with:
ref: main
repository: community-scripts/ProxmoxVED
token: ${{ secrets.GH_MERGE_PAT }}
- 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'."
exit 1
else
script_name=$(echo "$filtered_issues" | head -n 1) # Nur das erste Issue nehmen
script_name_lowercase=$(echo "$script_name" | tr '[:upper:]' '[:lower:]' | tr -d ' ')
echo "Script Name: $script_name_lowercase"
echo "script_name=$script_name_lowercase" >> $GITHUB_ENV
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: 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: |
branch_name="add-script-${script_name//[^a-zA-Z0-9_-]/}"
echo "Using branch: $branch_name"
echo "branch_name=$branch_name" >> $GITHUB_ENV
- name: Prepare new branch for PR
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
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 checkout -b "$branch_name"
cp "ct/$script_name.sh" .
cp "install/$script_name-install.sh" .
cp "json/$script_name.json" .
git add .
git commit -m "$commit_message"
- name: Clone ProxmoxVE (Target Repo)
run: |
git clone https://x-access-token:${{ secrets.GH_MERGE_PAT }}@github.com/community-scripts/ProxmoxVE.git ProxmoxVE
cd ProxmoxVE
git checkout -b "$branch_name"
cp ../ct/$script_name.sh .
cp ../install/$script_name-install.sh .
cp ../json/$script_name.json .
git add .
git commit -m "$commit_message"
- name: Push to ProxmoxVE
run: |
cd ProxmoxVE
git push --no-thin origin "$branch_name"
- name: Create Pull Request in ProxmoxVE
env:
GITHUB_TOKEN: ${{ secrets.GH_MERGE_PAT }}
run: |
gh pr create \
--repo community-scripts/ProxmoxVE \
--head "$branch_name" \
--base main \
--title "Migrate $script_name to ProxmoxVE" \
--body "Automated migration of $script_name from ProxmoxVED to ProxmoxVE."