Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-preview draft PR builds #20096

Merged
merged 1 commit into from
Jul 28, 2023
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
20 changes: 1 addition & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,27 +350,9 @@ jobs:
# required and add the new dependencies, and the cache will be persisted.
- dependency-cache-v1-
- gh/install
- run:
name: Set IS_DRAFT environment variable
command: |
PR_NUMBER="${CIRCLE_PULL_REQUEST##*/}"
if [ -n "$PR_NUMBER" ]
then
echo "IS_DRAFT=$(gh pr view --json isDraft --jq '.isDraft' "$PR_NUMBER")" >> "$BASH_ENV"
source "$BASH_ENV"
else
echo "Not a PR; skipping"
fi
- run:
name: Install dependencies
command: |
if [[ $IS_DRAFT == 'true' ]]
then
# Use GitHub registry on draft PRs, allowing the use of preview builds
METAMASK_NPM_REGISTRY=https://npm.pkg.github.com yarn --immutable
else
yarn --immutable
fi
command: .circleci/scripts/install-dependencies.sh
- save_cache:
key: dependency-cache-v1-{{ checksum "yarn.lock" }}
paths:
Expand Down
40 changes: 40 additions & 0 deletions .circleci/scripts/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

PR_NUMBER="${CIRCLE_PULL_REQUEST##*/}"
if [ -n "$PR_NUMBER" ]
then
IS_DRAFT="$(gh pr view --json isDraft --jq '.isDraft' "$PR_NUMBER")"
else
IS_DRAFT='false'
fi

# Build query to see whether there are any "preview-like" packages in the manifest
# A "preview-like" package is a `@metamask`-scoped package with a prerelease version that has no period.
QUERY='.dependencies + .devDependencies' # Get list of all dependencies
QUERY+=' | with_entries( select(.key | startswith("@metamask") ) )' # filter to @metamask-scoped packages
QUERY+=' | to_entries[].value' # Get version ranges
QUERY+=' | select(test("^\\d+\\.\\d+\\.\\d+-[^.]+$"))' # Get pinned versions where the prerelease part has no "."

# Use `-e` flag so that exit code indicates whether any matches were found
if jq -e "${QUERY}" < ./package.json
then
echo "Preview builds detected"
HAS_PREVIEW_BUILDS='true'
else
echo "No preview builds detected"
HAS_PREVIEW_BUILDS='false'
fi

if [[ $IS_DRAFT == 'true' && $HAS_PREVIEW_BUILDS == 'true' ]]
then
# Use GitHub registry on draft PRs, allowing the use of preview builds
echo "Installing with preview builds"
METAMASK_NPM_REGISTRY=https://npm.pkg.github.com yarn --immutable
else
echo "Installing without preview builds"
yarn --immutable
fi
Loading