mirror of
				https://github.com/community-scripts/ProxmoxVE.git
				synced 2025-11-04 10:22:50 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			160 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			160 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
name: Run Scripts on PVE Node for testing
 | 
						|
permissions:
 | 
						|
    pull-requests: write
 | 
						|
on:
 | 
						|
  pull_request_target:
 | 
						|
    branches:
 | 
						|
      - main
 | 
						|
    paths:
 | 
						|
      - 'install/**.sh'
 | 
						|
      - 'ct/**.sh'
 | 
						|
 | 
						|
jobs:
 | 
						|
  run-install-script:
 | 
						|
    runs-on: pvenode
 | 
						|
    steps:          
 | 
						|
      - name: Checkout PR branch (supports forks)
 | 
						|
        uses: actions/checkout@v4
 | 
						|
        with:
 | 
						|
          ref: ${{ github.event.pull_request.head.ref }}
 | 
						|
          repository: ${{ github.event.pull_request.head.repo.full_name }}
 | 
						|
          fetch-depth: 0          
 | 
						|
          
 | 
						|
      - name: Add Git safe directory
 | 
						|
        run: |
 | 
						|
          git config --global --add safe.directory /__w/ProxmoxVE/ProxmoxVE
 | 
						|
      
 | 
						|
      - name: Set up GH_TOKEN
 | 
						|
        env:
 | 
						|
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
						|
        run: |
 | 
						|
          echo "GH_TOKEN=${GH_TOKEN}" >> $GITHUB_ENV
 | 
						|
 | 
						|
      - name: Get Changed Files
 | 
						|
        run: |
 | 
						|
          CHANGED_FILES=$(gh pr diff ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --name-only)
 | 
						|
          CHANGED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
 | 
						|
          echo "Changed files: $CHANGED_FILES"
 | 
						|
          echo "SCRIPT=$CHANGED_FILES" >> $GITHUB_ENV
 | 
						|
        env:
 | 
						|
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}        
 | 
						|
 | 
						|
      - name: Get scripts
 | 
						|
        id: check-install-script
 | 
						|
        run: |
 | 
						|
          ALL_FILES=()
 | 
						|
          ADDED_FILES=()  
 | 
						|
          for FILE in ${{ env.SCRIPT }}; do           
 | 
						|
            if [[ $FILE =~ ^install/.*-install\.sh$ ]] || [[ $FILE =~ ^ct/.*\.sh$ ]]; then             
 | 
						|
              STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
 | 
						|
              if [[ ! " ${ADDED_FILES[@]} " =~ " $STRIPPED_NAME " ]]; then
 | 
						|
                ALL_FILES+=("$FILE")
 | 
						|
                ADDED_FILES+=("$STRIPPED_NAME")  # Mark this base file as added (without the path)
 | 
						|
              fi
 | 
						|
            fi
 | 
						|
          done
 | 
						|
          ALL_FILES=$(echo "${ALL_FILES[@]}" | xargs)
 | 
						|
          echo "$ALL_FILES"
 | 
						|
          echo "ALL_FILES=$ALL_FILES" >> $GITHUB_ENV
 | 
						|
     
 | 
						|
      - name: Run scripts
 | 
						|
        id: run-install
 | 
						|
        continue-on-error: true
 | 
						|
        run: |
 | 
						|
          set +e  
 | 
						|
          #run for each files in /ct
 | 
						|
          for FILE in ${{ env.ALL_FILES }}; do            
 | 
						|
            STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
 | 
						|
            echo "Running Test for: $STRIPPED_NAME"
 | 
						|
            if [[ $FILE =~ ^install/.*-install\.sh$ ]]; then
 | 
						|
              CT_SCRIPT="ct/$STRIPPED_NAME.sh"
 | 
						|
              if [[ ! -f $CT_SCRIPT ]]; then
 | 
						|
                echo "No CT script found for $STRIPPED_NAME"
 | 
						|
                ERROR_MSG="No CT script found for $FILE"
 | 
						|
                echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
 | 
						|
                continue
 | 
						|
              fi
 | 
						|
                echo "Found CT script for $STRIPPED_NAME"
 | 
						|
                chmod +x "$CT_SCRIPT"
 | 
						|
                RUNNING_FILE=$CT_SCRIPT
 | 
						|
            elif [[ $FILE =~ ^ct/.*\.sh$ ]]; then
 | 
						|
              INSTALL_SCRIPT="install/$STRIPPED_NAME-install.sh"
 | 
						|
              if [[ ! -f $INSTALL_SCRIPT ]]; then
 | 
						|
                echo "No install script found for $STRIPPED_NAME"
 | 
						|
                ERROR_MSG="No install script found for $FILE"
 | 
						|
                echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
 | 
						|
                continue
 | 
						|
              fi                
 | 
						|
                echo "Found install script for $STRIPPED_NAME"
 | 
						|
                chmod +x "$INSTALL_SCRIPT"
 | 
						|
                RUNNING_FILE=$FILE
 | 
						|
            fi
 | 
						|
            git remote add community-scripts https://github.com/community-scripts/ProxmoxVE.git
 | 
						|
            git fetch community-scripts
 | 
						|
            rm -f .github/workflows/scripts/app-test/pr-build.func || true
 | 
						|
            rm -f .github/workflows/scripts/app-test/pr-install.func || true
 | 
						|
            rm -f .github/workflows/scripts/app-test/pr-alpine-install.func || true
 | 
						|
            rm -f .github/workflows/scripts/app-test/pr-create-lxc.sh || true
 | 
						|
            git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-build.func
 | 
						|
            git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-install.func
 | 
						|
            git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-alpine-install.func
 | 
						|
            git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-create-lxc.sh
 | 
						|
            chmod +x $RUNNING_FILE         
 | 
						|
            chmod +x .github/workflows/scripts/app-test/pr-create-lxc.sh
 | 
						|
            chmod +x .github/workflows/scripts/app-test/pr-install.func
 | 
						|
            chmod +x .github/workflows/scripts/app-test/pr-alpine-install.func
 | 
						|
            chmod +x .github/workflows/scripts/app-test/pr-build.func
 | 
						|
            sed -i 's|source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)|source .github/workflows/scripts/app-test/pr-build.func|g' "$RUNNING_FILE"
 | 
						|
            echo "Executing $RUNNING_FILE"
 | 
						|
            ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
 | 
						|
            echo "Finished running $FILE"
 | 
						|
            if [ -n "$ERROR_MSG" ]; then
 | 
						|
              echo "ERROR in $STRIPPED_NAME: $ERROR_MSG"
 | 
						|
              echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
 | 
						|
            fi
 | 
						|
          done
 | 
						|
          set -e  # Restore exit-on-error
 | 
						|
      
 | 
						|
      - name: Cleanup PVE Node
 | 
						|
        run: |
 | 
						|
          containers=$(pct list | tail -n +2 | awk '{print $0 " " $4}' | awk '{print $1}')
 | 
						|
        
 | 
						|
          for container_id in $containers; do
 | 
						|
            status=$(pct status $container_id | awk '{print $2}')
 | 
						|
            if [[ $status == "running" ]]; then
 | 
						|
                pct stop $container_id
 | 
						|
                pct destroy $container_id
 | 
						|
            fi            
 | 
						|
          done   
 | 
						|
 | 
						|
      - name: Post error comments
 | 
						|
        run: |
 | 
						|
          ERROR="false"
 | 
						|
          SEARCH_LINE=".github/workflows/scripts/app-test/pr-build.func: line 253:"
 | 
						|
          for FILE in ${{ env.ALL_FILES }}; do
 | 
						|
            STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
 | 
						|
            if [[ ! -f result_$STRIPPED_NAME.log ]]; then
 | 
						|
              continue
 | 
						|
            fi
 | 
						|
            ERROR_MSG=$(cat result_$STRIPPED_NAME.log)
 | 
						|
      
 | 
						|
            if [ -n "$ERROR_MSG" ]; then
 | 
						|
              CLEANED_ERROR_MSG=$(echo "$ERROR_MSG" | sed "s|$SEARCH_LINE.*||")
 | 
						|
              echo "Posting error message for $FILE"
 | 
						|
              echo ${CLEANED_ERROR_MSG}
 | 
						|
              gh pr comment ${{ github.event.pull_request.number }} \
 | 
						|
                --repo ${{ github.repository }} \
 | 
						|
                --body ":warning: The script _**$FILE**_ failed with the following message: <br> <div><strong>${CLEANED_ERROR_MSG}</strong></div>"
 | 
						|
 | 
						|
              
 | 
						|
              ERROR="true"
 | 
						|
            fi
 | 
						|
          done
 | 
						|
          echo "ERROR=$ERROR" >> $GITHUB_ENV
 | 
						|
        env:
 | 
						|
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 | 
						|
 | 
						|
      - name: Fail if error
 | 
						|
        if: ${{ env.ERROR == 'true' }}
 | 
						|
        run: exit 1 
 |