Skip to content

Commit

Permalink
Add publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcloudquery committed Jul 31, 2024
1 parent 4075883 commit b61a79b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish npm package

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.18.0'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm install

- name: Get package name and current version from package.json
id: get_package_info
run: |
PACKAGE_NAME=$(jq -r .name < package.json)
PACKAGE_VERSION=$(jq -r .version < package.json)
echo "::set-output name=package_name::$PACKAGE_NAME"
echo "::set-output name=current_version::$PACKAGE_VERSION"
- name: Get latest published version from npm
id: get_latest_npm_version
run: echo "::set-output name=latest_npm_version::$(npm view ${{ steps.get_package_info.outputs.package_name }} version)"

- name: Check if version changed
id: check_version
run: |
echo "Latest npm version: ${{ steps.get_latest_npm_version.outputs.latest_npm_version }}"
echo "Current package.json version: ${{ steps.get_package_info.outputs.current_version }}"
if [ "${{ steps.get_latest_npm_version.outputs.latest_npm_version }}" != "${{ steps.get_package_info.outputs.current_version }}" ]; then
echo "Version has changed"
echo "::set-output name=version_changed::true"
else
echo "Version has not changed"
echo "::set-output name=version_changed::false"
fi
- name: Run tests
if: steps.check_version.outputs.version_changed == 'true'
run: npm test

- name: Build package
if: steps.check_version.outputs.version_changed == 'true'
run: npm run build

- name: Ensure no untracked changes after build
if: steps.check_version.outputs.version_changed == 'true'
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Untracked changes found after build"
exit 1
else
echo "No untracked changes"
fi
- name: Publish to npm
if: steps.check_version.outputs.version_changed == 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cloudquery/cloud-ui",
"description": "Plugin configuration UI connector for CloudQuery Cloud App",
"version": "0.1.9",
"version": "0.1.10",
"private": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down

0 comments on commit b61a79b

Please sign in to comment.