Skip to content

Commit 0d4a7a2

Browse files
committed
GDL-9 publish npm package to registry
1 parent de5b316 commit 0d4a7a2

File tree

3 files changed

+128
-23
lines changed

3 files changed

+128
-23
lines changed

.github/workflows/release.yaml

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

.github/workflows/tests.yaml

+31-12
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,39 @@ name: tests
44
on:
55
push:
66
branches-ignore:
7-
- 'development/**'
7+
- q/*/*
88

99
jobs:
1010
test:
11+
permissions:
12+
packages: write
13+
id-token: write
14+
contents: read
1115
runs-on: ubuntu-latest
1216
steps:
13-
- name: Checkout
14-
uses: actions/checkout@v2
15-
- uses: actions/setup-node@v2
16-
with:
17-
node-version: '16'
18-
- name: install dependencies
19-
run: yarn install --frozen-lockfile
20-
- name: lint markdown
21-
run: yarn lint_md
22-
- name: lint javascript
23-
run: yarn lint
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: '16'
22+
registry-url: https://npm.pkg.github.com
23+
- name: install dependencies
24+
run: yarn install --frozen-lockfile
25+
- name: lint markdown
26+
run: yarn lint_md
27+
- name: lint javascript
28+
run: yarn lint
29+
- name: Set common env vars for npm publish
30+
run: |
31+
echo "SHORTSHA=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_ENV
32+
echo "PKG_VERSION=$(jq -r .version < package.json)" >> $GITHUB_ENV
33+
- name: Set version for work in progress
34+
run: yarn version --no-git-tag-version --new-version "0.0.0-sha.${SHORTSHA}"
35+
if: github.ref_protected == false
36+
- name: Set version for protected branch
37+
run: yarn version --no-git-tag-version --new-version "${PKG_VERSION}-sha.${SHORTSHA}"
38+
if: github.ref_protected
39+
- name: Publish development version
40+
run: npm publish --provenance --tag "${{ github.ref_name }}"
41+
env:
42+
NODE_AUTH_TOKEN: ${{ github.token }}

package.json

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
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')",
11+
"lint": "eslint -c index.js $(git ls-files '*.js')",
1212
"lint_md": "node bin/mdlint.js $(git ls-files '*.md')"
1313
},
1414
"repository": {
1515
"type": "git",
16-
"url": "https://github.com/scality/Guidelines"
16+
"url": "git+https://github.com/scality/Guidelines.git"
1717
},
1818
"dependencies": {
1919
"commander": "1.3.2",
2020
"markdownlint": "^0.25.1"
2121
},
22+
"bugs": {
23+
"url": "https://github.com/scality/Guidelines/issues"
24+
},
2225
"devDependencies": {
2326
"babel-eslint": "6.1.2",
2427
"eslint": "^8.7.0",
2528
"eslint-config-airbnb": "6.2.0"
2629
},
2730
"keywords": [
28-
"eslint",
2931
"eslintconfig",
30-
"config",
31-
"airbnb",
32-
"scality",
3332
"javascript",
34-
"markdown",
33+
"scality",
3534
"styleguide"
3635
],
37-
"author": "Giorgio Regni",
36+
"author": "Scality Object Squad <object-squad@scality.com>",
3837
"license": "Apache-2.0",
3938
"homepage": "https://github.com/scality/Guidelines",
4039
"engines": {
4140
"node": ">=16"
42-
}
41+
},
42+
"publishConfig": {
43+
"access": "public"
44+
},
45+
"files": [
46+
"bin",
47+
"*.[c]js"
48+
]
4349
}

0 commit comments

Comments
 (0)