-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters