๐Ÿ“ฆ chenrui333 / playwright-scripts

playwright-scripts

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching
๐Ÿ“ฅ Clone https://github.com/chenrui333/playwright-scripts.git
HTTPS git clone https://github.com/chenrui333/playwright-scripts.git
SSH git clone git@github.com:chenrui333/playwright-scripts.git
CLI gh repo clone chenrui333/playwright-scripts
Rui Chen Rui Chen name design-decisions to github-package-automation db40eb9 1 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ claudedocs
๐Ÿ“„ .gitignore
๐Ÿ“„ bun.lock
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ setup-auth.mjs
๐Ÿ“„ README.md

GitHub Package Visibility Automation

Automate changing GitHub package visibility from private to public using Playwright and Bun.

Features

  • โœ… Automatically collects all private packages
  • โœ… Handles pagination/infinite scroll
  • โœ… Extracts and uses confirmation strings dynamically
  • โœ… Skips packages already public
  • โœ… Retry logic for transient failures
  • โœ… Detailed progress logging
  • โœ… Final summary with performance metrics
  • โœ… Uses persistent browser context (no repeated login)
  • โœ… Optional parallel processing for faster bulk operations

Prerequisites

  • Bun 1.0+ installed (install guide)
  • Playwright installed
  • Authenticated browser session saved locally

Installation

1. Install Bun (if not already installed)

# macOS, Linux, WSL
curl -fsSL https://bun.sh/install | bash

# Or using Homebrew
brew install oven-sh/bun/bun

2. Install dependencies

bun install

3. Install Playwright browsers

bunx playwright install chromium
# Or install all browsers: bunx playwright install

4. Set up authenticated browser context (one-time setup)

bun run setup

This will open a browser where you can log into GitHub. The session cookies will be saved in ./browser-data/ for future use.

Usage

Run the automation script:

bun start

Quick Reference

bun install                      # Install dependencies
bunx playwright install chromium # Install browser (one-time)
bun run setup                    # Set up authentication (one-time)
bun start                        # Run the automation

Configuration

Edit the CONFIG object in make-packages-public.mjs:

const CONFIG = {
  username: 'chenrui333',              // Your GitHub username
  packagesUrl: '...',                  // URL to your private packages
  userDataDir: './browser-data',       // Persistent auth storage
  headless: false,                     // Set true for background execution
  timeout: 30000,                      // Operation timeout (ms)
  retryAttempts: 1,                    // Retry count for failures
  retryDelay: 2000,                    // Delay between retries (ms)

  // Package filtering (set to null or '' to process all packages)
  packageFilter: 'tap/',               // Only process packages matching this prefix

  // Optional parallel processing (experimental)
  parallelProcessing: false,           // Enable to process multiple packages at once
  maxParallel: 3,                      // Max concurrent operations when parallel mode enabled
};

How It Works

  • Collect Packages: Visits your private packages page and collects all package URLs with pagination handling
  • For Each Package:
  • Navigate to settings page
  • Check if already public (skip if yes)
  • Click "Change visibility"
  • Select "Public" option
  • Extract required confirmation string from dialog
  • Type confirmation string
  • Click final confirmation button
  • Error Handling:
  • Retries transient failures once
  • Continues to next package on failure
  • Logs all errors for review
  • Summary: Prints final report with success/failure counts

Output Example

โ„น๏ธ  GitHub Package Visibility Automation Script
======================================================================

โ„น๏ธ  Collecting package links from private packages page...
โ„น๏ธ  Found 15 packages so far...
โœ… Collected 15 total package(s)

โ„น๏ธ  Starting visibility change for 15 package(s)...

๐Ÿ“ฆ Progress: 1/15
โ„น๏ธ  Processing package: my-package
โ„น๏ธ  Confirmation string required: "my-package"
โœ… Successfully changed my-package to public (3.2s)

๐Ÿ“ฆ Progress: 2/15
โ„น๏ธ  Processing package: another-pkg
โš ๏ธ  Package another-pkg is already public, skipping

...

======================================================================
โ„น๏ธ  SUMMARY
======================================================================
Total packages found:     15
Successfully changed:     12
Already public (skipped): 2
Failed:                   1
======================================================================

โšก Performance Metrics:
   Total time:           48.5s
   Avg per package:      3.4s
   Fastest:              2.1s
   Slowest:              5.8s
======================================================================

Troubleshooting

"Change visibility button not found"

Cause: GitHub UI changed or selector needs updating.

Fix: Inspect the settings page and update the selector in changePackageVisibility().

"Confirmation input not found"

Cause: Modal didn't load or selector mismatch.

Fix: Increase delay after clicking "Change visibility" button or update selector.

Authentication issues

Cause: Browser context expired or cookies invalid.

Fix: Re-run bun run setup to refresh authentication.

Rate limiting

Cause: Processing packages too quickly.

Fix: Increase delay between packages in main loop (currently 1000ms).

Security Notes

  • No API keys required: Uses browser automation only
  • Local authentication: Cookies stored locally in ./browser-data/
  • No hardcoded credentials: Manual login preserved between runs
  • Read-only except visibility: Script only modifies package visibility settings

Limitations

  • Only works for packages where you have admin access
  • Requires packages to be in container registry format
  • GitHub must not have CAPTCHA or 2FA challenges during automation
  • Browser must remain visible if headless: false (recommended for monitoring)
  • Parallel mode may trigger rate limits with many packages (use cautiously)

Contributing

Feel free to open issues or submit pull requests if you encounter GitHub UI changes or want to add features.

License

MIT


Disclaimer: This tool automates browser interactions with GitHub's UI. Use responsibly and in accordance with GitHub's Terms of Service. Automated actions should not violate rate limits or abuse GitHub's services