diff --git a/packages/provider-github/src/__tests__/providerGitHub.test.ts b/packages/provider-github/src/__tests__/providerGitHub.test.ts index db01923a8..a16183d3c 100644 --- a/packages/provider-github/src/__tests__/providerGitHub.test.ts +++ b/packages/provider-github/src/__tests__/providerGitHub.test.ts @@ -11,7 +11,7 @@ const ARTIFACTS = [ id: 123, name: 'rock-android-debug-1234567890', archive_download_url: - 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/123', + 'https://api.github.com/repos/callstack/rock/actions/artifacts/123', size_in_bytes: 10000, expires_at: '2025-05-20T12:00:00Z', }, @@ -20,7 +20,7 @@ const ARTIFACTS = [ id: 124, name: 'rock-android-debug-1234567890', archive_download_url: - 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/124', + 'https://api.github.com/repos/callstack/rock/actions/artifacts/124', size_in_bytes: 10000, expires_at: '2025-05-20T12:00:00Z', }, @@ -41,7 +41,7 @@ test('providerGitHub implements list method returning an array of artifacts', as limit, }); expect(fetch).toHaveBeenCalledWith( - `https://api.github.com/repos/callstackincubator/rock/actions/artifacts?per_page=${limit}&page=1&name=rock-android-debug-1234567890`, + `https://api.github.com/repos/callstack/rock/actions/artifacts?per_page=${limit}&page=1&name=rock-android-debug-1234567890`, { headers: { Authorization: 'token TEST_TOKEN', @@ -52,7 +52,7 @@ test('providerGitHub implements list method returning an array of artifacts', as { id: '123', name: 'rock-android-debug-1234567890', - url: 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/123', + url: 'https://api.github.com/repos/callstack/rock/actions/artifacts/123', }, ]); }); @@ -64,7 +64,7 @@ test('providerGitHub implements download method returning a stream with artifact global.fetch = vi.fn((url) => { if ( url === - 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts?per_page=100&page=1&name=rock-android-debug-1234567890' + 'https://api.github.com/repos/callstack/rock/actions/artifacts?per_page=100&page=1&name=rock-android-debug-1234567890' ) { return Promise.resolve( new Response(JSON.stringify({ artifacts: ARTIFACTS.slice(0, limit) })), @@ -72,7 +72,7 @@ test('providerGitHub implements download method returning a stream with artifact } if ( url === - 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/123' + 'https://api.github.com/repos/callstack/rock/actions/artifacts/123' ) { return Promise.resolve(downloadResponse); } @@ -97,7 +97,7 @@ test('providerGitHub implements delete method', async () => { global.fetch = vi.fn((url, options) => { if ( url === - 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts?per_page=100&page=1&name=rock-android-debug-1234567890' + 'https://api.github.com/repos/callstack/rock/actions/artifacts?per_page=100&page=1&name=rock-android-debug-1234567890' ) { return Promise.resolve( new Response(JSON.stringify({ artifacts: ARTIFACTS })), @@ -105,14 +105,14 @@ test('providerGitHub implements delete method', async () => { } if ( url === - 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/123' && + 'https://api.github.com/repos/callstack/rock/actions/artifacts/123' && options.method === 'DELETE' ) { return Promise.resolve(new Response()); } if ( url === - 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/124' && + 'https://api.github.com/repos/callstack/rock/actions/artifacts/124' && options.method === 'DELETE' ) { return Promise.resolve(new Response()); @@ -131,11 +131,11 @@ test('providerGitHub implements delete method', async () => { expect(response).toEqual([ { name: 'rock-android-debug-1234567890', - url: 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/123', + url: 'https://api.github.com/repos/callstack/rock/actions/artifacts/123', }, { name: 'rock-android-debug-1234567890', - url: 'https://api.github.com/repos/callstackincubator/rock/actions/artifacts/124', + url: 'https://api.github.com/repos/callstack/rock/actions/artifacts/124', }, ]); }); diff --git a/scripts/npm-publish.sh b/scripts/npm-publish.sh index ca61e4803..7a9885d34 100755 --- a/scripts/npm-publish.sh +++ b/scripts/npm-publish.sh @@ -1,29 +1,60 @@ #!/bin/bash -set -e +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" echo "Building all packages..." pnpm build -if [ -z "$NPM_TOKEN" ] && [ -z "$CI" ] && [ -z "$GITHUB_ACTIONS" ]; then +if [ -z "${CI:-}" ] && [ -z "${GITHUB_ACTIONS:-}" ]; then read -p "Enter NPM OTP: " OTP fi +publish_package() { + local package_dir="$1" + local package_json="$package_dir/package.json" + shift + + local package_name + local package_version + local package_ref + + package_name=$(node -p "require(process.argv[1]).name" "$package_json") + package_version=$(node -p "require(process.argv[1]).version" "$package_json") + package_ref="${package_name}@${package_version}" + + if npm view "$package_ref" version --registry https://registry.npmjs.org/ --silent >/dev/null 2>&1; then + echo "Skipping already published package ${package_ref}" + return 0 + fi + + echo "Publishing ${package_ref}" + ( + cd "$package_dir" + npm publish "$@" + ) +} + echo "NPM: Publishing all packages" -# In CI, trusted publishing should be non-interactive and not require OTP input. -if [ -n "$NPM_TOKEN" ] || [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then - pnpm -r run publish:npm -else - pnpm -r --no-bail run publish:npm --otp="$OTP" -fi +for package_json in "$ROOT_DIR"/packages/*/package.json; do + if ! grep -q '"publish:npm"' "$package_json"; then + continue + fi + + publish_args=() + if [ -z "${CI:-}" ] && [ -z "${GITHUB_ACTIONS:-}" ]; then + publish_args+=(--otp="$OTP") + fi + + publish_package "${package_json%/package.json}" --access public "${publish_args[@]}" +done echo "NPM: Publishing template" -cd templates/rock-template-default -# In CI, trusted publishing should be non-interactive and not require OTP input. -if [ -n "$NPM_TOKEN" ] || [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then - npm publish -else - npm publish --otp="$OTP" +template_publish_args=() +if [ -z "${CI:-}" ] && [ -z "${GITHUB_ACTIONS:-}" ]; then + template_publish_args+=(--otp="$OTP") fi +publish_package "$ROOT_DIR/templates/rock-template-default" --access public "${template_publish_args[@]}" echo "Done"