Skip to content

Commit

Permalink
feat(dev): via a new Prisma Dev extension (#109)
Browse files Browse the repository at this point in the history
* feat(alpha): via a new extension

- Fixes #47
- Fixes #93

This PR is made against "alpha" and merging this should release a "new"
alpha extension.

* feat(alpha): incorporate release feedback

- Remove the alpha branch dependency
- Push only when bumping alpha
- Bump @prisma/* packages when updating package.json

* feat(alpha): use vsce show for extension version

* Update scripts/bump-sha.sh

Co-Authored-By: Jan Piotrowski <[email protected]>

* feat(dev): publish Prisma Dev as a new extension

- rename to dev
- merge with master, adjust bump deps
- add release-workflow.md

* Update release-workflow.md

Co-Authored-By: Jan Piotrowski <[email protected]>

* fix: job name

Fixes #82

Co-authored-by: Jan Piotrowski <[email protected]>
  • Loading branch information
Divyendu Singh and janpio authored Apr 24, 2020
1 parent bb90bd0 commit 76c9b3d
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 29 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Automatic Publish
name: Check for Update + Automated Publish

on:
push:
Expand All @@ -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-dev:
name: Publish Dev
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 "dev"
41 changes: 41 additions & 0 deletions release-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Release Workflow

## Trigger

Schedule (every 5 minutes) or push to `master` branch.

## Development

With `PRODUCTION=0` in environment, the script doesn't publish but outputs the commands that would be run. A publish is only triggered when `PRODUCTION=1` is set.

Entry point to test development is `yarn vsce:check <channel>`, where `channel=dev|latest`.

## Steps

1. Defined in the file `.github/workflows/publish.yml`
1. `yarn vsce:check <channel>` is run twice with "dev" and "latest" as channels respectively. Internally, it calls `check-update.sh <channel>`

Note the both `dev` workflow and `latest` workflow call the same scripts, the channel variable acts as a workflow discriminator as both workflows have slight differences, now we list the workflow steps in details:

### Dev workflow

1. `yarn vsce:check dev` calls `check-update.sh dev`
1. `check-update.sh` sets up the repo with Prismo bot as the user, all commits in the remainder of this workflow are attributed to Prismo.
1. `check-update.sh` compares `CURRENT_VERSION` (extension) against `NPM_VERSION` of Prisma CLI.
1. If they are same, this script exits
1. If they are different, `bump.sh <channel> <version>` is called with `channel=dev` and `version=NPM_VERSION` (i.e. the new version of extension to publish)
1. `bump.sh` updates the `package.json` files in root, client, server and sets `name`, `displayName`, `version`, `dependencies.@prisma/*` packages, and `prisma.version` values.
1. `check-update.sh` then commits these changes, this commit is required because `vsce publish` (to be run later requires a clean git state)
1. `yarn vsce:publish <channel> <version>` i.e. `publish.sh <channel> <version>` is then called with `channel=dev` and `version=NPM_VERSION` (i.e. the new version of extension to publish). This command publishes the "Prisma Dev" extension.
1. `publish.sh` pushes to vscode master repo. Only changes from the dev channel are pushed.

### Latest workflow

1. `yarn vsce:check latest` calls `check-update.sh latest`
1. `check-update.sh` sets up the repo with Prismo bot as the user, all commits in the remainder of this workflow are attributed to Prismo.
1. `check-update.sh` compares `CURRENT_VERSION` (extension) against `NPM_VERSION` of Prisma CLI.
1. If they are same, this script exits
1. If they are different, `bump.sh <channel> <version>` is called with `channel=latest` and `version=NPM_VERSION` (i.e. the new version of extension to publish)
1. `bump.sh` updates the `package.json` files in root, client, server and sets `name`, `displayName`, `version`, `dependencies.@prisma/*` packages, and `prisma.version` values.
1. `check-update.sh` then commits these changes, this commit is required because `vsce publish` (to be run later requires a clean git state)
1. `yarn vsce:publish <channel> <version>` i.e. `publish.sh <channel> <version>` is then called with `channel=latest` and `version=NPM_VERSION` (i.e. the new version of extension to publish). This command published the "Prisma" extension.
11 changes: 0 additions & 11 deletions scripts/bump-sha.sh

This file was deleted.

51 changes: 51 additions & 0 deletions scripts/bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

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@"$CHANNEL" prisma --version | grep "Query Engine" | awk '{print $5}')

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

jq ".version = \"$PRISMA_VERSION\" | \
.prisma.version = \"$SHA\" | \
.dependencies[\"@prisma/get-platform\"] = \"$PRISMA_VERSION\" | \
.dependencies[\"@prisma/fetch-engine\"] = \"$PRISMA_VERSION\" | \
.dependencies[\"@prisma/sdk\"] = \"$PRISMA_VERSION\"" \
./server/package.json > ./server/package.json.bk

jq ".version = \"$PRISMA_VERSION\"" \
./client/package.json > ./client/package.json.bk

mv ./package.json.bk ./package.json
mv ./server/package.json.bk ./server/package.json
mv ./client/package.json.bk ./client/package.json

npm install

cd ./client
npm install
cd ..

cd ./server
npm install
cd ..

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.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" = "dev" ]; then
vsce show Prisma.prisma-dev --json | jq ".versions[0].version" | tr -d '"'
else
vsce show Prisma.prisma --json | jq ".versions[0].version" | tr -d '"'
fi
9 changes: 7 additions & 2 deletions scripts/prisma-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -eu

channel="$1"
CHANNEL="$1"

yarn info "@prisma/cli@$channel" --json | jq ".data[\"dist-tags\"].$channel" | tr -d '"'
# TODO: remove this if-condition once we move to dev
if [ "$CHANNEL" = "dev" ]; then
CHANNEL="alpha"
fi

yarn info "@prisma/cli@$CHANNEL" --json | jq ".data[\"dist-tags\"].$CHANNEL" | tr -d '"'
1 change: 0 additions & 1 deletion scripts/prisma_version

This file was deleted.

19 changes: 13 additions & 6 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"
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 "sh ./scripts/bump.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 \"$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 dev channel, and push to it
if [ "$PRODUCTION" = "1" ] && [ "$CHANNEL" = "dev" ]; 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

0 comments on commit 76c9b3d

Please sign in to comment.