Skip to content

Instantly share code, notes, and snippets.

@calvinchengx
Last active November 1, 2021 15:08
Show Gist options
  • Save calvinchengx/e1b1ab6388cec4f26192414dd9ed7af4 to your computer and use it in GitHub Desktop.
Save calvinchengx/e1b1ab6388cec4f26192414dd9ed7af4 to your computer and use it in GitHub Desktop.
Example deploy using vercel token (.circleci/config.yml and .now/linkproject.sh)
defaults: &defaults
docker:
- image: circleci/node:12.14
working_directory: ~/tmp/circleci-now
version: 2
jobs:
checkout:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/tmp/circleci-now
- restore_cache:
keys:
- npm-cache-{{ .Branch }}-{{ checksum "package.json" }}
- npm-cache-{{ .Branch }}
- npm-cache-
- run:
name: NPM Install
command: npm install
- save_cache:
key: npm-cache-{{ .Branch }}-{{ checksum "package.json" }}
paths:
- node_modules
- persist_to_workspace:
root: .
paths: .
unit-test:
<<: *defaults
steps:
- attach_workspace:
at: ~/tmp/circleci-now
- run:
name: NPM Install
command: npm install
- run:
name: Unit Test with Code Coverage
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
npm run test:coverage
./cc-test-reporter after-build -t lcov -r ${TEST_REPORTER_ID}
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/tmp/circleci-now
- run:
name: Deploy
command: |
./.now/linkproject.sh
if [ "${CIRCLE_BRANCH}" == "master" ];
then
npx now --token $ZEIT_TOKEN --scope $ZEIT_ORG_ID --confirm --prod
else
npx now --token $ZEIT_TOKEN --scope $ZEIT_ORG_ID --confirm
fi
workflows:
version: 2
test-deploy-purge:
jobs:
- checkout
- unit-test:
requires:
- checkout
- deploy:
filters:
branches:
only:
- develop
- master
requires:
- unit-test
#!/bin/bash
set -e
JSON=$(cat <<-EOF
{
"orgId": "$ZEIT_ORG_ID",
"projectId": "$ZEIT_PROJECT_ID"
}
EOF
)
echo $JSON > .now/project.json
@c0nscience
Copy link

Thanks for your snippet. I just found out that you just can provide the org and project id via environment variables entirely: VERCEL_ORG_ID and VERCEL_PROJECT_ID.

Then there is no need for creating the project.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment