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

feat(dev): via a new Prisma Dev extension #109

Merged
merged 11 commits into from
Apr 24, 2020
13 changes: 12 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ jobs:
- name: Install Dependencies
run: npm install
- name: Publish Extension as Patch
run: yarn vsce:check
run: yarn vsce:check "latest"

publish-alpha:
name: Publish Alpha
runs-on: ubuntu-latest
if: endsWith(github.ref, '/master')
steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: npm install
- name: Publish Extension as Patch
run: yarn vsce:check "alpha"
18 changes: 16 additions & 2 deletions scripts/bump-sha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

set -eu

CHANNEL=$1
echo "CHANNEL: $CHANNEL"

PRISMA_VERSION=$2
echo "PRISMA_VERSION: $PRISMA_VERSION"


OLD_SHA=$(jq ".prisma.version" ./package.json)

SHA=$(npx -q -p @prisma/cli@latest prisma2 --version | grep "Query Engine" | awk '{print $5}')
jq ".prisma.version = \"$SHA\"" ./package.json > ./package.json.bk
SHA=$(npx -q -p @prisma/cli@"$CHANNEL" prisma2 --version | grep "Query Engine" | awk '{print $5}')
divyenduz marked this conversation as resolved.
Show resolved Hide resolved

# If the channel is alpha, we need to change the name, displayName to the alpha extension
if [ "$CHANNEL" = "alpha" ]; then
jq ".prisma.version = \"$SHA\" | .dependencies[\"@prisma/get-platform\"] = \"$PRISMA_VERSION\" | .name = \"prisma-alpha\" | .displayName = \"Prisma Alpha\"" ./package.json > ./package.json.bk
else
jq ".prisma.version = \"$SHA\" | .dependencies[\"@prisma/get-platform\"] = \"$PRISMA_VERSION\" | .name = \"prisma\" | .displayName = \"Prisma\"" ./package.json > ./package.json.bk
fi

mv ./package.json.bk ./package.json

echo "Bumped prisma.version in package.json from $OLD_SHA to $SHA"
29 changes: 22 additions & 7 deletions scripts/check-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

set -eu

CURRENT_VERSION=$(cat scripts/prisma_version)
# For local development, in production, the environment will be set though GH actions and GH secrets
if [ -f ".envrc" ]; then
echo "Loading .envrc"
# shellcheck disable=SC1091
. .envrc
else
echo "No .envrc"
fi

CHANNEL=$1
echo "CHANNEL: $CHANNEL"

CURRENT_VERSION=$(sh scripts/extension-version.sh "$CHANNEL")
echo "CURRENT_VERSION: $CURRENT_VERSION"

NPM_VERSION=$(sh scripts/prisma-version.sh "latest")
NPM_VERSION=$(sh scripts/prisma-version.sh "$CHANNEL")
echo "NPM_VERSION: $NPM_VERSION"

# Setup the repo with GH_TOKEN to avoid running jobs when CI commits
Expand All @@ -19,11 +31,14 @@ fi

if [ "$CURRENT_VERSION" != "$NPM_VERSION" ]; then
echo "UPDATING to $NPM_VERSION"
echo "$NPM_VERSION" > scripts/prisma_version
sh ./scripts/bump-sha.sh
git add -A .
git commit -m "bump prisma_version to $NPM_VERSION"
yarn run vsce:publish
sh ./scripts/bump-sha.sh "$CHANNEL" "$NPM_VERSION"
if [ "$PRODUCTION" = "1" ]; then
git add -A .
git commit -m "bump prisma_version to $NPM_VERSION"
else
echo "Not committing because production is not set"
fi
yarn run vsce:publish "$CHANNEL" "$NPM_VERSION"
else
echo "CURRENT_VERSION ($CURRENT_VERSION) and NPM_VERSION ($NPM_VERSION) are same"
fi
11 changes: 11 additions & 0 deletions scripts/extension-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -eu

CHANNEL="$1"

if [ "$CHANNEL" = "alpha" ]; then
vsce show Prisma.prisma-alpha --json | jq ".versions[0].version" | tr -d '"'
else
vsce show Prisma.prisma --json | jq ".versions[0].version" | tr -d '"'
fi
1 change: 0 additions & 1 deletion scripts/prisma_version

This file was deleted.

17 changes: 12 additions & 5 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,29 @@ echo "AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN: $AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN"
echo "PRODUCTION: $PRODUCTION"
echo "============================"

CHANNEL=$1
echo "CHANNEL: $CHANNEL"

PRISMA_VERSION=$2
echo "PRISMA_VERSION: $PRISMA_VERSION"


# Try to publish if $AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN (Personal Access Token - https://code.visualstudio.com/api/working-with-extensions/publishing-extension#get-a-personal-access-token) exists
if [ -z "$AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN" ]; then
echo "\$AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN is empty. Please set the value of $AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN"
elif [ -n "$AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN" ]; then
if [ "$PRODUCTION" = "1" ]; then
echo "Publishing patch release"
./node_modules/.bin/vsce publish patch --pat "$AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN"
echo "Publishing $CHANNEL release"
./node_modules/.bin/vsce publish "$PRISMA_VERSION" --pat "$AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN"
carmenberndt marked this conversation as resolved.
Show resolved Hide resolved
else
echo "Printing the command because PRODUCTION is not set"
echo "sh ./scripts/bump-sha.sh" # The actual execution of this command is in check-update.sh becuase git working tree must be clean before calling `vsce publish`
echo "./node_modules/.bin/vsce publish patch --pat $AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN"
echo "./node_modules/.bin/vsce publish \"$PRISMA_VERSION\" --pat $AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN"
fi
fi

# Sync with remote branch (only master, see publish.yml) and push to it
if [ "$PRODUCTION" = "1" ]; then
# Sync with remote branch (only master, see publish.yml) when on alpha channel, and push to it
if [ "$PRODUCTION" = "1" ] && [ "$CHANNEL" = "alpha" ]; then
echo "Sync with ${GITHUB_REF} and push to it"
git pull github "${GITHUB_REF}" --ff-only
git push github HEAD:"${GITHUB_REF}"
Expand Down