nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.7k stars 2.37k forks source link

Documentation improvement idea for "Publish in CI/CD" page #22113

Open batrdn opened 8 months ago

batrdn commented 8 months ago

Documentation issue

Improvement idea for Publish in CI/CD

I recently automated the release workflow of a package in GitHub (workflow yaml below). This setup triggers a release action (using the nx release --skip-publish command) whenever a new pull request merges into the main branch, eliminating the need for manual local releases (as described in the page). My suggestion is adding a section in the documentation to showcase how the release process can be automated within GitHub Actions, emphasizing the transition from pull-request-merge to automated publishing. This addition might be more informative for Nx users.

GitHub Actions workflow

name: Release & Publish
on:
  push:
    branches:
      - main
jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    permissions:
      contents: write
    timeout-minutes: 10
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Install Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: https://registry.npmjs.org/
      - name: Install dependencies
        run: npm i
      - name: Build
        run: npm run build
      - name: Print Environment Info
        run: npx nx report
      - name: Configure git user
        run: |
          git config --local user.name "${{ github.actor }}"
          git config --local user.email "${{ github.actor }}@users.noreply.github.com"
      - name: Release packages
        run: npx nx release --skip-publish
        env:
          GH_TOKEN: ${{ github.token }}

  publish:
    name: Publish
    runs-on: ubuntu-latest
    needs: release
    permissions:
      contents: read
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Install Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: https://registry.npmjs.org/
      - name: Install dependencies
        run: npm i
      - name: Release packages
        run: npx nx release publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          NPM_CONFIG_PROVENANCE: true
github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because it hasn't had any activity for 6 months. Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore. If at this point, this is still an issue, please respond with updated information. It will be closed in 21 days if no further activity occurs. Thanks for being a part of the Nx community! 🙏