From 71e0bca0e7aae062d69569c085b56d86a7587ffd Mon Sep 17 00:00:00 2001 From: L Lllvvuu Date: Sat, 23 Sep 2023 01:30:19 -0700 Subject: [PATCH] ci: automate publishing package to npm In order for this to work, `NPM_TOKEN` must be provided to GitHub: repository > Settings > Secrets and variables > Actions > New repository secret The `NPM_TOKEN` can be created at https://www.npmjs.com/ profile pic > Account > Access Tokens > Generate New Token > Granular Access Token --- .github/workflows/publish.yml | 68 +++++++++++++++++++++++++++++++++++ README.md | 4 +-- package-lock.json | 6 ++-- package.json | 4 +-- tsup.config.ts | 1 + 5 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..d986cbd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,68 @@ +name: Publish to npm + +on: + push: + branches: + - master + paths: + - 'package.json' + +jobs: + check: + runs-on: ubuntu-latest + + outputs: + version_changed: ${{ steps.check-version.outputs.version_changed }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Check for version change + id: check-version + run: | + NEW_VERSION="$(node -p "require('./package.json').version")" + git show HEAD^:package.json > .old_package.json + OLD_VERSION="$(node -p "require('./.old_package.json').version")" + if [[ "$NEW_VERSION" != "$OLD_VERSION" ]]; then + echo "version_changed=true" >> "$GITHUB_OUTPUT" + else + echo "version_changed=false" >> "$GITHUB_OUTPUT" + fi + + publish: + needs: check + if: needs.check.outputs.version_changed == 'true' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Set package name for npm + run: | + cp package.json package.json.bak + sed 's/"name": "solidity"/"name": "vscode-solidity-langserver"/' package.json.bak > package.json + + - name: Build and publish to npm + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index 4f4f927..a87527a 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Solidity is the language used in Ethereum to create smart contracts, this extens It is also available as a standalone LSP: ```sh -npm install -g @juanfranblanco/vscode-solidity-server -vscode-solidity-server --stdio +npm install -g vscode-solidity-langserver +vscode-solidity-langserver --stdio ``` # Instructions diff --git a/package-lock.json b/package-lock.json index 577645a..caed22a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "solidity", - "version": "0.0.165", + "version": "0.0.166", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "solidity", - "version": "0.0.165", + "version": "0.0.166", "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", @@ -27,7 +27,7 @@ "yaml-js": "0.2.3" }, "bin": { - "vscode-solidity-server": "dist/cli/server.js" + "vscode-solidity-langserver": "dist/cli/server.js" }, "devDependencies": { "@types/node": "^11.15.3", diff --git a/package.json b/package.json index caac225..680bca1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "nethereum", "solhint" ], - "version": "0.0.165", + "version": "0.0.166", "publisher": "JuanBlanco", "license": "MIT", "engines": { @@ -36,7 +36,7 @@ ], "main": "./out/src/extension", "bin": { - "vscode-solidity-server": "./dist/cli/server.js" + "vscode-solidity-langserver": "./dist/cli/server.js" }, "scripts": { "vscode:prepublish": "npm run compile", diff --git a/tsup.config.ts b/tsup.config.ts index c92e695..33b482f 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -5,6 +5,7 @@ export const baseOptions = (options: Options) => ({ clean: true, bundle: !options.watch, minify: !options.watch, + sourcemap: true, }) export default defineConfig(baseOptions);