Skip to content

Commit b6066dd

Browse files
Add publish scripts
1 parent c6c5c9d commit b6066dd

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

.gitlab-ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,66 @@ test-14:
3838
- npm run test
3939
dependencies:
4040
- build
41+
42+
publish-npm:
43+
stage: deploy
44+
script:
45+
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
46+
- npm --color="always" publish
47+
dependencies:
48+
- build
49+
only:
50+
refs:
51+
- /^v.*$/
52+
variables:
53+
- $NPM_TOKEN
54+
except:
55+
- branches
56+
cache:
57+
paths:
58+
- node_modules/
59+
policy: pull
60+
61+
publish-github:
62+
stage: deploy
63+
script:
64+
# Update the package.json and package-lock.json
65+
# GitHub Package Repository now requires the `repository` field is the GitHub repository
66+
# This means the package publish to GitHub is different to the package published everywhere else
67+
- "node -e \"fs.writeFileSync('package.json', JSON.stringify((json => {json.repository = {type: 'git', url: 'https://github.com/' + process.env.GITHUB_REPOSITORY + '.git'}; return json;})(JSON.parse(fs.readFileSync('package.json', 'utf-8'))), null, 4) + '\\n', 'utf-8')\""
68+
69+
- echo "//npm.pkg.github.com/:_authToken=${GITHUB_NPM_TOKEN}" > .npmrc
70+
- npm --color="always" --registry=https://npm.pkg.github.com/ publish
71+
dependencies:
72+
- build
73+
only:
74+
refs:
75+
- /^v.*$/
76+
variables:
77+
- $GITHUB_REPOSITORY
78+
- $GITHUB_NPM_TOKEN
79+
except:
80+
- branches
81+
cache:
82+
paths:
83+
- node_modules/
84+
policy: pull
85+
86+
publish-gitlab:
87+
stage: deploy
88+
script:
89+
- echo "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" | sed s/^https:// > .npmrc
90+
- npm --color="always" --registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/ publish
91+
dependencies:
92+
- build
93+
only:
94+
refs:
95+
- /^v.*$/
96+
variables:
97+
- $GITLAB_NPM_PUBLISH
98+
except:
99+
- branches
100+
cache:
101+
paths:
102+
- node_modules/
103+
policy: pull

0 commit comments

Comments
 (0)