Skip to content

Commit 710c2a0

Browse files
committed
GDL-9 publish npm package to registry
1 parent de5b316 commit 710c2a0

File tree

4 files changed

+103
-7
lines changed

4 files changed

+103
-7
lines changed

.github/workflows/release.yaml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
name: Release
3+
4+
run-name: release ${{ inputs.tag }}
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'Tag to be released'
11+
required: true
12+
13+
permissions:
14+
packages: write
15+
id-token: write
16+
contents: read
17+
18+
jobs:
19+
publish:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Ensure the branch is protected
26+
run: |
27+
if [[ "${{ github.ref_protected }}" == "false" ]]; then
28+
echo "::error::The branch ${{ github.ref }} is not protected"
29+
exit 1
30+
fi
31+
- name: Ensure tag has not been released
32+
run: |
33+
TAG_EXISTS=$(git tag -l "${{ inputs.tag }}")
34+
if [ -n "$TAG_EXISTS" ]; then
35+
echo "::error::The tag ${{ inputs.tag }} has already been released"
36+
exit 1
37+
fi
38+
- name: Ensure version is properly set
39+
run: |
40+
PKG_VERSION="$(yarn -s run get-version)"
41+
if ! [ "$PKG_VERSION" = "$VERSION" ]; then
42+
echo "::error file=package.json,line=$(sed -n '/"version":/=' package.json)::The tag $VERSION must match the version $PKG_VERSION specified in package.json"
43+
exit 1
44+
fi
45+
env:
46+
VERSION: ${{ inputs.tag }}
47+
- name: Setup node with GitHub Packages
48+
uses: actions/setup-node@v4
49+
with:
50+
cache: yarn
51+
node-version: '16'
52+
registry-url: https://npm.pkg.github.com
53+
- run: yarn install --frozen-lockfile
54+
- name: Publish to GitHub Packages
55+
run: npm publish --provenance
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
- name: Setup node with npmjs.org
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version: '16'
62+
registry-url: https://registry.npmjs.org
63+
- name: Publish to npmjs.org
64+
run: npm publish --provenance
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
67+
- name: Create Release
68+
uses: softprops/action-gh-release@v2
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
with:
72+
tag_name: ${{ inputs.tag }}
73+
name: Release ${{ inputs.tag }}
74+
target_commitish: ${{ github.sha }}

.github/workflows/tests.yaml

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@ on:
66
branches-ignore:
77
- 'development/**'
88

9+
permissions:
10+
packages: write
11+
id-token: write
12+
contents: read
13+
914
jobs:
1015
test:
1116
runs-on: ubuntu-latest
1217
steps:
1318
- name: Checkout
14-
uses: actions/checkout@v2
15-
- uses: actions/setup-node@v2
19+
uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
1621
with:
1722
node-version: '16'
23+
registry-url: https://npm.pkg.github.com
1824
- name: install dependencies
1925
run: yarn install --frozen-lockfile
2026
- name: lint markdown
2127
run: yarn lint_md
2228
- name: lint javascript
2329
run: yarn lint
30+
- name: Set development version
31+
run: yarn version --no-git-tag-version --new-version "0.0.0-sha.${{ github.sha }}"
32+
- name: Publish development version
33+
run: npm publish --provenance
34+
env:
35+
NODE_AUTH_TOKEN: ${{ github.token }}

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!LICENSE
3+
!bin/
4+
!index.js
5+
!package.json
6+
!README.md

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
2-
"name": "eslint-config-scality",
2+
"name": "@scality/eslint-config",
33
"version": "7.10.2",
44
"description": "ESLint config for Scality's Node.js coding guidelines",
55
"bin": {
6-
"mdlint": "./bin/mdlint.js"
6+
"mdlint": "bin/mdlint.js"
77
},
88
"main": "index.js",
99
"scripts": {
1010
"test": "npm run --silent lint && npm run --silent lint_md",
11-
"lint": "node_modules/.bin/eslint -c index.js $(git ls-files '*.js')",
12-
"lint_md": "node bin/mdlint.js $(git ls-files '*.md')"
11+
"lint": "eslint -c index.js $(git ls-files '*.js')",
12+
"lint_md": "node bin/mdlint.js $(git ls-files '*.md')",
13+
"get-version": "echo $npm_package_version"
1314
},
1415
"repository": {
1516
"type": "git",
16-
"url": "https://github.com/scality/Guidelines"
17+
"url": "git+https://github.com/scality/Guidelines.git"
1718
},
1819
"dependencies": {
1920
"commander": "1.3.2",
@@ -39,5 +40,8 @@
3940
"homepage": "https://github.com/scality/Guidelines",
4041
"engines": {
4142
"node": ">=16"
43+
},
44+
"publishConfig": {
45+
"access": "public"
4246
}
4347
}

0 commit comments

Comments
 (0)