ProxmoxVED/.github/workflows/move-to-main-repo.yaml
2025-03-11 13:17:16 +01:00

114 lines
3.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: Checkout repository
uses: actions/checkout@v4
with:
ref: main
token: ${{ github.token }}
- 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: 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 }}
- 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: Create PR if files found
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"
git remote add upstream https://github.com/${target_repo}.git
git fetch upstream
- name: Push
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT }}
repository: community-scripts/ProxmoxVE
branch: test
force: true