Skip to content

Commit

Permalink
[nan-668] add verification bash script to publish packages (NangoHQ#1930
Browse files Browse the repository at this point in the history
)

## Describe your changes
The goal with this PR is to mimic a publish process of the cli with the
code that is in review to ensure a working cli that is in a remote
source. This is accomplished by building and publishing the packages to
the Github registry and finally using the cli to verify that it works
expected. This will protect against instances where a faulty cli is
published. This will be especially useful to verify that this PR:
NangoHQ#1918 works as expected with
packaging the utils package. Additionally, as we refactor the cli to
move code out of shared and reduce the package size of the cli this will
ensure things still work as expected.

## Issue ticket number and link
NAN-668

## Checklist before requesting a review (skip if just adding/editing
APIs & templates)
- [ ] I added tests, otherwise the reason is: 
- [ ] I added observability, otherwise the reason is:
- [ ] I added analytics, otherwise the reason is:
  • Loading branch information
khaliqgant authored Apr 3, 2024
1 parent 810151a commit d3c521a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/cli-verification.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CLI Publish & Verify

on:
push:
branches:
- master
- staging/**
pull_request:

concurrency:
group: verify-cli-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
publish-and-test:
runs-on: ubuntu-latest
env:
NANGO_CLI_UPGRADE_MODE: ignore
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@nangohq'
always-auth: true
- name: Publish npm packages to the github registry
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
continue-on-error: true
run: |
GIT_HASH=$(git rev-parse HEAD)
bash ./scripts/publish.sh 0.0.1-$GIT_HASH
- name: Publish the cli privately under the correct scope
working-directory: packages/cli
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
jq '.name = "@nangohq/cli"' package.json > temp.json && mv temp.json package.json
npm publish --access public
- name: Install the cli from the github package registry
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
GIT_HASH=$(git rev-parse HEAD)
mkdir nango-cli-test && cd nango-cli-test
npm init -y
npm install @nangohq/[email protected]$GIT_HASH
VERSION_OUTPUT=$(npx nango version)
EXPECTED_VERSION="Nango CLI version: 0.0.1-$GIT_HASH"
[ "$VERSION_OUTPUT" = "$EXPECTED_VERSION" ] || { echo "Version mismatch. Expected: $EXPECTED_VERSION, got: $VERSION_OUTPUT"; exit 1; }
npx nango version --debug
npx nango init --debug
cd nango-integrations
npx nango generate --debug
6 changes: 3 additions & 3 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ function bump_and_npm_publish {
GIT_ROOT_DIR=$(git rev-parse --show-toplevel)
VERSION=$1

# ensure version is of format x.y.z
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "VERSION '$VERSION' is not of format x.y.z"
# ensure version is of format x.y.z or 0.0.1-<commit hash>
if [[ ! "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+|0\.0\.1-[0-9a-fA-F]{40})$ ]]; then
echo "VERSION '$VERSION' is not of format x.y.z or 0.0.1-<commit hash>"
exit 1
fi

Expand Down

0 comments on commit d3c521a

Please sign in to comment.