Publish @flexmonster/angular to npm #7
This file contains hidden or 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
| name: Publish @flexmonster/angular to npm | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (used for @flexmonster/angular and the @flexmonster/js peer dependency)' | |
| required: true | |
| type: string | |
| tag: | |
| description: 'npm dist-tag to publish under' | |
| required: true | |
| type: choice | |
| default: 'latest' | |
| options: | |
| - latest | |
| - next | |
| - beta | |
| dry_run: | |
| description: 'Dry run (do not actually publish to npm)' | |
| required: false | |
| type: boolean | |
| default: false | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Resolve version and dist-tag | |
| id: version | |
| env: | |
| INPUT_VERSION: ${{ inputs.version }} | |
| INPUT_TAG: ${{ inputs.tag }} | |
| run: | | |
| VERSION="$INPUT_VERSION" | |
| DIST_TAG="$INPUT_TAG" | |
| echo "value=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT" | |
| echo "tag_flag=--tag $DIST_TAG" >> "$GITHUB_OUTPUT" | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| registry-url: 'https://registry.npmjs.org' | |
| scope: '@flexmonster' | |
| - name: Check if version already exists | |
| env: | |
| VERSION: ${{ steps.version.outputs.value }} | |
| run: | | |
| PKG_NAME=$(node -p "require('./projects/flexmonster/angular/package.json').name") | |
| if npm view "${PKG_NAME}@${VERSION}" version --registry https://registry.npmjs.org 2>/dev/null; then | |
| echo "::error::Version ${VERSION} already exists on npm." | |
| exit 1 | |
| fi | |
| - name: Set package version | |
| working-directory: projects/flexmonster/angular | |
| env: | |
| VERSION: ${{ steps.version.outputs.value }} | |
| run: npm version "$VERSION" --no-git-tag-version | |
| - name: Bump @flexmonster/js peer dependency | |
| working-directory: projects/flexmonster/angular | |
| env: | |
| JS_VERSION: ${{ steps.version.outputs.value }} | |
| run: npm pkg set "peerDependencies.@flexmonster/js=$JS_VERSION" | |
| - name: Install dependencies (also pins @flexmonster/js in root to the published peer) | |
| env: | |
| JS_VERSION: ${{ steps.version.outputs.value }} | |
| run: npm install "@flexmonster/js@$JS_VERSION" --save-exact --no-audit --no-fund | |
| - name: Build | |
| run: npx ng build @flexmonster/angular | |
| - name: Copy LICENSE and README to release folder | |
| run: | | |
| cp LICENSE dist/flexmonster/angular/LICENSE | |
| cp README.md dist/flexmonster/angular/README.md | |
| - name: Show package.json after version bump | |
| run: cat dist/flexmonster/angular/package.json | |
| - name: Publish package (dry run) | |
| if: ${{ inputs.dry_run }} | |
| working-directory: dist/flexmonster/angular | |
| run: npm publish ${{ steps.version.outputs.tag_flag }} --dry-run | |
| - name: Publish package | |
| if: ${{ !inputs.dry_run }} | |
| working-directory: dist/flexmonster/angular | |
| run: npm publish ${{ steps.version.outputs.tag_flag }} | |
| - name: Commit and push version bump | |
| if: ${{ !inputs.dry_run }} | |
| env: | |
| VERSION: ${{ steps.version.outputs.value }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add projects/flexmonster/angular/package.json package.json package-lock.json | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit." | |
| exit 0 | |
| fi | |
| git commit -m "Release v$VERSION" | |
| git push origin "HEAD:${GITHUB_REF#refs/heads/}" |