-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59d52fe
commit 778a970
Showing
14 changed files
with
140 additions
and
34 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 |
---|---|---|
|
@@ -2,43 +2,41 @@ name: Publish to NPM | |
|
||
on: | ||
release: | ||
tags: | ||
- '**-[0-9]+.[0-9]+.[0-9]+' | ||
- '**-[0-9]+.[0-9]+.[0-9]+-*' | ||
tags: | ||
- "**-[0-9]+.[0-9]+.[0-9]+" | ||
- "**-[0-9]+.[0-9]+.[0-9]+-*" | ||
types: [published] | ||
|
||
jobs: | ||
build-and-publish: | ||
name: 🚀 Publish to NPM | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Source checkout | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.release.target_commitish }} | ||
# Setting Node environment | ||
- name: Setting up Node environment | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16 | ||
registry-url: https://registry.npmjs.org/ | ||
# Environment configuration | ||
- name: Preparing environment for release | ||
run: | | ||
VERSION=$(echo $GITHUB_REF_NAME | sed 's/^.*[A-Za-z]-//g') | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
echo "PACKAGE=$(echo $GITHUB_REF_NAME | sed "s/-${VERSION}//g")" >> $GITHUB_ENV | ||
# Release process | ||
- name: Release | ||
run: | | ||
npm ci | ||
git config --global user.name "Automated NPM Release" | ||
git config --global user.email "[email protected]" | ||
npm version $VERSION --allow-same-version --workspace "@aligent/cdk-${{env.PACKAGE}}" | ||
npm run build --workspace "@aligent/cdk-${{env.PACKAGE}}" | ||
npm test --workspace "@aligent/cdk-${{env.PACKAGE}}" --if-present | ||
npm publish --access public --workspace "@aligent/cdk-${{env.PACKAGE}}" | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
- run: git push | ||
env: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.release.target_commitish }} | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ".nvmrc" | ||
cache: "yarn" | ||
registry-url: https://registry.npmjs.org/ | ||
|
||
- name: Install | ||
run: yarn install | ||
|
||
- name: Preparing environment for release | ||
run: | | ||
VERSION=$(echo $GITHUB_REF_NAME | sed 's/^.*[A-Za-z]-//g') | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
echo "PACKAGE=$(echo $GITHUB_REF_NAME | sed "s/-${VERSION}//g")" >> $GITHUB_ENV | ||
- name: Release | ||
run: | | ||
git config --global user.name "Automated NPM Release" | ||
git config --global user.email "[email protected]" | ||
echo "Publishing $PACKAGE @ $VERSION" | ||
yarn config set registry https://registry.npmjs.org/ | ||
yarn nx publish $PACKAGE --ver=$VERSION --tag=latest --verbose | ||
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* This is a minimal script to publish your package to "npm". | ||
* This is meant to be used as-is or customize as you see fit. | ||
* | ||
* This script is executed on "dist/path/to/library" as "cwd" by default. | ||
* | ||
* You might need to authenticate with NPM before running this script. | ||
*/ | ||
|
||
import { execSync } from 'child_process'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
|
||
import devkit from '@nx/devkit'; | ||
const { readCachedProjectGraph } = devkit; | ||
|
||
function invariant(condition, message) { | ||
if (!condition) { | ||
console.error(message); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag} | ||
// Default "tag" to "next" so we won't publish the "latest" tag by accident. | ||
const [, , name, version, tag = 'next'] = process.argv; | ||
|
||
// A simple SemVer validation to validate the version | ||
const validVersion = /^\d+\.\d+\.\d+(-\w+\.\d+)?/; | ||
invariant( | ||
version && validVersion.test(version), | ||
`No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got ${version}.` | ||
); | ||
|
||
const graph = readCachedProjectGraph(); | ||
const project = graph.nodes[name]; | ||
|
||
invariant( | ||
project, | ||
`Could not find project "${name}" in the workspace. Is the project.json configured correctly?` | ||
); | ||
|
||
const outputPath = project.data?.targets?.build?.options?.outputPath; | ||
invariant( | ||
outputPath, | ||
`Could not find "build.options.outputPath" of project "${name}". Is project.json configured correctly?` | ||
); | ||
|
||
process.chdir(outputPath); | ||
|
||
// Updating the version in "package.json" before publishing | ||
try { | ||
const json = JSON.parse(readFileSync(`package.json`).toString()); | ||
json.version = version; | ||
writeFileSync(`package.json`, JSON.stringify(json, null, 2)); | ||
} catch (e) { | ||
console.error(`Error reading package.json file from library build output.`); | ||
} | ||
|
||
// Execute "npm publish" to publish | ||
execSync(`npm publish --verbose --access=public --tag ${tag}`); |