Install Script Test #383
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Install Script Test | |
| on: | |
| schedule: | |
| # Run daily at 6:00 AM UTC | |
| - cron: '0 6 * * *' | |
| workflow_dispatch: | |
| pull_request: | |
| paths: | |
| - 'install-gh-aw.sh' | |
| - 'install-gh-aw.ps1' | |
| - 'scripts/test-install-script.sh' | |
| - '.github/workflows/install.yml' | |
| permissions: | |
| contents: read | |
| jobs: | |
| test-install: | |
| name: Test on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: read | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - ubuntu-22.04 | |
| - macos-latest | |
| - windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Test install script detection logic | |
| shell: bash | |
| run: | | |
| chmod +x scripts/test-install-script.sh | |
| ./scripts/test-install-script.sh | |
| - name: Test install script (dry run - check platform detection) | |
| shell: bash | |
| run: | | |
| chmod +x install-gh-aw.sh | |
| # Extract just the platform detection part without actually downloading | |
| OS=$(uname -s) | |
| ARCH=$(uname -m) | |
| echo "Testing platform detection:" | |
| echo " OS: $OS" | |
| echo " ARCH: $ARCH" | |
| # Run the script but capture the output before it tries to download | |
| # We'll use a fake version to test URL construction | |
| set +e | |
| # Cross-platform timeout implementation | |
| if command -v timeout > /dev/null 2>&1; then | |
| # Linux has timeout command | |
| timeout 10s ./install-gh-aw.sh v999.999.999 2>&1 | tee install-output.log || true | |
| else | |
| # macOS and others - use Perl-based timeout (available by default on macOS) | |
| perl -e 'alarm shift; exec @ARGV' 10 ./install-gh-aw.sh v999.999.999 2>&1 | tee install-output.log || true | |
| fi | |
| set -e | |
| # Verify platform was detected | |
| if grep -q "Detected OS:" install-output.log; then | |
| echo "✅ OS detection working" | |
| else | |
| echo "❌ OS detection failed" | |
| cat install-output.log | |
| exit 1 | |
| fi | |
| if grep -q "Detected architecture:" install-output.log; then | |
| echo "✅ Architecture detection working" | |
| else | |
| echo "❌ Architecture detection failed" | |
| cat install-output.log | |
| exit 1 | |
| fi | |
| if grep -q "Platform:" install-output.log; then | |
| echo "✅ Platform string constructed" | |
| else | |
| echo "❌ Platform string construction failed" | |
| cat install-output.log | |
| exit 1 | |
| fi | |
| echo "" | |
| echo "Platform detection results:" | |
| grep "Detected OS:" install-output.log || true | |
| grep "Detected architecture:" install-output.log || true | |
| grep "Platform:" install-output.log || true | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: install-test-${{ matrix.os }} | |
| path: install-output.log | |
| retention-days: 7 | |
| if-no-files-found: ignore | |
| - name: Test full install script (without dummy version) | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| chmod +x install-gh-aw.sh | |
| # Run the full installation script without version to get latest release | |
| echo "Running full installation script to test complete flow..." | |
| ./install-gh-aw.sh | |
| # Verify the installation worked | |
| INSTALL_DIR="$HOME/.local/share/gh/extensions/gh-aw" | |
| # Determine expected binary name based on OS | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| BINARY_NAME="gh-aw.exe" | |
| else | |
| BINARY_NAME="gh-aw" | |
| fi | |
| BINARY_PATH="$INSTALL_DIR/$BINARY_NAME" | |
| # Check if binary exists | |
| if [ ! -f "$BINARY_PATH" ]; then | |
| echo "❌ Binary not found at $BINARY_PATH" | |
| exit 1 | |
| fi | |
| echo "✅ Binary found at $BINARY_PATH" | |
| # Check if binary is executable | |
| if [ ! -x "$BINARY_PATH" ]; then | |
| echo "❌ Binary is not executable" | |
| exit 1 | |
| fi | |
| echo "✅ Binary is executable" | |
| # On Windows, Windows Defender may scan a newly downloaded binary before | |
| # allowing execution, causing commands to hang for several minutes. | |
| # Wrap binary invocations with a timeout so the step doesn't stall. | |
| BINARY_EXEC_TIMEOUT="" | |
| if [[ "$RUNNER_OS" == "Windows" ]] && command -v timeout &>/dev/null; then | |
| BINARY_EXEC_TIMEOUT="timeout 60" | |
| fi | |
| # Run version command to verify binary works | |
| # shellcheck disable=SC2086 | |
| if $BINARY_EXEC_TIMEOUT "$BINARY_PATH" version; then | |
| echo "✅ Binary version command works" | |
| else | |
| EXIT_CODE=$? | |
| if [ "$EXIT_CODE" -eq 124 ]; then | |
| echo "⚠️ Binary version command timed out (Windows Defender scan in progress) — skipping" | |
| else | |
| echo "❌ Binary version command failed (exit $EXIT_CODE)" | |
| exit 1 | |
| fi | |
| fi | |
| # Run help command to verify binary works | |
| # shellcheck disable=SC2086 | |
| if $BINARY_EXEC_TIMEOUT "$BINARY_PATH" --help > /dev/null 2>&1; then | |
| echo "✅ Binary help command works" | |
| else | |
| EXIT_CODE=$? | |
| if [ "$EXIT_CODE" -eq 124 ]; then | |
| echo "⚠️ Binary help command timed out (Windows Defender scan in progress) — skipping" | |
| else | |
| echo "❌ Binary help command failed (exit $EXIT_CODE)" | |
| exit 1 | |
| fi | |
| fi | |
| echo "" | |
| echo "✅ Full installation test passed!" | |
| test-install-powershell: | |
| name: Test PowerShell installer on Windows | |
| runs-on: windows-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Capture platform-detection output (expects failure for fake version) | |
| # The installer exits 1 when the nonexistent version download fails; that is | |
| # expected. continue-on-error suppresses the step failure so the next step | |
| # can assert the platform-detection messages that ran before the download. | |
| continue-on-error: true | |
| shell: pwsh | |
| run: | | |
| & ./install-gh-aw.ps1 v999.999.999 6>&1 2>&1 | Tee-Object -FilePath install-ps-output.log | |
| - name: Assert platform-detection messages from dry run | |
| shell: pwsh | |
| run: | | |
| Set-StrictMode -Version Latest | |
| if (-not (Test-Path install-ps-output.log)) { | |
| throw "Installer output file (install-ps-output.log) was not created; Tee-Object may have failed" | |
| } | |
| $outputText = Get-Content install-ps-output.log -Raw | |
| if (-not $outputText) { throw "Installer output file (install-ps-output.log) exists but is empty" } | |
| if ($outputText -notmatch "Detected OS:") { throw "OS detection failed" } | |
| if ($outputText -notmatch "Detected architecture:") { throw "Architecture detection failed" } | |
| if ($outputText -notmatch "Platform:") { throw "Platform string construction failed" } | |
| if ($outputText -notmatch "Failed to download") { throw "Installer did not report expected download failure for fake version" } | |
| - name: Test setup-cli composite action (Windows) | |
| id: setup-cli-test | |
| uses: ./actions/setup-cli | |
| with: | |
| version: latest | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Verify composite-action binary and installed-version output | |
| shell: pwsh | |
| run: | | |
| Set-StrictMode -Version Latest | |
| $ErrorActionPreference = 'Stop' | |
| $installedVersion = '${{ steps.setup-cli-test.outputs.installed-version }}' | |
| if (-not $installedVersion) { | |
| throw "installed-version output is empty; action output wiring is broken" | |
| } | |
| Write-Host "Composite action installed: $installedVersion" | |
| # Verify via gh aw commands rather than a hardcoded binary path. | |
| # `gh extension install` registers the extension under gh's own data dir | |
| # (e.g. %APPDATA%\GitHub CLI\extensions on Windows), so using `gh aw` | |
| # is the correct cross-platform verification mechanism. | |
| gh aw version 2>&1 | Write-Host | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "'gh aw version' failed with exit code $LASTEXITCODE" | |
| } | |
| gh aw --help 2>&1 | Write-Host | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "'gh aw --help' failed with exit code $LASTEXITCODE" | |
| } | |
| - name: Upload PowerShell test results | |
| if: always() | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: install-test-powershell-windows | |
| path: install-ps-output.log | |
| retention-days: 7 | |
| if-no-files-found: ignore | |
| report-failure: | |
| name: Report Installation Failures | |
| runs-on: ubuntu-latest | |
| needs: | |
| - test-install | |
| - test-install-powershell | |
| if: failure() | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Create issue on failure | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | |
| with: | |
| script: | | |
| const workflowUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
| const title = '🚨 Install Script Test Failed'; | |
| const body = `The install script test workflow failed. | |
| **Workflow Run:** ${workflowUrl} | |
| **Triggered by:** ${context.eventName} | |
| **Commit:** ${context.sha.substring(0, 7)} | |
| ## Details | |
| The install script testing workflow detected failures when testing the \`install-gh-aw.sh\` and \`install-gh-aw.ps1\` scripts across different platforms. | |
| Please review the workflow logs to identify which platform(s) failed and investigate the issue. | |
| ## Affected Platforms | |
| This workflow tests the install script on: | |
| - Ubuntu (latest and 22.04) | |
| - macOS (latest ARM and Intel-based 13) | |
| - Windows (latest) | |
| ## Next Steps | |
| 1. Check the [workflow run logs](${workflowUrl}) for detailed error messages | |
| 2. Review changes to \`install-gh-aw.sh\` and \`install-gh-aw.ps1\` that may have caused the failure | |
| 3. Test the install script locally on the affected platform(s) | |
| 4. Fix the issue and verify with \`scripts/test-install-script.sh\` | |
| --- | |
| *This issue was automatically created by the install script test workflow.*`; | |
| // Check if there's already an open issue | |
| const issues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'install-script,automated', | |
| per_page: 10 | |
| }); | |
| const existingIssue = issues.data.find(issue => | |
| issue.title === title | |
| ); | |
| if (existingIssue) { | |
| // Add a comment to existing issue | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existingIssue.number, | |
| body: `Another failure detected:\n\n${body}` | |
| }); | |
| console.log(`Added comment to existing issue #${existingIssue.number}`); | |
| } else { | |
| // Create new issue | |
| const issue = await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['bug', 'install-script', 'automated'] | |
| }); | |
| console.log(`Created new issue #${issue.data.number}`); | |
| } |