Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions packages/provider-github/src/__tests__/providerGitHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand All @@ -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',
},
Expand All @@ -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',
Expand All @@ -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',
},
]);
});
Expand All @@ -64,15 +64,15 @@ 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) })),
);
}
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);
}
Expand All @@ -97,22 +97,22 @@ 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 })),
);
}
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());
Expand All @@ -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',
},
]);
});
Expand Down
59 changes: 45 additions & 14 deletions scripts/npm-publish.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading