Skip to content

Commit 892cdc8

Browse files
authored
Merge pull request #27 from viperproject/release-via-ci
Release to NPM in CI
2 parents ed90db5 + 5f8a6b0 commit 892cdc8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

.github/workflows/test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,49 @@ jobs:
4545

4646
- name: Run tests
4747
run: npm test
48+
49+
release:
50+
if: ${{ github.repository == 'viperproject/locate-java-home' && github.ref == 'refs/heads/master' }}
51+
needs: setup-and-test
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v2
56+
57+
- name: Install Node.js
58+
uses: actions/[email protected]
59+
with:
60+
node-version: '16'
61+
62+
# compare version in package.json with last published version on
63+
# NPM and deploy this version if newer.
64+
# credits go to @fpoli!
65+
- name: Obtain version information
66+
run: |
67+
PACKAGE_NAME="$(cat package.json | jq '.name' --raw-output)"
68+
LAST_PUBLISHED_VERSION="$(
69+
npm show $PACKAGE_NAME version
70+
)"
71+
CURRENT_VERSION="$(
72+
cat package.json | jq '.version' --raw-output
73+
)"
74+
echo "LAST_PUBLISHED_VERSION=$LAST_PUBLISHED_VERSION" >> $GITHUB_ENV
75+
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
76+
77+
- name: Cache npm
78+
if: ${{ env.CURRENT_VERSION != env.LAST_PUBLISHED_VERSION }}
79+
uses: actions/cache@v2
80+
with:
81+
path: .npm
82+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
83+
restore-keys: |
84+
${{ runner.os }}-node-
85+
86+
- if: ${{ env.CURRENT_VERSION != env.LAST_PUBLISHED_VERSION }}
87+
run: npm ci --cache .npm --prefer-offline
88+
89+
- name: Release to NPM
90+
if: ${{ env.CURRENT_VERSION != env.LAST_PUBLISHED_VERSION }}
91+
run: |
92+
npm config set -- '//registry.npmjs.org/:_authToken' ${{ secrets.NPM_ACCESS_TOKEN }}
93+
npm publish --access public

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@viperproject/locate-java-home",
3-
"version": "1.1.8",
3+
"version": "1.1.9",
44
"description": "Locates JAVA_HOME on any platform, and can differentiate between different versions.",
55
"main": "js/es5/index.js",
66
"module": "js/es6/index.js",

0 commit comments

Comments
 (0)