Skip to content

Commit

Permalink
ci: automate publishing package to npm
Browse files Browse the repository at this point in the history
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
  • Loading branch information
llllvvuu committed Sep 23, 2023
1 parent 655c05b commit 71e0bca
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"nethereum",
"solhint"
],
"version": "0.0.165",
"version": "0.0.166",
"publisher": "JuanBlanco",
"license": "MIT",
"engines": {
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const baseOptions = (options: Options) => ({
clean: true,
bundle: !options.watch,
minify: !options.watch,
sourcemap: true,
})

export default defineConfig(baseOptions);

0 comments on commit 71e0bca

Please sign in to comment.